2012-04-21 02:27 AM
Hi there,
I'm trying to implement an enumeration test on the I2C bus with my own driverbut I haven't figured out how to deal with a timeout on the address.After I send the address of the slave, if nobody respond within a certain timeout(25ms in my case) I'd like to close up the communication and go on with the nextaddress. I tried setting the stop bit on timeout but the bus keep staying busy and inmaster mode, and it locks everything up, because the next thing I do is sending a new start condition which won't happen due to the bus being buse.The spec says that after setting the STOP bit, the stop condition will be actually setafter the next byte. Does this mean that I have to send a dummy byte (which hopefullyis nobody address)? Or is there something I am missing?Thanks in advanced.S.2012-04-21 04:51 AM
I use the AF bit in SR1 to detect non acknowledgement of the address
//wait for ADDR set condition and clear ADDR bit or AF failure do { //check status register sr1 = I2C2->SR1; } while(((sr1 & I2C_SR1_ADDR) == 0) & ((sr1 & I2C_SR1_AF) == 0)); sr2 = I2C2->SR2;2012-04-21 06:01 AM
2012-04-21 06:42 AM
You can consult the manual for that. It takes like two register writes or something
2012-04-23 03:22 AM
Ok for the Ack failed bit, but if it set what do you next?
Do you set the STOP bit? Is reading the status2 register
necessary even in that case?
If AF bit in _SR1 is set (no ACK from a device on address), I would make: 1). readout of _SR2 to complete the state machine, 2). clear of AF by writing '0' to _SR1, 3). issue STOP.
2012-04-30 06:06 AM
you do not state which chip, but if it is f1xx you must read the arrata.
Erik2012-05-01 03:29 AM
Sometimes it can happen, that a slave keeps the SDA line in low state (waiting for next SCL from master). As far as I know, the STM32 I2C cannot handle such a situation ''automatically''. To clear this ''bus error'', you have to put the SCL line to ''normal output'' (NOT alternate function) and clock out 8 clock bits, with SDA high. After this, every slave should leave the bus, as the slaves should recognize, that the master does NOT acknowledge their data.
So best do this procedure every time you see some ''timeout'' condition on I2C bus.