I am new to embedded programming and try to get my first I2C project working. I am using PIC32MX795F512L. I pretty much follow the chip specification for I2C on PIC32. The problem I am facing is the S bit, which is never cleared from the I2C1STAT register. I donโt really understand if I need to do this or if it is done automatically when the Start event is completed, but now I'm trying to manually clear it. However, nothing I do seems to have an effect. If you need more information to make it easier to understand what is happening, let me know. I use PICKIT3 to get debugging information. I know that a Master interrupt occurs, the S bit is set, I exit the interrupt code and hang on the while statement checking I2C1STATbits.S.
Edit: I am editing this post to have new code instead of old. Now I am using a 20 MHz peripheral clock. Only one of the many things I tried today did not work. The delay is only 256 ms. I know super long time, but it was fast.
main()
{
I2C1CONbits.SIDL = 0;
I2C1CONbits.SCLREL = 1;
I2C1CONbits.A10M = 0;
I2C1CONbits.DISSLW = 1;
I2C1ADD = 0x1E;
I2C1BRG = 0x060;
I2C1CONbits.ON = 1;
delay();
I2C1CONbits.SEN = 1;
while(I2C1CONbits.SEN == 1);
I2C1TRN = 0x3C;
while(I2C1STATbits.TRSTAT == 1);
while(I2C1STATbits.ACKSTAT == 0);
I2C1TRN = 0x00;
while(I2C1STATbits.TRSTAT == 1);
while(I2C1STATbits.ACKSTAT == 0);
I2C1TRN = 0x70;
while(I2C1STATbits.TRSTAT == 1);
while(I2C1STATbits.ACKSTAT == 0);
while(1);
}
Thanks for any help.
source
share