![]() |
![]() |
![]() |
|
|
|||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
|
|
Thread Tools | Display Modes |
|
|
(permalink) |
|
Experienced Member
|
Hey guys,
I have a question about the I2C commands used. The MikroC is rather confusing, and that example isn't very helpful for me. Can someone please explain to me how the I2C commands work? how can i set time and get it for show on lcd?
__________________
Visit my site : http://www.kamalan.com my free books : http://www.kamalan.com/index_files/Books.htm |
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
Code:
I2C_Init(100000); // initialize I2C communication I2C_Start(); // issue I2C start signal I2C_Wr(0xA2); // send byte via I2C (device address + W) I2C_Wr(2); // send byte (address of EEPROM location) I2C_Wr(0xF0); // send data (data to be written) I2C_Stop(); // issue I2C stop signal Delay_100ms(); I2C_Start(); // issue I2C start signal I2C_Wr(0xA2); // send byte via I2C (device address + W) I2C_Wr(2); // send byte (data address) I2C_Repeated_Start(); // issue I2C signal repeated start I2C_Wr(0xA3); // send byte (device address + R) PORTB = I2C_Rd(0u); // Read the data (NO acknowledge) I2C_Stop(); // issue I2C stop signal
__________________
http://www.it4um.com |
|
|
|
|
|
|
(permalink) | |
|
Experienced Member
|
Quote:
BTW, what does the 100000 mean in the statement I2C_Init(100000); Mike. |
|
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Here's the Philips I2C application note. A must if you plan on using I2C as it's from the creators of the I2C bus.
http://www.nxp.com/acrobat_download/.../AN10216_1.pdf |
|
|
|
|
|
(permalink) | ||
|
Experienced Member
|
Quote:
I agree Mike, too much comments, that was copy/paste from basic example of I2C use from MikroC ... not developed by me as for i2c_init() .. here's what the mikroC help say: Quote:
- init i2c - send start signal - send address of the device + read or write - send the location from/to where you want to read/write ...
__________________
http://www.it4um.com |
||
|
|
|
|
|
(permalink) |
|
Experienced Member
|
It does indeed show how to communicate but I feel it would be more useful if it had comments (and code) like,
Code:
I2C_Start(); I2C_Write(0xA2); // Serial EEPROM address, chip 1 //instead of I2C_Start(); // issue I2C start signal I2C_Wr(0xA2); // send byte via I2C (device address + W) |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
mike, I agree 1000% .. I personally hate the "obvious" comments that show "what statement does" instead of "why is this doing what" .. but apart from that, OP's question was that "how i2c commands work" .. this example show's just that and it is pretty obvious what is done + there is help on each statement included with mikroC. Everything else is "understanding the i2c protocol" and for that one need to read data sheet, these "libraries" are just here to make the code "nicer", they do not offer additional layer over i2c (like lcd* libriaries do for example)
I do not agree with way many things are done in mikroC but it is easy tool to use and generates pretty good code (imho for 12* and 16* the generated code is much better (smaller/faster) then what CSC C generates.. donno about other compilers as I'm using those two for 12* and 16* as I have licence for them, for 18* I use C18 and for 2*, 3* dsPIC* must admit I never even saw them except on picture
__________________
http://www.it4um.com |
|
|
|
|
|
(permalink) |
|
Experienced Member
|
Nigel's tutorial may also be a help http://www.winpicprog.co.uk/pic_tutorial6.htm
|
|
|
|