Go Down

Topic: Wire.requestFrom() hangs when there is an analogRead() after it (Read 2 times) previous topic - next topic

steeljack

Okay, I now have 4k7 pullups on the I2C bus, I'm using your recommended code, and I've added a delay before analogRead(). Now I get
Code: [Select]
1023
1022
1022
1023
1022
1023
1023
1022
1023
1023
1021
1023
1023
1023
1023
1023
1023
1023
1023
1023

as my output, indicating that I am reading the analog port, but never getting a reply from the chip, meaning I have no idea if it's actually listening to me, and therefore whether the data is valid.

Krodal

Can you make a function of the i2c_scanner : http://playground.arduino.cc/Main/I2cScanner
You could rename the 'loop' function and remove the delay at the end.
What happens if you run the i2c_scanner before everything else, and after your code ?

steeljack

The BQ76925 uses a condensed version of the I2C protocol where the device address and register address are combined into one address (to reduce overhead or something like that), but for what it's worth, here's what I get when I run the scanner
Code: [Select]
I2C Scanner
Scanning...
I2C device found at address 0x20 !
I2C device found at address 0x21 !
I2C device found at address 0x22 !
I2C device found at address 0x23 !
I2C device found at address 0x24 !
I2C device found at address 0x25 !
I2C device found at address 0x26 !
I2C device found at address 0x27 !
I2C device found at address 0x28 !
I2C device found at address 0x29 !
I2C device found at address 0x2A !
I2C device found at address 0x2B !
I2C device found at address 0x2C !
I2C device found at address 0x2D !
I2C device found at address 0x2E !
I2C device found at address 0x2F !
I2C device found at address 0x30 !
I2C device found at address 0x31 !
I2C device found at address 0x32 !
I2C device found at address 0x33 !
I2C device found at address 0x34 !
I2C device found at address 0x35 !
I2C device found at address 0x36 !
I2C device found at address 0x37 !
I2C device found at address 0x38 !
I2C device found at address 0x39 !
I2C device found at address 0x3A !
I2C device found at address 0x3B !
I2C device found at address 0x3C !
I2C device found at address 0x3D !
I2C device found at address 0x3E !
I2C device found at address 0x3F !
done


The address format is 01(5-bit reg address)

steeljack

I missed the bit about running it before and after my code. Here is what I get then

Code: [Select]
Scanning...
I2C device found at address 0x20 !
I2C device found at address 0x21 !
I2C device found at address 0x22 !
I2C device found at address 0x23 !
I2C device found at address 0x24 !
I2C device found at address 0x25 !
I2C device found at address 0x26 !
I2C device found at address 0x27 !
I2C device found at address 0x28 !
I2C device found at address 0x29 !
I2C device found at address 0x2A !
I2C device found at address 0x2B !
I2C device found at address 0x2C !
I2C device found at address 0x2D !
I2C device found at address 0x2E !
I2C device found at address 0x2F !
I2C device found at address 0x30 !
I2C device found at address 0x31 !
I2C device found at address 0x32 !
I2C device found at address 0x33 !
I2C device found at address 0x34 !
I2C device found at address 0x35 !
I2C device found at address 0x36 !
I2C device found at address 0x37 !
I2C device found at address 0x38 !
I2C device found at address 0x39 !
I2C device found at address 0x3A !
I2C device found at address 0x3B !
I2C device found at address 0x3C !
I2C device found at address 0x3D !
I2C device found at address 0x3E !
I2C device found at address 0x3F !
done

16
1023
Scanning...
No I2C devices found

Scanning...
No I2C devices found

1023
Scanning...
No I2C devices found

Krodal

I'm not sure, but does that mean that your code make the i2c-bus or the i2c device get stuck ?
This can happen, if there is a aknowlegde mismatch on the i2c-bus.

You could do more tests. A test with only reading from the device and another test with only writing to the device.

Can you perhaps make routines for reading and writing and make them from scratch ?

Go Up