For the last 2 days I can't get I2C communication with DS1307 RTC working.
My program hangs when it needs to wait for TWINT to be set by hardware. Don't know what to do.
I'm 99.99% sure hardware is OK. I tried internal pull ups and external later. No change.
IC2_wait is where it all stops, endless loop (tested with LCD display, it read some wierd stuff for TWCR)
Here is some of my code
reset: ldi r16, 0x04 out SPH, r16 rcall LCDInit rcall I2Cinit ldi r16, 0xD0 rcall I2C_start ldi r16, 0x07 rcall I2C_write ldi r16, 0x10 rcall I2C_write rcall I2C_stop loop: rjmp loop ; VOID || VOID I2Cinit: push r16 ;Clock <100kHz ldi r16, 20 out TWBR, r16 clr r16 out TWSR, r16 pop r16 ret ; R16=SLA_W or SLA_R || VOID I2C_start: push r17 ;START ldi r17, (1<<TWINT) | (1<<TWSTA) | (1<<TWEN) out TWCR, r17 rcall I2C_wait ;START OK? in r17, TWSR andi r17, 0xF8 cpi r17, START brne I2C_error ;ADDRESS out TWDR, r16 ldi r17, (1<<TWINT) | (1<<TWEN) out TWCR, r17 rcall I2C_wait ;ADDRESS OK ? in r17, TWSR andi r17, 0xF8 cpi r17, MT_SLA_ACK brne I2C_error pop r17 ret ; VOID || VOID I2C_wait: push r16 loop69: in r16, TWCR sbrs r16, TWINT rjmp loop69 pop r16 ret