2014-12-27 12:09 PM
2015-12-30 10:38 AM
2015-12-30 06:20 PM
Hi Folks:
I know the exact cause of the I2C problem and have solved it. The cause is that in an OS environment with preemptive scheduling it is likely that data in read sensitive registers will be lost during task switches--due to the fact that you need to read registers in order to save them. For example, if the I2C SR1 register is saved during a task switch, the value of bit 1 may be cleared. The solution is to make the all the I2C operation code between the point the bus is acquired and the routine exits a critical section in the P_I2C_Rx_Byte() and P_I2C_Tx_Byte() routines. Since these routines only transfer a one byte register, it is safe to do this. The details of entering a critical section are OS dependent and and versions of these routines configured for FreeRTOS are attached. Also, I strongly advise adopting the changes in I2C_CheckEvent() which I previously described. Best Regards, Paul R. ________________ Attachments : code.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzVA&d=%2Fa%2F0X0000000bMm%2FqT_Jv7BxqOxXBNmKcv.RA_qGB8xniQ4.4sdFq5kqlrM&asPdf=false