i2c PEEKing and POKEing registers on a slave device issue

Hi, New to the forum so please forgive me for any newbie mistakes!

Fundamental problem, thought it would be easy using the example code in the Arduino for WIRE master_reader , to read register values from a Analog Device AD9883A video chip.

Whilst I can successfully use the i2c Scanner to find the device (reports correct address 76H), I cannot read back any register values. Probably me not understanding correctly, so how should I read, for example, the contents (8-bits) of register of 00H from device with address 76H?

My circuit has the correct pull-up and series resistors implemented.

Thanks.

Hi GPSJay

I cannot read back any register values.

Please post your code, using code tags (the "#" button above the smileys). And can you say what happens when you try to read the registers?

Thanks

Ray

Hi,

The code is the modified master_reader example:

#include <Wire.h>

void setup()
{
  Wire.begin();        // join i2c bus (address optional for master)
  Serial.begin(9600);  // start serial for output
}

void loop()
{
  Wire.requestFrom(76, 6);    // request 6 bytes from slave device #76h

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }

  delay(500);
}

I get nothing at all displayed in the serial monitor window.

Thanks, GPSJay.

Device address "76" in your code is decimal 76. This equates to 0x4C in hexadecimal.

I've not used this IC, but looking at the datasheet, I think you need to send a base register address to the IC before you can read the register contents. There are details on page 23 of the REV B datasheet.

In your loop, before the requestFrom, try something like this:

Wire.beginTransmission(0x4C);
Wire.write(0x00);             // send base address
Wire.endTransmission();

The requestFrom should then read registers 0 to 5.

All the best

Ray

Hi Ray,

Not much luck with this i’m afraid ! I’ve burnt up a lot of time on this so will probably ‘park’ it for the moment, unless people want to give some help !?

What probably is confusing me is the combination of address and read/ write bit.

7 Bit address with 8th bit the read/ write indicator = what Hex value?
Does this go at the address transmission, or at the request from ?

// Wire Master Reader
// Demonstrates use of the Wire library
// Reads data from an I2C


#include <Wire.h>

void setup() 
{
  Wire.begin ();
  Serial.begin (115200);               //Serial monitor Baud rate
}

void loop()
{
  Wire.beginTransmission(0x4C);        // Address 0x4C Hex (76 Dec)
  Wire.write(0x00);                    // send base address
  Wire.endTransmission();              // End Transmission
  
delay(50);

  Wire.requestFrom(76, 6);             // request 6 bytes from slave device 76 Dec
  
   while(Wire.available())             // slave may send less than requested
   {
    char c = Wire.read();              // 
    Serial.println(c);                 // print the contents of the wire.read buffer
   }
  delay(1000);                         // Delay
}

Hi GPSJay

7 Bit address with 8th bit the read/ write indicator = what Hex value? Does this go at the address transmission, or at the request from ?

The device address goes in both a write (so, in this case, in the beginTransmission) and a read (in this case, in the requestFrom). The Wire library shifts the 7 bit address left one bit (so it fills bits 7 down to 1) and sets bit 0 to 1 or 0 depending on whether it is a read or write. The resulting 8 bits get sent down the wire. Since Wire does this, you don't need to worry about it in your code.

What if anything do you see on serial monitor when you run your program?

Regards

Ray

Hi Ray,

so if the device address is 4C hex, I put 0x4C in for both transmission and read?

If so, I have tried this and I get nothing. In fact i put a print message tracer in the code which isn’t appearing, so I guess its not getting that far i.e. no data read back and in the buffer.

// Wire Master Reader
// Demonstrates use of the Wire library
// Reads data from an I2C


#include <Wire.h>

void setup() 
{
  Wire.begin();
  Serial.begin (115200);               //Serial monitor Baud rate
}
void loop()
  {
  Wire.beginTransmission(0x4C);        // Address MSB 7 Bit = 4C Hex + 1 LSB Bit for read or write, all handled by wire library
  Wire.write(byte(0x00));              // Send base address
  Wire.endTransmission();              // End Transmission

  Wire.requestFrom(0x4C, 1);           // Request 1 byte to be read 
  
   while(Wire.available())             // Slave may send less than requested
   {
    Serial.println("in loop");         // Print a tracing message
    char c = Wire.read();             // 
    Serial.println(c);                 // Print the contents of the wire.read buffer
   }
  delay(1000);                         // Delay
}

My circuit has the correct pull-up and series resistors implemented.

Could you clarify which pull-up and series resistors you meant? Maybe sketch a circuit diagram and post a photo of it.

Hi, Sorry for the slow reply… I have attached a snapshot of the pull resistors for the device i2c.

Thanks for posting the diagram.

The 2.2k pull-ups look reasonable. I have not seen series resistors on I2C before but maybe they are required for this device.

On the code, only other thing I can think of to test is adding some delay before and after the requestFrom.

Hey Jason,are you using series resistors because the target device is running on 3.3v and your micro is at 5 ? Bob