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