How to send i2c data from arduino uno

Hi All

i try to learnin aruino with diy project to send i2c data from arduino uno.
i'd like to generate data like this

send to address 0x01
write 00 AB 00 85 00 02 01 01 89 CD

have a look at Arduino I2c
in your application is the Arduino to be a master or a slave

hi horace

thank you for replay
my arduino be master

here is i2c signal that is want to generate but i don't know how to start to writing code

have a look at the Controller Writer Sketch which is an I2C master transmitting a string and a byte using the Wire.write() method - you can copy this code as a start for your program
the Arduino wire library is used - have a look at the code of the Controller Writer Sketch and try to understand what the Wire statements are doing.
You can create an array to hold your data 00 AB 00 85 00 02 01 01 89 CD and use the Wire.write(data, length) to transmit it

Please post a link to the device at that address. It has to respond correctly, or your program will not work.

for my understand i want to writing i2c signal follow attach picture.

i not sure how to start to writing code and will learn to use Wire.write(data,leangth)...

i just sample writing as below to see response and got as attach signal from digitl analyzer (by pulseview)

#include <Wire.h>

void setup()
{
Wire.begin(0x01); // join i2c bus (address optional for master)
}

void loop()
{
Wire.beginTransmission(0x01); // transmit to device #4
Wire.write(0x00); // sends five bytes
Wire.endTransmission(); // stop transmitting
delay(500);
}

copy the Controller Writer Sketch code and paste it into the Arduino IDE
edit the data transmission part in loop() to match your slave address and your data transmission requirements.
What slave are you communicating with? how will it respond?

your Wrire.begin() in setup does not require a parameter as it is the master
try

#include <Wire.h>

void setup()
{
  Wire.begin(); // join i2c bus (address optional for master)
}

void loop()
{
  byte data[]={1,2,3};
  Wire.beginTransmission(1); // transmit to device #1
  Wire.write(data, sizeof(data));        // sends five bytes
  Wire.endTransmission();    // stop transmitting
  delay(500);
}

receiver

#include <Wire.h>

void setup()
{
  Wire.begin(1);                // join i2c bus with address #1
  Wire.onReceive(receiveEvent); // register event
  Serial.begin(115200);           // start serial for output
}

void loop()
{
  delay(100);
}

// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
  while(Wire.available()) // loop through data received
  {
    byte c = Wire.read();   // receive byte as a byte
    Serial.print(c, HEX);   // print the byte
    Serial.print(" ");
  }
  Serial.println();         
}

receiver displays

1 2 3 
1 2 3 
1 2 3 
1 2 3 

i try to copy and plate your code and see response by logic analyzer then get result as attach picture.

here is my setup

copy the code and replace the array "1,2,3" values with your data "00 AB 00 85 00 02 01 01 89 CD"

What is the slave device you are sending to, and its address.

If you have no receiving device there will not be a correct ack and you will not see what you expect.

I assume the slave is the Logic analyser in post #12 photo and its address is 0x01

A logic analyzer is not an I2C device. It cannot be the slave. You need some device to actually address.

perhaps the logic analyser is being used to look at the I2C signals
when correct the Uno will be connected to the intended target

perhaps we need a reference to the manual for the intended target?

here is result from the array 0x00,0x02x0x03


the

if i not connected slave device will can't get real i2c data right?
now i writing code and check by digital analzer as setup on bench arduio to digital analyzer.

i try again to writing code in setup

then got result as attach picture

i try again move code in setup to loop and got result as attach

as my code i2c generate only loop "write address 0x01" but not start to write data "0x00,0x01,0x02"