Reputation: 27
I am trying to connect to an HS3000 humidity and temperature sensor using I2C with Mbed OS on an Arduino Nano 33 BLE Sense. However, I keep running into I2C communication issues when trying to read the "Who Am I" register. My code consistently prints:
I2C write error on 'Who Am I'!
I2C read error on 'Who Am I'!
Received from sensor: 0x97 0x01
I believe the issue lies somewhere in the I2C communication, but I'm unsure where to proceed from here. I've verified the wiring and connections, but I may be overlooking something.
This is part of a bigger lab project and I've attempted to shorten all the details and the code to fit stack overflow's guidelines but if you think the lab manual and my full code is necessary let me know and I'll attach both.
#include "mbed.h"
#include "USBSerial.h"
#include "I2C.h"
// Define memory-mapped GPIO registers for controlling the LEDs
#define DIRSET (uint32_t*) 0x50000514 // Set GPIO direction (Input/Output)
#define OUTSET (uint32_t*) 0x50000508 // Set LED Pin (Turn ON)
#define OUTCLR (uint32_t*) 0x5000050c // Clear LED Pin (Turn OFF)
#define HUMIDITY_FLAG (1UL << 0)
#define TEMPERATURE_FLAG (1UL << 1)
//Ticker ticker;
EventFlags event_flags;
USBSerial serial;
void set_i2c_pullup(){
*DIRSET |= (1 << 0);
*OUTSET |= (1 << 0);
}
void ISR(){
static bool toggle = true;
if (toggle){
event_flags.set(HUMIDITY_FLAG);
}
else{
event_flags.set(TEMPERATURE_FLAG);
}
toggle = !toggle;
}
Mutex print_mutex;
I2C i2c(I2C_SDA1, I2C_SCL1);
const int HS3000_ADDR = 0x44 << 1; // 0x44 shifted for 7-bit I2C address
int main(void){
set_i2c_pullup();
char who_am_i_addr[] = {0x1E}; // Register to read ID
char who_am_i_data[2];
if (i2c.write(HS3000_ADDR, who_am_i_addr, 1) != 0) {
serial.printf("I2C write error on 'Who Am I'!\r\n");
}
ThisThread::sleep_for(200ms);
if (i2c.read(HS3000_ADDR, who_am_i_data, 2) != 0) {
serial.printf("I2C read error on 'Who Am I'!\r\n");
}
serial.printf("Received from sensor: 0x%02X 0x%02X\r\n", who_am_i_data[0], who_am_i_data[1]);
//ticker.attach(&ISR, 1s);
while(true){
// Main loop
}
}
Setup:
Board: Arduino Nano 33 BLE Sense
Sensor: HS3000 humidity and temperature sensor
Information from datasheet I found useful:
"The HS3xxx series sensor operates as a slave device on the I2C bus with support for 100kHz and 400kHz bit rates"(pg.10)
"The HS3xxx series default I2C address is 44HEX. The device will respond only to this 7-bit address."(pg.10)
Table 2. Non-Volatile Memory Registers(pg.14)
Address | Register Description |
---|---|
0x06 | Humidity Sensor Resolution – Read Register (bits 11:10). |
0x46 | Humidity Sensor Resolution – Write Register (bits 11:10). |
0x11 | Temperature Sensor Resolution – Read Register (bits 11:10). |
0x51 | Temperature Sensor Resolution – Write Register (bits 11:10). |
0x1E | Read Sensor ID – Upper 2 bytes. |
0x1F | Read Sensor ID – Lower 2 bytes |
Issues:
Note that there are no compiling errors.
I2C write error: Happens when attempting to write to the "Who Am I" register (0x1E).
I2C read error: Happens when attempting to read the sensor's response.
Expected Behavior:
I'm expecting to read the sensor's ID from the "Who Am I" register to verify that communication with the sensor is working.
Actual Behavior:
Instead, I receive the I2C write and read errors, and the sensor outputs 0x97 0x01 when reading the ID, which doesn't match the expected values.
Questions:
Could this be an issue with the I2C address or sensor communication configuration?
Are there any additional steps I should take to troubleshoot I2C communication with the HS3000?
Upvotes: 0
Views: 41