I am trying to get the I2C working on a MEGA324 since the last 2 days to no avail, so, I need to ask here perhaps a much more experienced person may know what is going on.
My first try was to use the libraries from Pascal Stang which I've implemented and tested OK with the ATMEGA168.
I have a board with an ATMEGA324 which uses the FT245 chip FIFO to USB (virtual serial) and as i use USB power I prefererred it over the 168 which requires its own power plus a USB to serial converter.
My first try was a direct copy and paste and I made a new project on AVR Studio using the ATMEGA324.
What I found out is that whenever the send start function is called, the whole program works like a never ending loop for all the instructions above this statement to the beginning of the main().
I replaced Pascal's i2cSendStart() by the explicit instruction from the MEGA324 manual:
TWCR = (1<<TWINT)|(1<<TWSTA)|(1<<TWEN);
Exactly same problem , the main behaves like a never ending loop and executes all instructions above this statement.
Then I've written above as
TWCR = (1<<TWINT)|(1<<TWSTA); TWCR =(1<<TWEN);
Now at least the loop stopped but of course there are like four or five more calls . So I replaced this on all sendstart() but now any other function like write byte etc is the same. Conclusion: anything related to the I2C produces this.
I then decided to change the whole library and use Peter Fleury's , but EXACT same problem !! the I2C will not work.
I've also changed the CHIP with same result.
The attached i2c_FTDI.c is the program.
Please let me know any addittional details you may need .
Could it be a hardware issue ? could be a problem with the clock Frequency? it is using internal RC at 8 MHZ.
Thanks a million in advance for any clue I keep trying but really running out of options on what to change.