I'm trying to get data from a sensor, but don't see how I can get data back. I'm looking at the data on the I2C bus with a logic analyzer, and I'm sending what I expect, but I seem to cut off the slave before he can respond. My understanding from the datasheet is that I need to send this command to wake it up and request a measurement:
0xD8 0x30 0x0A
and then I need to send this command to get the data:
0xD8 0x06 0xD9
#define HEARTBEAT_PIN (13)
#define 7BIT_ADDR (0x6C)
#define ADDR_WRITE (0xD8)
#define ADDR_READ (0xD9)
#define MAX_NUM_RX_BYTES (8)
#define MAX_NUM_TX_BYTES (8)
static uint8_t tx_buffer[MAX_NUM_TX_BYTES];
static uint8_t rx_buffer[MAX_NUM_RX_BYTES];
static uint8_t new_rx_data;
void setup(void) {
// Clear any module memory
memset(tx_buffer, 0, MAX_NUM_TX_BYTES);
memset(rx_buffer, 0, MAX_NUM_RX_BYTES);
new_rx_data = false;
Wire.begin();
}
void loop(void) {
RequestMeasurement();
delay(10);
GetData();
delay(500);
}
void RequestMeasurement(void) {
// MR: 0xD8 0x30 0x0A
// Internal (to IC) register address?
tx_buffer[0] = 0x30;
// Request-measurement command
tx_buffer[1] = 0x0A;
Wire.beginTransmission(7BIT_ADDR);
Wire.write(tx_buffer, 2);
Wire.endTransmission(true);
}
void GetData(void) {
// GD: 0xD8 0x06 0xD9 0x?? 0x?? 0x?? 0x?? 0x?? (0x?? => slave data)
// Slave address + 'write' indication bit
// Internal (to IC) register address?
tx_buffer[0] = 0x06;
// Slave address + 'read' indication bit
tx_buffer[1] = ADDR_READ;
Wire.beginTransmission(7BIT_ADDR);
Wire.write(tx_buffer, 2);
Wire.endTransmission(true);
// HOW DO I LEAVE THE BUS OPEN LONG ENOUGH
// FOR THE SLAVE DEVICE TO RESPOND WITH THE DATA?
//Wire.requestFrom(7BIT_ADDR, 3, true);
}