|
|
View previous topic :: View next topic |
Author |
Message |
cjusto
Joined: 26 Apr 2006 Posts: 38 Location: Portugal
|
time out for i2c |
Posted: Thu Sep 07, 2006 1:50 pm |
|
|
hi forum!!
i am using two PIC18F4525 and i implemented the code for multi byte send and receive. it works fine.
now i have a problem. in the slave i use the interruption.
because of other code, with interruption, at some point i need to turn off the ssp interruption.
the problem is that my master freezes, as the slave doesn't receive or answers. is there any way to make master work with time out??
some tips??
thanks! |
|
|
Ttelmah Guest
|
|
Posted: Thu Sep 07, 2006 2:51 pm |
|
|
Since a master generates the clock, and does not 'wait', it should not need a timeout. The key is that the slave will hold the ACK, till the byte is read in the code, and this can cause some of the supplied I2C routines to wait. The normal proceedure, is to verify that the slave is ready to receive, before proceeding. If you look at the thread entiled 'MCP3221', a few days ago, I posted a routine to read this chip, which does exactly this. It issues a dummy 'write', and verifies that the slave acknowledges this, before then issuing a repeated start, and the real transfer. Once a transaction has commenced, the slave should not lock out the I2C, till a transaction is complete. The same approach is used in most of the example IC files for various chips, with a read of the status register, or a dummy poll like this, before the transfer begins.
One approach you could use (since the I2C lines are using what are effectively open collector drives), if to have the slave pull the clock lne low, before going 'off line', and in the master, verify that this line is high, before initiating an I2C_START.
To do a genuine 'timeout', would depend on how your master routines are written. Obviously, if they are not interrupt driven, a timer interrupt, or even if they are interrupt driven, and you are using a 18 family chip, a high priority timer interrupt, could be used, but handling it tidyly, will be harder than making sure the slave is ready before a transfer.
Best Wishes |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|