Pin mapping for Mega644PA TQFP?

I want to program a Mega644PA TQFP based board with Arduino IDE. I'm using the well-known Sanguino hack, but the main problem is that pin mapping is specified to DIP not TQFP, so when I upload the sketch some pin doesn't work on the board..

What pin mapping should I use for Mega644PA TQFP?

The pinout would be exactly the same. PB0 on the DIP40 is still PB0 on the TQFP package. The Arduino specific pinout are defined by the physical port names on the ATmega

PB0 is pin1 on the DIP and pin40 on the QFP, so pin mapping must be different..

Pin mapping is defined in pins_arduino.h . It 'translates' ATmega's pins to Arduino's and it is based on AVR definitions in io...h files. ATmega644PA has self iom644pa.h in compare with ATmega644P. It has iom644p.h. So the difference must be. You have to edit pins_arduino.h yourself if it doesn't exists for PA type, and probably it doesn't.

Take a look at the datasheet for the ATmega644 On the DIP40 variant PB0 are located at physical pin 1. On the TQFP variant PB0 are located at physical pin 40. As far as I remember, pin 1 are defined as D0 on the Sanguino. That means that D0 is located at physical pin 40 for the TQFP variant. Repeat for all pins :)

hansibull: On the DIP40 variant PB0 are located at physical pin 1. On the TQFP variant PB0 are located at physical pin 40. As far as I remember, pin 1 are defined as D0 on the Sanguino. That means that D0 is located at physical pin 40 for the TQFP variant. Repeat for all pins :)

Maybe you're right, but strange that if I'm using, for example, "digitalWrite(28, HIGH)" then nothing happens on PA4, but "digitalWrite(A4, HIGH)" format works.. I don't understand.. the arduino pinout diagram for mega644 says that A4=28.. but why doesn't work it with number 28??

PB0 is pin1 on the DIP and pin40 on the QFP, so pin mapping must be different..

Pin mapping translates board-specific Arduino "pins" to AVR Ports and bits. Chip pin numbers are not normally involved, and you don't want them to be. It's up to the PCB designer to make sure that PA4 goes to something that is labeled "28" on the board. (You COULD change the mapping for each different board shape, but that's generally a bad idea since people would like to maintain the "pin0 = uart0 rx" functions as well. Which is why there are several different mappings for the 1284...)

westfw: It's up to the PCB designer to make sure that PA4 goes to something that is labeled "28" on the board.

It's ok, I know 28 is a logical arduino pin, but when I set a "digitalWrite(28, HIGH)" why arduino pin mapping doesn't redirect this reference to the related physical pin (PA4)?

I'm using the well-known Sanguino hack

Which core exactly IS that? The most likely reasons for your problems is that the variants/pins_arduino.* file doesn't match the pinout picture you are looking at... (My really ancient (0022) Sanguino install maps 28 to PA3, for example.)

westfw: The most likely reasons for your problems is that the variants/pins_arduino.* file doesn't match the pinout picture you are looking at...

You're right, thanks! I found it in the mentioned file: PA3=28, PA4=27.. and 27 works!

The used pinout picture is wrong!!..

(http://www.electrodragon.com/w/images/a/a4/Atmega644-pinout.png)

This "pin mapping" thing drives me crazy!..