I2C slave issue summary

During this time the company has a project, uses multiple MCU, communicate with I2C. Encountered many problems here tidy.

Host I2C with the HAL library is relatively simple.

There is a point to note is that the beginning of Start-Write-Stop-Start-Read-Stop timing with the way I read the instructions, a power supply control chip, but life and death is not successful, I think this timing, I do not need to use the HAL library interrupt, I2C operation with polling on it, a little convenient, and most also support the I2C slave device. But this power chip is not supported, and later changed to the Start-Write-Restart-Read-Stop timing mode, then no problem, after communicating with the manufacturers, they explained that they will take the initiative before the Restart signal down the line, do some data processing before it releases the line and, if received the Stop signal, they direct the end of the operation, resulting in reading out the data later is a fixed value (0xFF).

 

Slave because the agreement is the custom, I look for a more flexible operation, using LL library .

Note that there are several points:

1, I2C as from the transmitter, when the last byte of the master inquiry, the transmission from the machine, and the host will not send an ACK signal, if the case is opened from the machine ITERREN register, it would enter the interrupt, this special interrupt request requires special handling. Otherwise, if your special break in some time-consuming operation, it will affect the normal I2C communications.

2, I'm afraid I2C hanging dead I do not know, I made a 2 minute timer to Stop signal refresh signals, if two minutes Stop signal is not received, I think the I2C interrupt, then represented by LED lights. I read timing is Start-Write-Restart-Read-Stop. Later discovery program is running LED lamp has been expressed as linked to the I2C (I2C during operation the reading operation has been done), but the read data in the host, I2C communication is normal. And later we found the reason in Stm32F1 reference manual. DESCRIPTION STOPF bits in the I2C register SR1 said explained in detail.

Because the original is the Stop Read operation sent by the host can not be finally recognized by a slave to the slave recognizes only AF (i.e., NACK signal), resulting in the measured time I has not been refreshed, resulting in an LED lamp I "false military intelligence. " Later, I will refresh signals on the ADDR interrupt request, to solve the problem.

 

Guess you like

Origin www.cnblogs.com/dubrother/p/12306952.html