Arduino due as slave in i2c

DUE is slave in i2c and the master is Atmel AVR. The following code is the parameter passed for i2c write for Master.

 typedef struct {
/* ! TWI chip address to communicate with. */
char chip;
/* ! TWI address/commands to issue to the other chip (node). */
uint8_t addr[3];
/* ! Length of the TWI data address segment (1-3 bytes). */
int addr_length;
/* ! Where to find the data to be written. */
uint8_t *buffer;
/* ! How many bytes do we want to write. */
unsigned int length;

} twi_package_t;

Here the chip address is the slave address. In Wire.begin(0x02) the slave address is defined. The problem here is the TWI Address/commands. What must I mention for Arduino? Usually there is nothing mentioned here.

Does this help?

not actually :frowning: ,because I program the i2c master in Atmel avr in Atmel studio and Arduino as slave in Arduino IDE. The code above id for the Master in Atmel studio. In the second parameter we have to mention the slave's code to write the data in it. But in arduino, just address of the slave is present. So what should be mentioned ?

The arduino address is the address the AVR master needs to use to talk to the arduino, there is arduino slave code listed in the previous link, below the arduino master code.
Note that the master and slave code are using the same address, because the master is addressing the slave, by the slave address. The master has no address of its own (unless you make it a slave as well).
Does that help, or have I not understood the problem?

weird_dave:
The arduino address is the address the AVR master needs to use to talk to the arduino

Yes this is the slave's address. It is clear. My point is ,my master is programmed in another IDE. I have included that code part earlier. It asks for the "slave address" and it asks for another parameter called "slave memory address" - it says at which address in the slave should I write my data? . This is my doubt.

I see, the AVR code sounds like it is designed to address a memory device, which of course the Arduino isn't. The simplest option is to rewrite the AVR code to just send/receive data of a specific length. If you can't do that, the next simplest option is to make the Arduino ignore the address.
A more complex option would be to use the address to access different data sets.

You may want to take a look at a memory datasheet: (any will do, this is just to demonstrate what is going on)

page 9, section 7 onwards is the interesting stuff.

Thank you for the support. I would definitely try this :slight_smile: :slight_smile: