I am trying to write and read i2c using an ESP32 board

I am a beginner with Arduino.
I am trying to write and read i2c using an ESP32 board.
i2c writing has been done.
But I couldn't read the register.
I want 0x0A to be called at registor address 0x09.
The source code is as below.
The logic analyzer results are as follows.

#include <Wire.h>

byte ADDRESS_SLAVE = 0X3B;
byte REGISTER_XY = 0X09;
byte READ_LENGTH = 1;

void setup()
{
Wire.begin();
Wire.setClock(100000); // set I2C 'full-speed'
Serial.begin(115200);
}

void loop()
{
Wire.beginTransmission(0X3B);
Wire.write(0X09); // set register for write
Wire.write(0X0A); // set register for write
Wire.endTransmission(); // false to not release the line

Wire.beginTransmission(0X3B); // Begin communication with slave address  (0X3B)
Wire.write(0X09); // set register for read
Wire.endTransmission(false); // Send the restart condition

Wire.requestFrom(0X3B, 1); // Perform read request from slave address 0X3B and read 1 byte from the register that it is pointed at (0X09)
byte READ = Wire.read(); // Read the byte that was received
delay(1000);

}

Welcome to the forum

Your topic was MOVED to its current forum category as it is more suitable than the original because it is not an Introductory Tutorial

Your topic was MOVED to its current forum category as it is more suitable than the original

When you posted your code without code tags did you receive a warning message ?

are you sure of the device address (0x3b)?
do you have pull-up resistors?
is register address 9 writable?
what device are you communicating with?

this is the sequence i use to read

    Wire.beginTransmission (chip);
    Wire.write (port);    
    Wire.endTransmission ();

    Wire.requestFrom (chip, 1); //get 1 byte
    byte val =  Wire.read ();

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