0

I am using the SW6106 powerbank IC as an I2C but no matter what I have tried I couldn't read something other than "FF".

Datasheet for the IC.

Timing diagram for reading data: Read Timing Diagram

Timing diagram for writing data: Write Timing Diagram

The code I use:

#include <Wire.h>

byte ADDRESS_SLAVE = 0x3C; 
byte REGISTER_XY = 0xB0;
byte READ_LENGTH = 1;

void setup() {
  Serial.begin(115200);

  Wire.begin();
  Wire.setClock(400000); // set I2C 'full-speed'

  Wire.beginTransmission(ADDRESS_SLAVE);  
  Wire.write(REGISTER_XY);  // set register for read
  Wire.endTransmission();
}

void loop() {
   Wire.requestFrom(ADDRESS_SLAVE,READ_LENGTH); 
   byte buff[READ_LENGTH];    
   Wire.readBytes(buff, READ_LENGTH);
   for (int i = 0; i < READ_LENGTH; i++) {
     Serial.println(buff[i], HEX);
   }
   Serial.println();
   delay(1000);
}

Serial monitor output: Serial Monitor

I really couldn't understand anything from that timing diagram and couldn't read anything from the IC. I'd appreciate any help.

Edit: I edited the code a little bit to see what Wire.endTransmission(); returns.

#include <Wire.h>

byte ADDRESS_SLAVE = 0x3C; 
byte REGISTER_XY = 0xB0;
byte READ_LENGTH = 1;

void setup() {
  Serial.begin(115200);

  Wire.begin();
  Wire.setClock(400000); // set I2C 'full-speed'
}

void loop() {
  Wire.beginTransmission(ADDRESS_SLAVE);  
  Wire.write(REGISTER_XY);  // set register for read
  int x = Wire.endTransmission();
  Serial.println(x, DEC);
  delay(200);
}

And it retruns the following: endTransmission

I really don't know where I am doing wrong.

15
  • Have you tried the I2C scanner to check it's on the right address? Sometimes the quoted address in datasheets is the 7-bit address and sometimes the 8-bit address.
    – Majenko
    Nov 22, 2019 at 21:31
  • @Majenko Yes, I have tried it and I can confirm it's on the right address.
    – efe
    Nov 22, 2019 at 21:49
  • The way that I2C works on that chip, looking at the diagrams, is perfectly normal. Maybe if you move the write (register select) into the loop to just before the read?
    – Majenko
    Nov 22, 2019 at 22:38
  • Is pin LED4/I2C connected to ground?
    – Majenko
    Nov 22, 2019 at 22:41
  • You ignore both the return values from Wire.endTransmission() and Wire.requestFrom(). Please output them to the Serial monitor for debugging. Wire.endTransmission() returns a status code and Wire.requestFrom() returns the number of bytes actually read.
    – chrisl
    Nov 23, 2019 at 0:27

1 Answer 1

1

I know this post is very old, but I was able to get the register map from the manufacturer, Ismartware. Here's a link to the datapack for anyone else that may end up here while searching for the same thing.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.