How can I read data from an I2C temperature sensor (TMP102) using an STM32 microcontroller?
Good day guys, how can I read data from an I2C temperature sensor (TMP102) using an STM32 microcontroller? I am encountering the error
Failed to read from the I2C bus: Remote I/O error
Failed to read from the I2C bus: Remote I/O error
despite confirming that the sensor is powered and the I2C connections are correctly set up. Here is my current code snippet, which attempts to read 10 bytes of data from the sensor:
char buffer[10];if (read(file, buffer, 10) != 10) { perror("Failed to read from the I2C bus");}
char buffer[10];if (read(file, buffer, 10) != 10) { perror("Failed to read from the I2C bus");}
@Middleware & OS @Helper
Solution
Try this code instead
#include "stm32f1xx_hal.h"
I2C_HandleTypeDef hi2c1;
#define TMP102_ADDR (0x48 << 1) // TMP102 default address (0x48) shifted for HAL functions #define TEMP_REG 0x00 // Temperature register address