ACKEN bit on PIC24FJ64GA002 not clearing after acknowledge sequence

145 views Asked by At
uint8_t i2c_read(void)

{

    uint8_t u8_readData;
    uint8_t u8_ackBit = 0;
    while(I2C1CON & 0x1F);          //wait for idle
    I2C1CONbits.RCEN = 1;           //prepare device to receive
    while(I2C1CONbits.RCEN);
    u8_readData = I2C1RCV;          //write recieved data to variable
    while(I2C1CON & 0x1F);          //wait for idle

    I2C1CONbits.ACKDT = u8_ackBit;  //prepare to send ack bit
    I2C1CONbits.ACKEN = 1;          //transmit ack bit
    //HERE IS MY PROBLEM 
    while(I2C1CONbits.ACKEN);       //wait for idle
    return(u8_readData);
}

This is part of my code that I am having trouble with as shown in the code while(I2C1CONbits.ACKEN); is not being able to clear. This part of code is used to connect a Infrared sensor (type: MLX90614 family) to the Pic24. My breadboard connections are correct and I tripled checked it. What happens is when I run the code, the code stops at this while loop and doesn't move on.

0

There are 0 answers