why dont certain AVR port names work in Arduino

I have been trying to learn how to acess the input and output pins of the arduino WITHOUT using analogRead and analogWrite, etc.

a lot of AVR tutorials recommend calling pins like this:

DDRD &= ~(1<<PD2); //Configure PORTD pin 2 as an input
PORTD |= (1<<PD2); //Activate pull-ups in PORTD pin 2
DDRB |= (1<<PB5);

(from http://hekilledmywire.wordpress.com/2011/02/23/direct-port-manipulation-using-the-digital-ports-tutorial-part-3/#more-37)

However, I can’t ever get pin names like PD2 or PB5 to work. any idea why?

thanks!

I've never used pin manipulation :( but check out this site:

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

This should be helpful, as its from the experts themselves. :)

baum

try including avr/io.h

rather than PC0, PC1, etc do PINC0, PINC1, etc

both syntaxes work with the ATMega168, but the 328 does not support the PCx, just PINCx (changing the letter to be what register you wish, i just referred to register C).

This is a known working synatx below:

Serial.println (PINC & _BV(PINC0)); Serial.println (PINC & _BV(PINC1)); Serial.println (PINC & _BV(PINC2)); Serial.println (PINC & _BV(PINC3)); Serial.println (PINC & _BV(PINC4)); Serial.println (PINC & _BV(PINC5)); Serial.println (PINC & _BV(PINC6)); Serial.println(); Serial.println("end"); Serial.println(); delay(1000);

I'm not positive, but i believe PORTCx works as well as PINCx

tempmj: rather than PC0, PC1, etc do PINC0, PINC1, etc

both syntaxes work with the ATMega168, but the 328 does not support the PCx, just PINCx (changing the letter to be what register you wish, i just referred to register C).

Wow I didn't know that, I think I'll make a patch to my own installation to fix this.

the 328 does not support the PCx

this was apparently an avrgcc decision rather than an arduino decision, BTW...

westfw:

the 328 does not support the PCx

this was apparently an avrgcc decision rather than an arduino decision, BTW...

I didn't expect Arduino to have any leverage at all on avr-gcc development, and was this really a "decision"? It feels like one of those things that got left out accidentally...

was this really a "decision"? It feels like one of those things that got left out accidentally...

It does appear to be fixed in newer gcc distributions.

But it was a pretty stupid for a mistake; the 328p is nearly identical to 168, but the relevant include file was defined entirely differently. It "smells" of someone making a decision that was later over-ridden. (Or it could be Atmel's fault. On some platforms, these include files are derived automatically from distributer-provided asm files or documentation, and Atmel could have changed their formatting and/or strategy.)

is there a way i can make a new include file to allow for the old syntax? a lot of programs i bump into seem to use it and it is a pain to always have to change it by hand

thanks for any help!

install a new version of .../hardware/tools/avr/avr/include/avr/portpins.h (from http://svn.savannah.nongnu.org/viewvc/trunk/avr-libc/include/avr/portpins.h?root=avr-libc&view=log )

(note the most recent bugfix.)