Go Down

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


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

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
reg address LSB
reg address MSB

Device address, read bit
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.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?



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.


Go Up