I2C Communication with FUSB302B - Address to hex?

I was hoping you all could help with a question I have about writing and reading from I2C enabled device. The device I'm hoping to read data from is the PD controller "FUSB302B". I would like to write the MEASURE register which address is "04h". My background in firmware isn't very strong so I'm not to sure how that address correlates with the hex value you put into Wire.write(). Below is my code:

void loop()
	byte data;
	Wire.beginTransmission(34);                               //0x22 to decimal 
	Wire.write(byte("address 04h to hex?));            // sends instruction byte
	Wire.requestFrom("address 04h to hex?", 1);
		data = Wire.read();

The PD controller's datasheet:

What have you done ? Are you using real tabs in the source code ? How did that happen ? Are you also wearing a top hat and a cane when you go outside ? Can you change your editor settings and run a tool on all your *.ino files to change the real tabs into spaces ?

The requestFrom() reads from a I2C address, but you got the global idea.
Don't keep the I2C bus busy all the time, add a delay in the loop().
The datasheet shows a "repeated start".

Can you find a I2C Scanner sketch, let it run to see if it finds its I2C address.
Then you know that the I2C bus is working.
Use the found I2C address in your sketch.

Then try to read its Device ID.

void loop()
  Wire.beginTransmission(0x22);    // I2C address
  Wire.write( 0x01);               // Register address
  Wire.endTransmission(false);     // false for a repeated start
  int n = Wire.requestFrom(0x22, 1); // request 1 byte
  if( n == 1)         // received the same amount of bytes that was requested ?
    data = Wire.read();
    Serial1.println(data, HEX);
    Serial1.println("Error, can't see the chip");

  delay( 1000);

If that Device ID makes sense, then you know that you can read from a register.
Writing data to register 0x04 is like this:

  Wire.beginTransmission(0x22);  // I2C address
  Wire.write( 0x04);             // Register address
  Wire.write( 0x33);             // The data. I just gave an example, don't use 0x33

Haha, I edit in Microchip Studio and use Ardunio core.

The device address is 0x22 (actually confirmed with the I2c scanner so great tip).
I just get confused when it comes to datasheets sometimes (my background is mostly system and board design) so thank you for the clarification.

So the short answer is when a datasheet stataes the address of the register is 0ah, it's 0x0a in hex (a being a varible in this situation).

It is just a notation.

In a document
A hexadecimal value can be written as A0h or A3HEX
Sometimes 23DEC is used in a document to indicate that it is a normal decimal number.

In the 'C' and 'C++' language
A hexadecimal number is 0x25
There is also 0b01000010 for a binary notation.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.