Hi,
I'm testing the mbed with a temperature/humidity I2C sensor (Sensirion SHT21) connected on port p27/p28.
I'm experiencing the below problems using the I2C class library.
Using the functions write(int address, char *data, int length, bool repeated) and read(int address, char *data, int length, bool repeated) everything works fine, the sensor answer to commands sent via I2C.
Now, I would like to have a function that checks if the SHT21 is connected on the I2C bus, so I write this small piece of code:
#define SHT21_ADDRESS 128
int SHT21_Check(void) {
int ack;
i2c.start();
ack = i2c.write(SHT21_ADDRESS);
i2c.stop();
return ack;
}
The problem is that the i2c.write() returns always 0 (and reading the documentation 0 means NoACK, while 1 means ACK), but using an oscilloscope I can see that the sensor acks its address correctly.
I've tried to change the SHT21_ADDRESS to another value, on the oscilloscope I see that the SHT21 sends NoACK but the i2c.write() returns always 0.
This is an image of the oscilloscope when the SHT21_ADDRESS is acked (but the i2c.write() returns 0):
I can't understand where I'm wrong with this code.
Thanks for any help/suggestions.
Samuele.
Hi, I'm testing the mbed with a temperature/humidity I2C sensor (Sensirion SHT21) connected on port p27/p28.
I'm experiencing the below problems using the I2C class library.
Using the functions write(int address, char *data, int length, bool repeated) and read(int address, char *data, int length, bool repeated) everything works fine, the sensor answer to commands sent via I2C.
Now, I would like to have a function that checks if the SHT21 is connected on the I2C bus, so I write this small piece of code:
The problem is that the i2c.write() returns always 0 (and reading the documentation 0 means NoACK, while 1 means ACK), but using an oscilloscope I can see that the sensor acks its address correctly. I've tried to change the SHT21_ADDRESS to another value, on the oscilloscope I see that the SHT21 sends NoACK but the i2c.write() returns always 0.
This is an image of the oscilloscope when the SHT21_ADDRESS is acked (but the i2c.write() returns 0):
I can't understand where I'm wrong with this code. Thanks for any help/suggestions.
Samuele.