Go Down

Topic: Cannot get wire.send to send more than 2 bytes (Read 555 times) previous topic - next topic

Lawmate

Oct 22, 2019, 10:43 pm Last Edit: Oct 22, 2019, 10:44 pm by Lawmate
Hi

I am working to try and communicate with a BQ4050 battery fuel gauge from TI. There are some settings that are stored on board in flash memory. On page 92 of the technical reference manual there is some info on how to read and write to these registers.

As I understand the format is:
Device address, write bit
0x44
reg address LSB
reg address MSB

then
Device address, read bit
0x44
read byte

The thing that I don't understand is when using the wire library I have the following code

Code: [Select]
byte readDFByteReg( char devAddress, byte regAddress1, byte regAddress2 ){
 
  byte dataByte = 0;
  byte sentData[3] = { 0x44, regAddress2, regAddress1 };

  Wire.beginTransmission( devAddress );
  Wire.send( sentData, 3 );
  Wire.endTransmission();
  delay(5);
 
  Wire.requestFrom( devAddress , 1);
  Wire.write( 0x44 );
  if( Wire.available() > 0 ){
    dataByte = Wire.receive();
  }

  return dataByte;
}


But when I look at the output of the pins, the Arduino always ends the transmission after sending only 2 of the 3 bytes. I have tried sending 4 or 5 bytes, but it still will only send 2 bytes. As I understand the transmit buffer size is 32 bytes, so I'm a littel confused as to why I can only send 2 bytes. Is it because the device is nacking after the 2nd byte?

Thanks


Lawmate

OK, after further reading, the Wire.endTransmission()  call returns a error number 3, which according to this page https://www.arduino.cc/en/Reference/WireEndTransmission means the data was responded with a nack, as I saw on the analyser.

I will need to research more into how to get access to this data flash on the BQ4050.

Thanks

Go Up