0

Accessing all the pins on the Atmega32u4 breakout
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Accessing all the pins on the Atmega32u4 breakout

by colinta on Wed Nov 07, 2018 12:25 pm

In particular, how do I access D5? Looking at the diagram at https://learn.adafruit.com/atmega32u4-breakout/design I see that, e.g. E6 is accessed using "pin 7" (pin mapping label is D7). But D5 doesn't have a pin mapping; usually it's hooked up to the TXLED.

Is there a way to control this pin in Arduino wiring code, or do we have to resort to using the PORTDx "commands" (which I know exist, but I'm not familiar with).

colinta
 
Posts: 12
Joined: Tue Apr 01, 2014 10:13 am
Location: Denver, CO

Re: Accessing all the pins on the Atmega32u4 breakout

by adafruit_support_mike on Thu Nov 08, 2018 12:51 am

That pin isn't broken out to the edge of the board, and the board support package doesn't provide a convenience mapping for the digitalWrite() function. To control that pin, you'll have to use PORTD bit manipulation.

That process isn't so bad.. PORTD is a register in the ATmega32u4's memory whose bits are mapped to physical pins at the edge of the chip. When you set a bit in PORTD, the corresponding pin goes high or low.

There's also a memory register named DDRD which controls the pin's configuration. Setting a bit in DDRD configures a pin as an output (the pin will mirror the value you set in PORTD), setting the bit to 0 configures the pin as an input (PORTD will mirror the signal connected to the pin).

This page shows the basics of port manipulation:

https://www.arduino.cc/en/Reference/PortManipulation

adafruit_support_mike
 
Posts: 58843
Joined: Thu Feb 11, 2010 2:51 pm

Re: Accessing all the pins on the Atmega32u4 breakout

by colinta on Wed Nov 14, 2018 12:26 pm

Thanks, Mike! But D5 *is* broken out on the side... the only I/O pin I don't see is E2. Why is that, btw?

I'll use PORT/PIN/DDR registers, that works for me.

colinta
 
Posts: 12
Joined: Tue Apr 01, 2014 10:13 am
Location: Denver, CO

Re: Accessing all the pins on the Atmega32u4 breakout

by colinta on Wed Nov 14, 2018 12:33 pm

Looking closely at the schematic... E2 goes to "HWB" - aka reset button? or is this a "do what you want" button? D5 is wired to an LED. Again is this for funsies?

colinta
 
Posts: 12
Joined: Tue Apr 01, 2014 10:13 am
Location: Denver, CO

Re: Accessing all the pins on the Atmega32u4 breakout

by adafruit_support_mike on Fri Nov 16, 2018 12:48 am

Sorry, I was looking at the wrong schematic.

Referring to this one:

https://cdn-learn.adafruit.com/assets/a ... 1473702355

the pin identifed as PORTD5 in the ATmega32u4 datasheet connects to a pin labeled D5.

That board has been discontinued, which was part of my confusion.

The /HWB signal is a built-in feature of the ATmega32u4 described in section 10.3.5 of the datasheet. The full name is Harware Bootloader. If the HWBE flag is set and /HWB is pulled low when the chip resets, the chip will execute firmware loaded in its protected bootloader memory when it starts up. If /HWB is left high during a reset, the chip will start executing the firmware in its bootloader-programmable memory.

adafruit_support_mike
 
Posts: 58843
Joined: Thu Feb 11, 2010 2:51 pm

Please be positive and constructive with your questions and comments.