i2c delay

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

i2c delay

741 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by clcorbin on Tue Mar 12 22:05:32 MST 2013
Gents,

I am building an i2c library for several peripherals that I use regularly.  The basic libraries are based on working libraries I wrote for my AVR projects.

The i2c core library I am using to implement these device libraries is from the lpcxpresso.examples.lpc11c24 zip file. 

The conversion was fairly straight forward with one exception: A couple of commands require the device to send data back to the MCU, but it takes up to 5ms before the device is ready to send the data.  From my experience, the device does not perform clock stretching, so it was necessary to implement the delay in the function side like this:

[LIST]
[*]i2c_start
[*]i2c_address
[*]i2c_data (command word to the device to let it know a command is coming)
[*]i2c_data (command)
[*]delay(5ms)
[*]i2c_restart(address + read)
[*]i2c_read
[*]i2c_stop
[/LIST]
The problem I am having is figuring out how to implement this type of delay using the interrupt driving library.  Or if it is even possible or desirable to do so.  Would it be possible to break it up into two separate transmissions:

[LIST]
[*]i2c_start
[*]i2c_address
[*]i2c_data (command word to the device to let it know a command is coming)
[*]i2c_data (command)
[*]i2c_stop
[/LIST]
Insert 5ms delay

[LIST]
[*]i2c_start(address + read)
[*]i2c_read
[*]i2c_stop
[/LIST]
Have other folks encountered this issue (I'm sure some one has!)?  If so, how did you handle it?  Any other ideas on how to properly handle this type of situation?

Thanks for the help.  While I have made several projects with the AVRs (Atmegas mostly), the arm-cortex world is definitely more complex (but more capable as well...).


Clint
0 Kudos
Reply
1 Reply

714 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by clcorbin on Wed Mar 13 14:06:46 MST 2013
Ok.  I figured it out.  The plan above is the correct way to deal with it.  After thinking about it more last night, I did some more research on this issue with I2C in general and found several cases where the two part transmission with delay in  between was called out for the case were clock stretching was not used.

Even worse, when I went to test this with my working AVR code, I found that was exactly how I implemented it as well...
0 Kudos
Reply