1
\$\begingroup\$

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?

\$\endgroup\$
1
0
\$\begingroup\$

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.

\$\endgroup\$
1
  • \$\begingroup\$ 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. \$\endgroup\$ – cyberponk Feb 14 '17 at 1:16
0
\$\begingroup\$

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

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.