cancel
Showing results for 
Search instead for 
Did you mean: 

Are I2C_START and I2C_STOP commands included in HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive commands?

KMunj
Associate II

I am using ​HAL_I2C_Master_Transmit and HAL_I2C_Master_Receive commands to read device ID of various sensors. I wrote a simple code to do that. It works for some sensors (e.g. MCP9800, HDC1080). But it doesn't work for some other sensors (e.g MLX90164, MAX30101, MLX90632, AFE4404). Some of these sensors ask for specific I2C_START and I2C_STOP commands. Following is my sample code for MCP9800;

-----------------------------------------------------------------------------------------------------------------------

buffer[0]=0xFE; //Pointer buffer for Manufacturer ID

HAL_I2C_Master_Transmit

(&hi2c1,0x40<<1,buffer,1,100);

HAL_Delay(500);

HAL_I2C_Master_Receive

(&hi2c1,0x40<<1,buffer,2,100);

IDNumber = buffer[0]<<8 | buffer[1]; //combine 2 8-bit into 1 16bit

UU_PutString(USART2, "\r\nManufacturer ID in Decimal for HDC1080 = ");

UU_PutNumber(USART2, IDNumber);

HAL_Delay(500);

--------------------------------------------------------------------------------------------------------------------

What are HAL commands for I2C_START and I2C_STOP? I couldn't find in the HAL manual.

Thanks

Kiran

2 REPLIES 2
AAl-H
Associate III

Are you sure you should use HAL_I2C_Master_Transmit not HAL_I2C_Mem_Read?

If you're reading data from the sensor's memory then you need to use HAL_I2C_Mem_Read

Tell me if that works

If that's not it, some sensors require a re-start before generating a stop

I didn't find a HAL function that does that in Polling mode

So, you'll have to modify the HAL function to NOT generate a stop

Tell me if this helps

KMunj
Associate II

​Hi Ahmed,

Thanks for trying. This didn't help much. But following link helped a lot.

https://community.st.com/s/question/0D50X00009XkXY9SAN/i2c-cannot-read-from-sensor

Thanks

Kiran