I have a good grasp on how i2c works but need help with detail to troubleshoot my application. I love hardware base protocols when they work but when they don't it's a pain to fix.
My issue is I'm not always getting the ISR to fire and when I do, I get a error (0x00). I'm also not sure what makes it fire as most of the time it does not. I though it watches for SDA to fall followed by clock (start). I have set up a basic slave to talk to a known master (wii-mote). It does use i2c its the normal form AFAICT using 400kHz "fast" I2C, with slave address 0x52. I see on the scope that the master sends its address and data constantly. I can set up my slave to read the data but either my app seems to freeze once I enable the interrupts or I get 0x00 in ISR.
So questions are;
1) What part of the message triggers the ISR? Start bit or end bit? It looks like my scope triggers on start bit when it does. If it should trigger on stop bit, is there a significant delay before the IRS is called.
2) What could ause a buss error (0x00). My scope shows the wave form correctly, I see nothing wrong with it.
3) Why would I get a ISR event sometimes, other times all communication just stops, or the lines goes dead (SCL low SDA high) as soon as I enable my interrupts.
Observations, I see the master sending a write at 0x58 of 37. Then I see a read at 0x58 of 0xff ( 7 more FF's). Guessing this is all specific to the use case of the master. Then it repeats endlessly. I start my slave and after the set up and starting my interrupts I get one of 3 conditions.
1 SDA line is high SCL is low and nothing changes, app seems to be frozen
2 Master continues to talk but my app seems to be frozen.
3 I get a reply from ISR of 0x00 then my app seems to be frozen.
I'm not sure what makes my results change but does not seem to be random. I'm using know working code examples. Nothing special going on there but happy to show the code if that is asked for. I just feel there is more of a hardware issue here. Happy to provide more info about the master and the wiring.
In the simplest sense I'm doing this.
twi_ddr &= ~0x03; twi_reg_addr = 0; TWAR = addr << 1; TWSR = 0; TWBR = ((F_CPU / 400000) - 16) / 2; TWCR = _BV(TWIE) | _BV(TWEA); TWCR |= _BV(TWEN); sei();
After the sei command I get nothing further from the code.
Using an atmega32u4
Master is a Nintendo Wii-mote
Data is encrypted and runs at 400Hz
The project I'm using is found here. http://code.google.com/p/circle-...
I'm not using any external pull ups as the mega MCU is pointed out to be enough.