Go Down

Topic: ATMEGA32U4 Breakout Board Issue - Analog Pins as Digital (Read 2299 times) previous topic - next topic

32teeth

Hey all

i have an interesting issue i can't seem to figure out.
i have an ATMEGA32U4 Breakout Board running the Leonardo bootloader.

When i do:
pinMode([0-17], OUTPUT);
digitalWrite([0-17],[HIGH|LOW]);
everything works as intended.

When i try to address the Analog Pins (A0-A5) on Port F(PF0-PF7) as Digital pins
pinMode([18-23], OUTPUT);
digitalWrite([18-23], [HIGH|LOW]);
no dice

my question is, on the ATMEGA32U4, can the Analog Pins not be used as Digital Pins as they where on the ATMEGA328?

cyclegadget


  I don't know but, in the pin.H assignment list it does not show digital 18-23.

I would try
Code: [Select]
pinMode([A0-A5], OUTPUT);
digitalWrite([A0-A5], [HIGH|LOW])


Let us know if that works.
Good links: Eagle tutorial= http://www.youtube.com/playlist?list=PLDE1858BD83D19C70
General Arduion tutorials = http://tronixstuff.wordpress.com
http://www.gammon.com.au/forum/bbshowpost.php?bbtopic_id=123

CrossRoads

The position of the pins in the list is was determines their digital #.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

CrossRoads

This is from the Leonardo pins_arduino.h file,
C:\Arduino-1.0\hardware\arduino\variants\leonardo\pins_arduino.h

So the pins do seem to be defined.

const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
   PD, // D0 - PD2
   PD,   // D1 - PD3
   PD, // D2 - PD1
   PD,   // D3 - PD0
   PD,   // D4 - PD4
   PC, // D5 - PC6
   PD, // D6 - PD7
   PE, // D7 - PE6
   
   PB, // D8 - PB4
   PB,   // D9 - PB5
   PB, // D10 - PB6
   PB,   // D11 - PB7
   PD, // D12 - PD6
   PC, // D13 - PC7
   
   PB,   // D14 - MISO - PB3
   PB,   // D15 - SCK - PB1
   PB,   // D16 - MOSI - PB2
   PB,   // D17 - SS - PB0
   
   PF,   // D18 - A0 - PF7
   PF, // D19 - A1 - PF6
   PF, // D20 - A2 - PF5
   PF, // D21 - A3 - PF4
   PF, // D22 - A4 - PF1
   PF, // D23 - A5 - PF0
   
   PD, // D24 / D4 - A6 - PD4
   PD, // D25 / D6 - A7 - PD7
   PB, // D26 / D8 - A8 - PB4
   PB, // D27 / D9 - A9 - PB5
   PB, // D28 / D10 - A10 - PB6
   PD, // D29 / D12 - A11 - PD6
};
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

32teeth

#4
Dec 14, 2011, 12:38 pm Last Edit: Dec 14, 2011, 12:41 pm by 32teeth Reason: 1
Thanks CrossRoads.
I double checked my pin assignment in the code and it is accurate to my wiring and the pins_arduino.h

Although while double checking my design to the pins_arduino.h i noticed some duplication of port usage for A6 - A11 (see below)


const uint8_t PROGMEM digital_pin_to_port_PGM[30] = {
   PD, // D0 - PD2
   PD,   // D1 - PD3
   PD, // D2 - PD1
   PD,   // D3 - PD0
   PD,   // D4 - PD4
   PC, // D5 - PC6
   PD, // D6 - PD7
   PE, // D7 - PE6
   
   PB, // D8 - PB4
   PB,   // D9 - PB5
   PB, // D10 - PB6
   PB,   // D11 - PB7
   PD, // D12 - PD6
   PC, // D13 - PC7
   
   PB,   // D14 - MISO - PB3
   PB,   // D15 - SCK - PB1
   PB,   // D16 - MOSI - PB2
   PB,   // D17 - SS - PB0
   
   PF,   // D18 - A0 - PF7
   PF, // D19 - A1 - PF6
   PF, // D20 - A2 - PF5
   PF, // D21 - A3 - PF4
   PF, // D22 - A4 - PF1
   PF, // D23 - A5 - PF0
   
   PD, // D24 / D4 - A6 - PD4
   PD, // D25 / D6 - A7 - PD7
   PB, // D26 / D8 - A8 - PB4
   PB, // D27 / D9 - A9 - PB5
   PB, // D28 / D10 - A10 - PB6
   PD, // D29 / D12 - A11 - PD6
};


Does the Leonardo do some kind of multiplexing on those pins?
I did notice in the datasheet that these are ADC8 - ADC13, but as i understand you either would use them as A6-A11 or D4, D6, D8, D9, D10, D12 not both.

Also asked this in the Adafruit forum and got this answer about the lack of Digital support on Analog 0-5
"this is a bug in the leonardo support for Arduino - its still beta so we suspect it will be fixed when its out of beta "
"this is part of the IDE itself, no idea how to fix it."

CrossRoads

I suspect you as the coder will have to do the multiplexing if the pins are connected to the same header pin.
If using an Analog pin, then the digital pin will have to pinMode'd as an input so as not to interfere, as an example.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

dzfan

I know this is 3 years after the original post, but maybe this will help someone.  II had the same problem using my own ATmega32u4 on a breakout board where I could not use the analog pins as GPIO.  I discovered it was because the JTAGEN fuse bit was set.  When this bit is set, the Port F pins are all pulled high.  Disable the fuse and it should start working as expected.

32teeth

you can use the extra Analogs as inputs same as you would A6 and A7 on the pro

Code: [Select]

int state;
state = analogRead(A6) > 100 ? 0 : 1;

Go Up