1

I am trying to use i2c with ATmega16u4/ATmega32u4 in Proteus (version 8.5 SP1) and in my i2c code the following code line hangs the MCU:

while(wait && (TWI_MTX == twi_state)){

It never gets past this. Doing some debugging I verified that TWCR never changes in the Proteus simulation, so it is impossible to enable i2c, which is the cause of this hang.

I tried setting it directly, with TWCR=0xFF just for testing, but register value never changes, it is always 0 during the entire simulation. If I do the same thing on ATmega328p the register does change successfully.

If I upload the code to a physical processor it works fine. If I use the same code on ATmega328p simulation in Proteus, it also works.

This is not a pull up resistor or communication issue. I have 4.7k digital pull ups connected, but the thing is, the pins never get to change states in the first place, because I cant get the MCU to set i2c enable registers.

This looks to me like a Proteus model problem or bug. Has anyone got ATmega32u4 to work with i2c in Proteus simulation?

cyberponk
  • 662
  • 6
  • 10
  • 3
    Possible duplicate of [ATmega16u4 and ATmega32u4 i2c bug in Proteus?](http://electronics.stackexchange.com/questions/286295/atmega16u4-and-atmega32u4-i2c-bug-in-proteus) – uint128_t Feb 13 '17 at 19:07

2 Answers2

1

This looks to me like a Proteus model problem or bug.

another possibility is that the header file didn't have the right definition for TWCR. check against the datasheet.

dannyf
  • 4,272
  • 1
  • 7
  • 9
  • This is a great observation, but the same HEX file runs flawlessly on the physical microcontroller, so the header files have to be right. I´ll give it a check anyway. – cyberponk Feb 14 '17 at 01:16
1

I had the same problem. Fix for me was to update PROTEUS to v 8.8

jusaca
  • 8,749
  • 4
  • 36
  • 58
user257937
  • 11
  • 2