Why can’t I control Port F on my ATMEGA32U4?

It took me about an hour and some Googling to realize why I couldn’t control any pins on PORTF on my ATMEGA32U4. The chip ships with JTAG fuses enabled from the factory, which means you cannot use PORTF as GPIO until you change the fuse settings. Alternatively, you can disable the JTAG port by modifying bit 7 of the MCU control register (MCUCR). The following excerpt from the datasheet explains how:

Bits 7 – JTD: JTAG Interface Disable
When this bit is zero, the JTAG interface is enabled if the JTAGEN Fuse is programmed. If this
bit is one, the JTAG interface is disabled. In order to avoid unintentional disabling or enabling of
the JTAG interface, a timed sequence must be followed when changing this bit: The application
software must write this bit to the desired value twice within four cycles to change its value.

The ATMEGA32U4 ships with the JTAGEN fuse programmed and the initial value for the JTD bit upon power-up is 0, therefore the JTAG interface is enabled and you cannot control PORTF as general I/O. After setting JTD to 1, you should be able to control PORTF as you wish.


One Response to “Why can’t I control Port F on my ATMEGA32U4?”

  1. Scott October 13, 2014 at 7:51 pm #

    Here’s sample code in case someone needs it.

    //disable JTAG in case it’s on
    uint8_t mcucp = MCUCR | (1 << JTD);
    //it takes two writes as per datasheet
    MCUCR = mcucp;
    MCUCR = mcucp;

Leave a Reply:

Gravatar Image