Hi!
I'm having some troubles with the I2C communication between my MCU and my temperature sensor.
Sensor
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00153511.pdf
MCU
http://ww1.microchip.com/downloads/en/DeviceDoc/39932b.pdf
Link to mikroe and the function definitions.
**broken link removed**
I've tested so that I can write successfully to the sensor. But the problem is when I used I2C1_Rd, the MCU just hangs when I do that.
Any suggestions to what might cause these problems?
I'm having some troubles with the I2C communication between my MCU and my temperature sensor.
Sensor
http://www.st.com/internet/com/TECHNICAL_RESOURCES/TECHNICAL_LITERATURE/DATASHEET/CD00153511.pdf
MCU
http://ww1.microchip.com/downloads/en/DeviceDoc/39932b.pdf
Link to mikroe and the function definitions.
**broken link removed**
Code:
void main()
{
double temp;
TRISA.B0=0;
TRISA.B1=0;
TRISC=0xFF; //outputs for i2c
ANCON0=0xFF;
I2C1_Init(100000);
while(1)
{
I2C1_Start();
I2C1_Wr(0b10010010); //controll code + adress + r/w = 0
I2C1_Wr(0b00000011); //point to temperature reg
I2C1_Repeated_Start();
I2C1_Wr(0b10010011); //controll code + adress + r/w = 1
take1 = I2C1_Rd(1); //ACK
take2 = I2C1_Rd(0); //NACK
I2C1_Stop();
LATA.B0 = ~LATA.B0; //just to see if it hangs or not
delay_ms(500);
}
}
I've tested so that I can write successfully to the sensor. But the problem is when I used I2C1_Rd, the MCU just hangs when I do that.
Any suggestions to what might cause these problems?