Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 13th May 2008, 12:43 PM   (permalink)
Experienced Member
Hesam Kamalan is on a distinguished road
Send a message via Yahoo to Hesam Kamalan
Default I2C Command and DS1304

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
Hesam Kamalan is offline   Reply With Quote
Old 13th May 2008, 01:47 PM   (permalink)
Experienced Member
arhi is just really nicearhi is just really nicearhi is just really nice
Default

Quote:
Originally Posted by Hesam Kamalan
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?
You can read about I2C protocol in most of PIC data sheet's, what part of the I2C commands in mikroC you find problematic?

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
can you pinpoint the part of the code that is not clear and I'll try to explain it to you.
__________________
http://www.it4um.com
arhi is offline   Reply With Quote
Old 13th May 2008, 02:04 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

Quote:
Originally Posted by arhi
You can read about I2C protocol in most of PIC data sheet's, what part of the I2C commands in mikroC you find problematic?

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();            //Delay for 100 milliseconds



  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
can you pinpoint the part of the code that is not clear and I'll try to explain it to you.
I don't like to be picky, but that is the most ridiculous commenting I have witnessed. Can you see why? There was one comment that was missing and so I added it.

BTW, what does the 100000 mean in the statement I2C_Init(100000);

Mike.
Pommie is online now   Reply With Quote
Old 13th May 2008, 02:18 PM   (permalink)
Experienced Member
 
Blog Entries: 4
blueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to beholdblueroomelectronics is a splendid one to behold
Send a message via Skype™ to blueroomelectronics
Default

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
__________________
Bill
Smart Kits build Smart People

http://www.blueroomelectronics.com
blueroomelectronics is offline   Reply With Quote
Old 13th May 2008, 02:19 PM   (permalink)
Experienced Member
arhi is just really nicearhi is just really nicearhi is just really nice
Default

Quote:
Originally Posted by Pommie
I don't like to be picky, but that is the most ridiculous commenting I have witnessed. Can you see why? There was one comment that was missing and so I added it.

BTW, what does the 100000 mean in the statement I2C_Init(100000);

Mike.

I agree Mike, too much comments, that was copy/paste from basic example of I2C use from MikroC ... not developed by me .. I tend to put totally different comments in my code

as for i2c_init() .. here's what the mikroC help say:
Quote:
Initializes I²C with desired clock (refer to device data sheet for correct values in respect with Fosc). Needs to be called before using other functions of I²C Library.

Library requires MSSP module on PORTB or PORTC.

anyhow, even as I actually disagree with style of commenting in this example done by mikroC developer, it show's how to communicate with the I2C device
- 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
arhi is offline   Reply With Quote
Old 13th May 2008, 02:48 PM   (permalink)
Experienced Member
Pommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to beholdPommie is a splendid one to behold
Default

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)
Mike.
Pommie is online now   Reply With Quote
Old 13th May 2008, 03:09 PM   (permalink)
Experienced Member
arhi is just really nicearhi is just really nicearhi is just really nice
Default

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
arhi is offline   Reply With Quote
Old 13th May 2008, 07:36 PM   (permalink)
Experienced Member
 
OY2L is on a distinguished road
Default

Nigel's tutorial may also be a help http://www.winpicprog.co.uk/pic_tutorial6.htm
OY2L is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes




All times are GMT. The time now is 05:38 AM.


Electronic Circuits  |  Radio Controlled
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.