Go Down

Topic: Pin mapping a ATmega2561 (Read 10426 times) previous topic - next topic

hansibull

#30
May 15, 2017, 10:12 pm Last Edit: May 15, 2017, 10:12 pm by hansibull
Quote
I tried, but it did not work....
Do I have to change anything else ?
Here is the code piece I've changed...
If this isn't about the ATmega2561, I suggest you start a new thread over at the programming questions forum.
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

alyeomans

Hi All

I have been working with what StanK posted (and Crossroads here and on an older thread) with good results on my 2561 custom board. I have tested:
Uart0
Uart1
Digital pins
ADC

I have had some trouble with the digital pins of port A appearing on port C and vice versa. Also A4 to A7 i.e port F, have a constant high voltage (5V) - this also appears on the ADC value and is like the internal pull up is enabled. The first 4 pins of port F i.e A0, A1, A2 and A3 work OK for ADC and digital.

Following is the setup I used:

board.txt
Code: [Select]
mega2561.name=Arduino Mega 2561
mega2561.upload.protocol=wiring
mega2561.upload.maximum_size=258048
mega2561.upload.maximum_data_size=8192
mega2561.upload.tool=avrdude
mega2561.upload.speed=115200

mega2561.bootloader.tool=avrdude
mega2561.bootloader.low_fuses=0x7F
mega2561.bootloader.high_fuses=0x99
mega2561.bootloader.extended_fuses=0xFF
mega2561.bootloader.path=stk500v2
mega2561.bootloader.file=stk500v2/stk500boot_v2_mega2560.hex
mega2561.bootloader.unlock_bits=0x3F
mega2561.bootloader.lock_bits=0x0F

mega2561.build.f_cpu=16000000L
mega2561.build.mcu=atmega2561
mega2561.build.core=arduino
mega2561.build.variant=mega2561
mega2561.build.board=AVR_MEGA2561


The pins_arduino.h attached. Note I have changed the ADC inputs as follows:
Code: [Select]
#define analogInputToDigitalPin(p)  ((p < 8) ? 46 + (7 - (p)) : -1)
//This seem to follow the table pin numbers correctly


Test record
D pinIC pindatasheet pin namepins_arduino.hcomment
24
51PA0 (AD0)PC0
25
50PA1 (AD1)PC1
26
49PA2 (AD2)PC2
27
48PA3 (AD3)PC3
28
47PA4 (AD4)PC4
29
46PA5 (AD5)PC5
30
45PA6 (AD6)PC6
31
44PA7 (AD7)PC7
32
35PC0 (A8)PA7
33
36PC1 (A9)PA6
34
37PC2 (A10)PA5
35
38PC3 (A11)PA4
36
39PC4 (A12)PA3
37
40PC5 (A13)PA2
38
41PC6 (A14)PA1
39
42PC7 (A15)PA0
A061PF0 (ADC0)A0
A160PF1 (ADC1)A1
A259PF2 (ADC2)A2
A358PF3 (ADC3)A3
A4XPF4 (ADC4/TCK)A45V on pin. digitalWrite LOW no affect
A5XPF5 (ADC5/TMS)A55V on pin. digitalWrite LOW no affect
A6XPF6 (ADC6/TDO)A65V on pin. digitalWrite LOW no affect
A7XPF7 (ADC7/TDI)A75V on pin. digitalWrite LOW no affect
A0-7 ADC input test
A061PF0 (ADC0)
A160PF1 (ADC1)
A259PF2 (ADC2)
A358PF3 (ADC3)
A4XPF4 (ADC4/TCK)unconnected has 5V on pin, ADC reads 1024
A5XPF5 (ADC5/TMS)unconnected has 5V on pin, ADC reads 1024
A6XPF6 (ADC6/TDO)unconnected has 5V on pin, ADC reads 1024
A7XPF7 (ADC7/TDI)unconnected has 5V on pin, ADC reads 1024


Cheers
Alex

hansibull

If you don't want to reinvent the wheel, listen up: we already have proper ATmega2561 support for Arduino IDE now. Feel free to do whatever you like, but it's already done. https://github.com/MCUdude/MegaCore


MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

alyeomans

Thanks Hansibul. Works great.

Had some trouble with serial data not clocking properly so checked the clock fuses in boards.txt and updated the fuses and works great.

For all external clock sources I updated to:
low_fuses=0xff
high_fuses=0x99

while on the fuse calculator page I checked the internal clock sources and updated internal fuses to:
low_fuses=0xe2
high_fuses=0xd6

Note I have only checked the 16Mhz.

Have run software serial and attachedInterupt for pin change interrupt at the same time. With above fuse change the board uploads bootloader and can use the serial port programming also (with capacitor between DTR and reset).

Cheers
Al

hansibull

You don't want those fuse settings for the external clock.

For the low fuse setting, you want tu use the full swing oscillator option. It drives the external oscillator with a little more power, resulting in a more stable and noise immune clock. Use 0xF7 for the low fuse.

For the high fuse; you probably don't need JTAG enabled. Boot flash section size does not need to be more than 512 words to fit Optiboot in there, and you _do_ want to enable the boot reset vector. Do you want the EEPROM to be erased every time you upload something new? Probably not. Use 0xD6 for the high fuse.
MightyCore -  ATmega1284, mega644, mega324, mega164, mega32, mega16, mega8535
Github.com/MCUdude/MightyCore

MiniCore - ATmega8, mega48, mega88, mega168, mega328
Github.com/MCUdude/MiniCore

Go Up