AnsweredAssumed Answered

I2C Troubleshooting without an oscilloscope

Question asked by Matthieu Tanguay on Jul 20, 2017
Latest reply on Jul 21, 2017 by Vangelis Fortounas

Hello everyone,

 

I recently got myself a little nucleo compatible accessory shield that comes with at I2C Temperature sensor LM75B. After carefully reading the datasheet I felt confident that I could get a working code quick enough. As a first test I decided to try to do a read of the temperature sensor using the pointer. I found some example online that I modified for my needs that look something like that : 

 

 

I2C_HandleTypeDef hi2c1;

volatile uint8_t buffer[5];
volatile uint16_t rawTemp;
int16_t Temp;

void TempMeasurement(void){
buffer[0] = 0x00; //Pointer to the Temp. Register
HAL_I2C_Master_Transmit(&hi2c1,0x48<<1,buffer,1,100); //Send pointer for Temperature Register
HAL_Delay(10);
HAL_I2C_Master_Receive(&hi2c1,0x48<<1,buffer,2,100);
//Buffer[0] : MSB
//Buffer[1] : LSB
printf("Buffer After %d\r\n",buffer[0]);
rawTemp = buffer[0]<<5 | buffer[1]; //combine 2 MSB and LSB in one 10 bit number
}

 

I use the cube to generate the basic code for the I2C Bus. I also know that the sensor is working because I ran the provided mbed code as a check to verify that the electric part of the "project" is working. If you could help with the code that would be great. On the other hand what I am interested in is ways that I can use HAL librairies to inspect where and how the code is breaking?

 

I tried to dig into the code and found various values like TIMEOUT and ERROR. Could I use these to check how my bus is failing?

 

Thank you in advance. 

Outcomes