Question
Cannot write data into buffer using HAL_I2C_Mem_Read_IT
- March 7, 2026
- 2 replies
- 113 views
Hi All,
I'm currently trying to interface with a VL53L4CD sensor using the ULD provided by ST. I understand that it is required to write your own code in the "platform" files to interface with the API, but I cannot seem to get my I2C implementation writing into a buffer. It is probably really trivial, but here is the code:
In main.c:
status = VL53L4CD_GetSensorId(dev, &sensor_id);
if(status || (sensor_id != 0xEBAA))
{
printf("\r\n VL53L4CD not detected at requested address \n");
return status;
}And in plaform.c:
uint8_t VL53L4CD_RdWord(Dev_t dev, uint16_t RegisterAdress, uint16_t *value)
{
uint8_t status = 255;
/* To be filled by customer. Return 0 if OK */
/* Warning : For big endian platforms, fields 'RegisterAdress' and 'value' need to be swapped. */
HAL_I2C_Mem_Read_IT(&hi2c1, dev, RegisterAdress, 2, (uint8_t*)&value, 2);
status = 0;
return status;
}The function "GetSensorId" has index of 0x010F, which is successfully sent to the device. Data being read back from the sensor is 0xEBAA. This all ties up with what I'm expecting, yet the value of sensor_id remains as 0. Attached is a screenshot from my Logic Analyser.
Is there something else that i'm missing from how the HAL_I2C library writes to buffers? Any help would be greatly appreciated!
