Hello, i am having strange problems interfacing EEPROM with ATmega32.
I have tested the code on Proteus simulation and it works. I have checked the connections and everything seems to be ok. The SPI is getting initialized, the physical EEPROM is responding to start condition with a 0x08 but when i send device address afterwards it simlpy does not respond with 0x18. Instead it is giving NO ACK i.e 0x20..
A2 and A1 pins are grounded so i used 0xA0 as device address. I even tried using 0xA4, 0xA8, 0xAC as device address but just does not respond to anything
My code is a bigger one but here is the most basic code i programmed on it just to check where is the problem.
#define F_CPU 16000000UL #include#include #include int main(void) { DDRD=0xFF; PORTD=0xFF; //INT TWBR=0x12; // Bit rate TWSR=(0<<TWPS1)|(0<<TWPS0); //prescaler configured to make 100KHz SCL frequency //SEND START TWCR= (1<<TWINT)|(1<<TWSTA)|(1<<TWEN); while(!(TWCR & (1<<TWINT))); while((TWSR & 0xF8)!= 0x08); _delay_ms(50); //SEND DEVICE ADD TWDR=0xA4; TWCR=(1<<TWINT)|(1<<TWEN); while (!(TWCR & (1<<TWINT))); while((TWSR & 0xF8)!= 0x18); flash(); _delay_ms(1000); /*This is where the code hangs because it is not receiving 0x18 but if i set it to 0x20 then code runs i.e its returning NO ACK*/ //SEND ADD MSB TWDR=0x00; TWCR=(1<<TWINT)|(1<<TWEN); while (!(TWCR & (1<<TWINT))); while((TWSR & 0xF8)!= 0x28); //SEND ADD LSB TWDR=0x00; TWCR=(1<<TWINT)|(1<<TWEN); while (!(TWCR & (1<<TWINT))); while((TWSR & 0xF8)!= 0x28); //SEND DATA TWDR=0xAA; TWCR=(1<<TWINT)|(1<<TWEN); while (!(TWCR & (1<<TWINT))); while((TWSR & 0xF8)!= 0x28); //SEND STOP TWCR= (1<<TWINT)|(1<<TWEN)|(1<<TWSTO); while(!(TWCR & (1<<TWSTO))); // Wait till stop condition is transmitted _delay_ms(50); } void flash(void) { PORTD=0x00; _delay_ms(200); PORTD=0xFF; _delay_ms(200); PORTD=0x00; _delay_ms(200); PORTD=0xFF; _delay_ms(200); }