/*
* Example Code for pressure reading from I2C bus
* Used microcontroller: Microchip PIC24FV32KA302
* This code is not complete! Basic I2C functions have to be added
*
*/
//Read byte from I2C bus; send master ACK-bit
char i2c_read_ack(void) //does not reset bus!!!
{
int i = 0;
char data = 0;
//set I2C module to receive
I2C1CONbits.RCEN = 1;
//if no response, break
while (!I2C1STATbits.RBF)
{
i++;
if (i > 2000) break;
}
//get data from I2CRCV register
data = I2C1RCV;
//set ACK to high
I2C1CONbits.ACKEN = 1;
//wait before exiting
Delay(10);
//return data
return data;
}
|