(help needed) using devices with i2c address greater than 127

thakshak
Tue Jul 21, 2015 3:04 pm
I have a AM2320 temperature and humidity sensor (datasheet http://akizukidenshi.com/download/ds/aosong/AM2320.pdf)

it has address 0xB8(dec-184) > 127

trying with the following code, every string printed is zero… :(

#include <Wire.h>
#define I2CADDR 0xb8
#define READCMD 0x03
#define REGSTADDR 0x00
#define REGCOUNT 4

#define REGADDR 0x0B

void setup() {
Wire.begin(); // wake up I2C bus
Serial.begin(9600);
}

void loop() {
byte buf[10];
//
// Read Command
//
Wire.beginTransmission(I2CADDR);
Wire.write(READCMD);
Wire.write(REGSTADDR);
Wire.write(REGCOUNT);
Wire.endTransmission();
//
// Waiting
//
delay(2); //>1.5ms
//
// Read
//
Wire.requestFrom(I2CADDR, 2 + REGCOUNT + 2); // COMMAND + DATA + REGCOUNT + CRCLSB + CRCMSB
int i = 0;
for (; i < 2 + REGCOUNT + 2; i++)
buf[i] = Wire.read();
for (i=0; i < 2 + REGCOUNT + 2; i++)
Serial.println(buf[i]);
delay(3000);
}


martinayotte
Tue Jul 21, 2015 3:56 pm
Definitively, the 0xB8 address is already shifted, so, as you mentioned, you need the “(#define I2CADDR (0xb8 >> 1))”
Other then that, I don’t see where it is failing since I don’t have such module to try it out.
Do you have proper PullUps resistors on the bus ?

thakshak
Tue Jul 21, 2015 7:13 pm
martinayotte wrote:Definitively, the 0xB8 address is already shifted, so, as you mentioned, you need the “(#define I2CADDR (0xb8 >> 1))”
Other then that, I don’t see where it is failing since I don’t have such module to try it out.
Do you have proper PullUps resistors on the bus ?

mrburnette
Thu Jul 23, 2015 1:23 am
thakshak wrote:I have a AM2320 temperature and humidity sensor (datasheet http://akizukidenshi.com/download/ds/aosong/AM2320.pdf)

it has address 0xB8(dec-184) > 127


martinayotte
Thu Jul 23, 2015 1:55 pm
@Ray, this is because their I2C implementation doesn’t shift the address :

I2C_Write(AM2320_address + I2C_write_cmd);


thakshak
Sat Jul 25, 2015 8:23 pm
martinayotte wrote:Definitively, the 0xB8 address is already shifted, so, as you mentioned, you need the “(#define I2CADDR (0xb8 >> 1))”
Other then that, I don’t see where it is failing since I don’t have such module to try it out.
Do you have proper PullUps resistors on the bus ?

RogerClark
Sat Jul 25, 2015 10:05 pm
What is the Max speed of I2C for this module?

Default speed on the STM32 is set to 250kbps instead of 100kbps on AVR.
However most modules operate up to 400kpbs, so this is not normally an issue, but its something to bear in mind.


thakshak
Sun Jul 26, 2015 11:09 am
RogerClark wrote:What is the Max speed of I2C for this module?

Default speed on the STM32 is set to 250kbps instead of 100kbps on AVR.
However most modules operate up to 400kpbs, so this is not normally an issue, but its something to bear in mind.


RogerClark
Sun Jul 26, 2015 12:09 pm
Just to test this

Go into /STM32F1/libraries/wire.cpp and at the bottom change

TwoWire Wire(PB6, PB7, SOFT_FAST);


thakshak
Sun Jul 26, 2015 1:39 pm
RogerClark wrote:Just to test this

Go into /STM32F1/libraries/wire.cpp and at the bottom change

TwoWire Wire(PB6, PB7, SOFT_FAST);


RogerClark
Sun Jul 26, 2015 9:33 pm
Unfortunately it looks like the Arduino / Wiring API does not have a way to set the speed.

I think this is a major omission now that new boards are capable of higher speeds and some devices e.g. Accelermoeters benefit if you can read their data as fast as possible.

As I excpet some libraries may have hard coded references to Wire in them, it would make sense to add a new function to Wire of setSpeed(int speedInKHz)

Or possibly add an optional argument to Wire.begin(int address, int speedInKHz)

Do you have any other ideas ?


Kenjutsu
Mon Jul 27, 2015 8:58 am
RogerClark wrote: it would make sense to add a new function to Wire of setSpeed(int speedInKHz)

Or possibly add an optional argument to Wire.begin(int address, int speedInKHz)


Leave a Reply

Your email address will not be published. Required fields are marked *