Closed
Description
I can read the I2C addresses of the I2C sensors with pins 21/22 but I cannot read the WHO_AM_I byte.
This works on the Teensy and STM32L4:
uint8_t readByte(uint8_t address, uint8_t subAddress)
{
uint8_t data; // `data` will store the register data
Wire.beginTransmission(address); // Initialize the Tx buffer
Wire.write(subAddress); // Put slave register address in Tx buffer
Wire.endTransmission(false); // Send the Tx buffer, but send a restart to keep connection alive
Wire.requestFrom(address, 1); // Read one byte from slave register address
data = Wire.read(); // Fill Rx buffer with result
return data; // Return data read from slave register
}
Metadata
Metadata
Assignees
Labels
No labels