Go Down

Topic: Arduino variant, how do I add more pins (Read 2 times) previous topic - next topic

bluscape

I've made a custom board based on the Arduino Mega 2560. I've used pins on my board that is not used on the Arduino board (for example all the pins on PORT J)

How do I add the PORT J pins to the Arduino code?

I looked at the pins_arduino.h file but is not 100% sure if this is the correct place. I'm not sure what to do.

Any help will be appreciated.

Thank you


Tom Carpenter

#1
Jul 16, 2012, 10:03 pm Last Edit: Jul 16, 2012, 10:08 pm by TCWORLD Reason: 1
Code: [Select]
#ifdef ARDUINO_MAIN

const uint16_t PROGMEM port_to_mode_PGM[] = {
NOT_A_PORT,
(uint16_t) &DDRA,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
(uint16_t) &DDRE,
(uint16_t) &DDRF,
(uint16_t) &DDRG,
(uint16_t) &DDRH,
NOT_A_PORT;
(uint16_t) &DDRJ, // ddr J is already defined
(uint16_t) &DDRK,
(uint16_t) &DDRL,
};

const uint16_t PROGMEM port_to_output_PGM[] = {
NOT_A_PORT,
(uint16_t) &PORTA,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
(uint16_t) &PORTE,
(uint16_t) &PORTF,
(uint16_t) &PORTG,
(uint16_t) &PORTH,
NOT_A_PORT,
(uint16_t) &PORTJ, // port J is already defined
(uint16_t) &PORTK,
(uint16_t) &PORTL,
};

const uint16_t PROGMEM port_to_input_PGM[] = {
NOT_A_PIN,
(uint16_t) &PINA,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
(uint16_t) &PINE,
(uint16_t) &PINF,
(uint16_t) &PING,
(uint16_t) &PINH,
NOT_A_PIN,
(uint16_t) &PINJ, // pin J is already defined
(uint16_t) &PINK,
(uint16_t) &PINL,
};


Say you wanted J2 to J7 to be digital 70 to digital 75, you would change the following:
Code: [Select]



#define NUM_DIGITAL_PINS            76

...
...

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
// PORTLIST
// -------------------------------------------
...
PK , // PK 6 ** 68 ** A14
PK , // PK 7 ** 69 ** A15
PJ , // PJ 2 ** 70 ** D70
PJ , // PJ 3 ** 71 ** D71
PJ , // PJ 4 ** 72 ** D72
PJ , // PJ 5 ** 73 ** D73
PJ , // PJ 6 ** 74 ** D74
PJ , // PJ 7 ** 75 ** D75
};

const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
// PIN IN PORT
// -------------------------------------------
...
_BV( 5 ) , // PK 5 ** 67 ** A13
_BV( 6 ) , // PK 6 ** 68 ** A14
_BV( 7 ) , // PK 7 ** 69 ** A15
_BV( 2 ) , // PJ 2 ** 70 ** D70
_BV( 3 ) , // PJ 3 ** 71 ** D71
_BV( 4 ) , // PJ 4 ** 72 ** D72
_BV( 5 ) , // PJ 5 ** 73 ** D73
_BV( 6 ) , // PJ 6 ** 74 ** D74
_BV( 7 ) , // PJ 7 ** 75 ** D75
};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
// TIMERS
// -------------------------------------------
...
NOT_ON_TIMER , // PK 4 ** 66 ** A12
NOT_ON_TIMER , // PK 5 ** 67 ** A13
NOT_ON_TIMER , // PK 6 ** 68 ** A14
NOT_ON_TIMER , // PK 7 ** 69 ** A15
NOT_ON_TIMER , // PJ 2 ** 70 ** D70
NOT_ON_TIMER , // PJ 3 ** 71 ** D71
NOT_ON_TIMER , // PJ 4 ** 72 ** D72
NOT_ON_TIMER , // PJ 5 ** 73 ** D73
NOT_ON_TIMER , // PJ 6 ** 74 ** D74
NOT_ON_TIMER , // PJ 7 ** 75 ** D75
};
~Tom~

CrossRoads

Take a look at the overallstructure, and create yourself a new Variant.
Copy the 2560 files there.
In pins_arduino.h, there are several arrays where the pins are defined.
One array lists the ports used, these will be the pins, listed in what ends up as D0 to Dxx.
Next is the pins within the ports.
Next is whether the pins have timers associated with them.

There might be more. I haven't dug into the 1.0 format in a while, and then maniacbug was able to get the files finished up for a 1284 chip.

You'll probably need a new entry for boards.txt also to call out your new variant to map in your new pins_arduino.h. And possiby a new entry on avrdude.conf, altho maybe not if boards.txt calls out the same chip type.

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.


bluscape

1.) I've added the new pins in a custom header file "..\hardware\arduino\variants\custom\pins_arduino.h"
2.) I copied the board settings for the Arduino Mega 2560 and created a custom board entry
3.) I've updated the pin numbers in my sketch

##############################################################

custom2560.name=Custom 2560

custom2560.upload.protocol=stk500v2
custom2560.upload.maximum_size=258048
custom2560.upload.speed=115200

custom2560.bootloader.low_fuses=0xFF
custom2560.bootloader.high_fuses=0xD8
custom2560.bootloader.extended_fuses=0xFD
custom2560.bootloader.path=stk500v2
custom2560.bootloader.file=stk500boot_v2_mega2560.hex
custom2560.bootloader.unlock_bits=0x3F
custom2560.bootloader.lock_bits=0x0F

custom2560.build.mcu=atmega2560
custom2560.build.f_cpu=16000000L
custom2560.build.core=arduino
custom2560.build.variant=custom

But when I compile my sketch I get the following errors for each new pin:

error: 'DIO76_DDR' was not declared in this scope
error: 'DIO76_PIN' was not declared in this scope
error: 'DIO76_WPORT' was not declared in this scope

etc.

So somewhere there is a mapping from the arduino pins to the actual avr pins but I dont know where.

Any ideas?

Go Up