cancel
Showing results for 
Search instead for 
Did you mean: 

I2C and PEC (interrupt driven)

brianforde9
Associate II
Posted on October 23, 2008 at 11:16

I2C and PEC (interrupt driven)

2 REPLIES 2
brianforde9
Associate II
Posted on May 17, 2011 at 12:48

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.

brianforde9
Associate II
Posted on May 17, 2011 at 12:48

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 ]