I2C protocol with arduino uno as master and an AVR microcontroller as slave

Hi to everyone!!
Im new in arduino also in C++ programing…That what i have to do is to read temperature data for an AVR microcontroller… this microcontroller is reading three temp sensors. And what i have to do is to go to regester of this microcontroller an to recieve those data… is anyone here who can tell me what to read or if can give me any example!!

thanks!!! :slight_smile:

this is my code but is for reciving dota for each device not for each register… how can I change it???

#include <Wire.h>
int address1 = 17; //decimal address of sensor 1
int address2 = 33; //decimal address of sensor 2
int address3 = 65; //decimal address of sensor 3

int c1;
int c2;
int c3;

void setup()
{
Serial.begin(9600);
Wire.begin();
}

void loop()
{
int c1 = read_temp(address1);
int c2 = read_temp(address2);
int c3 = read_temp(address3);

Serial.print("Sensor 1: ");
Serial.print(c1);
Serial.print("C | ");

Serial.print("Sensor 2: ");
Serial.print(c2);
Serial.print("C | ");

Serial.print("Sensor 3: ");
Serial.print(c3);
Serial.println(“C”);
delay(500);
}

int read_temp(int address)
{

Wire.beginTransmission(address);
//Wire.write(0);
// Wire.endTransmission();
Wire.requestFrom(address, 2);

if (address=17)
{
c1=Wire.read();
}

if (address=33)
{
c2=Wire.read();
}

if (address=65)
{
c3=Wire.read();
}
/* while (Wire.available() == 0);
{
float c = Wire.read();
return c;
}*/
}

tonig123:
Hi to everyone!!
Im new in arduino also in C++ programing…That what i have to do is to read temperature data for an AVR microcontroller… this microcontroller is reading three temp sensors. And what i have to do is to go to regester of this microcontroller an to recieve those data… is anyone here who can tell me what to read or if can give me any example!!

thanks!!! :slight_smile:

this is the code which Im using…the problem is tha this code is reading data from diferent devices.I want to make it to change it to rede data from the same device and different register…

#include <Wire.h>
int address1 = 17; //decimal address of sensor 1
int address2 = 33; //decimal address of sensor 2
int address3 = 65; //decimal address of sensor 3

int c1;
int c2;
int c3;

void setup()
{
Serial.begin(9600);
Wire.begin();
}

void loop()
{
int c1 = read_temp(address1);
int c2 = read_temp(address2);
int c3 = read_temp(address3);

Serial.print("Sensor 1: ");
Serial.print(c1);
Serial.print("C | ");

Serial.print("Sensor 2: ");
Serial.print(c2);
Serial.print("C | ");

Serial.print("Sensor 3: ");
Serial.print(c3);
Serial.println(“C”);
delay(500);
}

int read_temp(int address)
{

Wire.beginTransmission(address);
//Wire.write(0);
// Wire.endTransmission();
Wire.requestFrom(address, 2);

if (address=17)
{
c1=Wire.read();
}

if (address=33)
{
c2=Wire.read();
}

if (address=65)
{
c3=Wire.read();
}

}

this microcontroller is reading three temp sensors.

Is that three temporary sensors? If so, come on back when you get the permanent ones.

If that is three temperature sensors, it would be useful to know which ones. There are libraries for reading most one wire temperature sensors.

Three attempts to get the code shown. Still not right. Sigh...

the microcontroller ATXMEGA128A1U

this microcontroller (ATXMEGA128A1U ) is programmed to drive 3 high power LED and to measure the temp from each one.. my aim is to take that data with arduino as master.