Help using SoftwareSerial on ATMega2560 pin#69

Hi everyone,

For a personal project, I've built my own PCB with Atmega2560 in it. The thing is I had to use pin number 68 and 69 as software serial port, mostly because the SoftwareSerial page says :
"Note:
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69"

Normal ArduinoMega2560 doesn't use those pins (see ArduinoPInMapping : http://www.arduino.cc/en/Hacking/PinMapping2560 ) so I created my own target following this tutorial (atmega - Arduino use all Ports ATMega2560 - Stack Overflow). I basically just added the pin Arduino doesn't use into the pins_arduino.h header file. It works great if I just wanted to use this pin with DigitalWrite. But I want to use it as a SoftwareSerial and this is not working. I checked into the pins_arduino.h: header file and for me these pins seems to have been declared as PCINT...

Can someone help on this ?

Thanks a lot.

ludovic_pendaries:
Hi everyone,

For a personal project, I've built my own PCB with Atmega2560 in it. The thing is I had to use pin number 68 and 69 as software serial port, mostly because the SoftwareSerial page says :
"Note:
Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 50, 51, 52, 53, 62, 63, 64, 65, 66, 67, 68, 69"

Normal ArduinoMega2560 doesn't use those pins (see ArduinoPInMapping : http://www.arduino.cc/en/Hacking/PinMapping2560 ) so I created my own target following this tutorial (atmega - Arduino use all Ports ATMega2560 - Stack Overflow). I basically just added the pin Arduino doesn't use into the pins_arduino.h header file. It works great if I just wanted to use this pin with DigitalWrite. But I want to use it as a SoftwareSerial and this is not working. I checked into the pins_arduino.h: header file and for me these pins seems to have been declared as PCINT...

Can someone help on this ?
Thanks a lot.

ludovic_pendaries,
You need to upload your pins_arduino.h file. That is where the problem is. You need to update the:

#define digitalPinToPCICR(p)
#define digitalPinToPCICRbit(p)
#define digitalPinToPCMSK(p)
#define digitalPinToPCMSKbit(p)

....

etc

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.

Hi chucktodd,

Thanks for your reply !
I had some feelings about this update but I have to confess that I am a bit lost in the declaration of the PCIR. As far as I can see the declaration seems correct to me. Here is the relevant part of my pins_arduino.h :

#define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 13)) || \
                                  (((p) >= 50) && ((p) <= 53)) || \
                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )

#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
                                0 ) )

#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) ? (&PCMSK0) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )

#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
                                ( ((p) == 50) ? 3 : \
                                ( ((p) == 51) ? 2 : \
                                ( ((p) == 52) ? 1 : \
                                ( ((p) == 53) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
                                0 ) ) ) ) ) )

I think the pins from 62 to 69 are declared as PCIR, or I don't understand well. What do you think ?

[EDIT]
In case it could help, the tx is working perfectly, so the problem must really be on this PCIR declaration..

Anyone ?

After considering it for a while, I tried to declare the pin 65 to 68 (PJ2 to PJ5) as PCICR :

#define digitalPinToPCICR(p)    ( (((p) >= 10) && ((p) <= 13)) || \
                                  (((p) >= 50) && ((p) <= 53)) || \
				  (((p) >= 77) && ((p) <= 80)) || \
                                  (((p) >= 62) && ((p) <= 69)) ? (&PCICR) : ((uint8_t *)0) )

#define digitalPinToPCICRbit(p) ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) || (((p) >= 77) && ((p) <= 80)) ? 0 : \
                                ( (((p) >= 62) && ((p) <= 69)) ? 2 : \
                                0 ) )

#define digitalPinToPCMSK(p)    ( (((p) >= 10) && ((p) <= 13)) || (((p) >= 50) && ((p) <= 53)) || (((p) >= 77) && ((p) <= 80)) ? (&PCMSK0) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? (&PCMSK2) : \
                                ((uint8_t *)0) ) )

#define digitalPinToPCMSKbit(p) ( (((p) >= 10) && ((p) <= 13)) ? ((p) - 6) : \
				( ((p) == 50) ? 3 : \
                                ( ((p) == 51) ? 2 : \
                                ( ((p) == 52) ? 1 : \
                                ( ((p) == 53) ? 0 : \
				( (((p) >= 77) && ((p) <= 80)) ? ((p) - 75) : \
                                ( (((p) >= 62) && ((p) <= 69)) ? ((p) - 62) : \
                                0 ) ) ) ) ) ))

And it still not work... I think I'm getting close. Anyone can help ?

How many USART ports do you need? The Mega2560 has 4 of them so unless you use them all or specifically need there pins I would stick to the hardware USART and use the extra pins for simple I/O instead.