Let's Make Robots!

connecting two ATmega328p chips using l2C/TWI (C-language)

Hey everyone. I am new to coding for arduino in pure C. I spent the whole week trying to hook up my two Atmega328p chips using l2C, everything that I find out there never works. I just want a simple communication where I send one byte to the slave that turns on an LED on the slave. Please if anyone has tried this please help.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

So it sounds like you aren't having trouble uploading the code. So is it how your using the code?
I looked at the tutorial you linked to. Are you uploading the I2Cmaster.c to one and the I2Cslave.c to the other.
The slave avr is emulating the microchip io expander chip using PORTD. Did you connect leds to PORTD as in the schematic on the page?
How far have you got with this? What error messages if any or what isn't working as you'd expected?

I followed everything on the tutorial ( connected Leds, l2c master code on one chip and slave code on the other). Both codes compiled with no errors . However when I power up the whole thing nothing happens. Could it be because I am running at different clock from the tutorial (I'm using 16mhz crystal and the tutorial recommends 1105200hz)?

Did you set it to 16000000 hz in the configuration. Don't copy their value.
Also if you modify the line TWBR = 0x30 to TWBR = 0x48 it will make the I2C master 100khz clock which will give you close to the same bus speed as the example 98.743khz.
According to the bitrate formula

 // SCL frequency = 11059200 / (16 + 2 * 48 * 1) = 98.743 kHz  (0x30 = 48 decimal)
if all you did was changed the 11MHZ to 16MHZ in configuration then you are running it at 142.857 kHz

Also have you got the 10k ohm pullup resistors on the SDA and SCK pins. They are absolutely essential.

I think you confusing clock and baud rate there. Entirely different things.

No. That is the clock rate they compiled the code with.

so it is.

Its probably a good idea to compile using the same clock speed that they are 

Share some code or links to what tutorials you've followed, it's really hard to diagnose a problem when the only symptom is "It doesn't work".

Here is the tutorial.
Just so we understand what's going on here, by "...coding for Arduino in pure C..." do you mean you are not using the Arduino IDE and bootloader, instead writing the code in another editor and using a separate ISP to program an ATMega?
I'm using text editor to write code and compile it using AVR-GCC. The arduino still has the bootloader and code is uploaded using avrdude.