I2C interfacing with ATmega32 and ArduinoMega2560 failed

arduinoatmegaavrembeddedi2c

I'm trying out I2C interfacing the ATmega32 with Arduino Mega2560 Board without success.

The Arduino Board is configured to be the Master Read.
The Atmega32 is configured to be the Slave Write.

I have connected the wires like in the Image below:

Image

The Code for ATmega32 in Atmel 6:

#include <avr/io.h>

#include "I2C_slave.h"

void i2c_initSlave(unsigned char slaveAddress)
    {
        TWCR = 0x04;
        TWAR = slaveAddress;
        TWCR = (1<<TWINT) | (1<<TWEN) | (1<<TWEA);
    }

    //*************************************************

    void i2c_send(unsigned char data)
    {
        TWDR = data;
        TWCR = (1<<TWINT) | (1<<TWEN);
        while ((TWCR & (1<<TWINT))== 0);
    }

    //*************************************************

    void i2c_listen()
    {
        while ((TWCR & (1<<TWINT)) == 0);
    }


int main(void)
{
    int PIN = 0x02;
    DDRC &= ~PIN;  

    i2c_initSlave(0x90);

    i2c_listen();
    i2c_send("G");

    while(1)
    {
        return 0; 
    }
}

The Code for Arduino Board:

#include <Wire.h>

#define TRANCEIVER_ADDRESS 0x90


void setup()
{
  Wire.begin(TRANCEIVER_ADDRESS);  // join i2c bus (address optional for master)
  Serial.begin(115200);  // start serial for output
}

void loop()
{
  Serial.println("HALLO");

  Wire.requestFrom(TRANCEIVER_ADDRESS, 2);

  while(Wire.available())    // slave may send less than requested
  { 
    char c = Wire.read(); // receive a byte as character
    Serial.print(c);         // print the character
  }

  delay(500);
}

As described in the code, I use Address 0x90 to establish the connection and send the character "G" from ATmega32 to Arduino. The output i got in the SerialCommand Window in Arduino IDE is like in the image below:
enter image description here

That means NO CONNACTION !!!

Could someone spot the problem? I think the problem is in the ATmega32 code.

Is the DDRC and PORTC configured correct to the MASTER READ?

DDRC=0xFF;
PORTC=0x00;

I'am not sure. Or should the PORTC be

PORTC=0xFF;

Could someone explain me?

Best Answer

In PIC code as slave I2C, use:

i2c(Slave, sda=PIN_C4, scl=PIN_C3, address=0xa0, FORCE_HW, FAST);

In Arduino code as master I2C, use:

const int SLAVE_ADDRESS2 = 0xA0;  // esclavo PIC
Wire.beginTransmission(SLAVE_ADDRESS2 >> 1);