2008-10-23 02:16 AM
I2C and PEC (interrupt driven)
2011-05-17 03:48 AM
I am attempting to use the I2C to transfer data between two STM32 devices, one acting as Master Transmitter and the other acting as Slave Receiver. I am driving the I2C using interrupts, and the ''state'' macros of the firmware library. I have had numerous problem (as described in other postings) to force the I2C firmware to perform as required, but things seem well now.
However, I am having problems with PEC generation, which I cannot surmount; In the Master Transmitter, I tried using I2C_TransmitPEC(I2C2); when the last byte is to be transferred. However, this does not clear the TxE interrupt, which continues to be generated after setting the PEC bit in CR1. If I disable interrupts at this point, I do not know when the PEC has been transferred, and so do not know when to generate STOP. Instead, I tried using I2C_SendData(I2C2, I2C_GetPEC(I2C2)); However, the PEC generated using this code, is incorrect (the last data byte is not taken into account). My question is this; How am I supposed to successfully generate PEC, using interrupts.2011-05-17 03:48 AM
I guess the solution is to use a soft PEC, and send it using
lvPEC = CRC08(lvPEC, lvData); I2C_SendData(I2C2, lvPEC); instead of calling I2C_TransmitPEC(I2C2); This way, the TxE interrupt is not needlessly generated. [ This message was edited by: brian.forde on 23-10-2008 14:47 ]