How to handle multiple request events in Atmega328p using I2C communication

Hello All,

I am using two different Arduino Uno and I am trying to establish a communication between them using I2C. What i need is a specific Ram Address for the data stored in the slave device such that I can poll for each data separately in the master device. Is that possible using arduino? Any help is greatly appreciated!

Thank you!
Akhil

What specific ram address? That's not very common in a higher level (with a little exception for pointers). So what is that magic ram address?

But you, you can make a slave Arduino return data. How you decide what to send is based on how you implement a protocol and what you really want to do.

1. This is the RAM memory map of the ATmega328P MCU of the Arduino UNO:
ram.png

2. Let us assume that you have chosen the following two RAM locations of your UNO-Slave to contain the data bytes as indicated:

(0x0100) = 0x12
(0x0105) = 0x34

3. Now you want to tell the Master to command the Slave to send the content of RAM location of 0x0100 (0x105) when request comes from the Master.

You can always achieve the target of Step-3; but, you have write appropriate codes for both the Master Sketch and Slave Sketch using the I2C Bus Protocol. Try to write some codes; test them; if they work, it is fine; else, post them in this thread; there are people around to help you generously!

BTW: Post#1 has hinted you to use pointer to handle RAM locations using their numerical addresses. The following codes (they store a data byte 0x12 into RAM location 0x0100 of Slave) could help you if you are not comfortable with the usage of pointer variable.

byte *ptr;
ptr = 0x0100;  //pointer variable ptr now holds the address 0x0100 into where you wish to store a data byte
*ptr = 0x12;   //data byte 0x12 has enetered into RAM location 0x0100

ram.png