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.
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 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.