What You Get - maierma/avr-netino GitHub Wiki

What you get

This side records the differences to the arduino boards. Mostly they are caused by the different ATmega and, of course, the boards have other IO features.

I changed the pin numbers to a more friendly way for the AVR-Net-IO. They are also different to the sanguino, which uses the same ATmega.

##Pins

Pin Nr Port PWM Names
0 C0 - pins_port_C0, pins_SCL, pins_J3_2
1 C1 - pins_port_C1, pins_SDA, pins_J3_3
2 C2 - pins_port_C2, pins_TCK, pins_J3_4
3 C3 - pins_port_C3, pins_TMS, pins_J3_5
4 C4 - pins_port_C4, pins_TDO, pins_J3_6
5 C5 - pins_port_C5, pins_TDI, pins_J3_7
6 C6 - pins_port_C6, pins_TOSC1, pins_J3_8
7 C7 - pins_port_C7, pins_TOSC2, pins_J3_9
8 A0 - pins_port_A0, pins_ADC0, pins_A0, A0
9 A1 - pins_port_A1, pins_ADC1, pins_A1, A1
10 A2 - pins_port_A2, pins_ADC2, pins_A2, A2
11 A3 - pins_port_A3, pins_ADC3, pins_A3, A3
12 A4 - pins_port_A4, pins_ADC4, pins_ADC_1, A4
13 A5 - pins_port_A5, pins_ADC5, pins_ADC_2, A5
14 A6 - pins_port_A6, pins_ADC6, pins_ADC_3, A6
15 A7 - pins_port_A7, pins_ADC7, pins_ADC_4, A7
16 D0 - pins_port_D0, pins_RXD, pins_RS232_RxD
17 D1 - pins_port_D1, pins_TXD, pins_RS232_TxD
18 D2 - pins_port_D2, pins_INT0, pins_LED_1
19 D3 - pins_port_D3, pins_INT1, pins_RFM12_IRQ
20 D4 + pins_port_D4, pins_OC1B, pins_LED_2
21 D5 + pins_port_D5, pins_OC1A, pins_RFM12_CS
22 D6 + pins_port_D6, pins_OC2B, pins_LED_3
23 D7 + pins_port_D7, pins_OC2A, pins_SDcard_INS
24 B0 - pins_port_B0, pins_T0, pins_IR_Rx
25 B1 - pins_port_B1, pins_T1, pins_JUMP_PROG
26 B2 - pins_port_B2, pins_INT2, pins_ENC28J60_IRQ
27 B3 + pins_port_B3, pins_OC0, pins_SDcard_CS
28 B4 - pins_port_B4, pins_SS, pins_ENC28J60_CS
29 B5 - pins_port_B5, pins_MOSI, pins_SPI_MOSI
30 B6 - pins_port_B6, pins_MISO, pins_SPI_MISO
31 B7 - pins_port_B7, pins_SCK, pins_SPI_SCK

##Explanation

  • Pins 0..11 are on Sub-D25 (J3)
  • Pins 12..15 are the screw connectors labelled with ADC 1 to ADC 4
  • Pins 18..24,26 are on EXT connector
  • to make programming (and porting) easier, I've defined constants for all pins reflecting their usage (including the AddOn board).
  • constants beginning with pins_ are declared in pins_arduino.h, which is included by Arduino.h. So you don't have to include this file if used.

##Libraries The modified libraries are change in a compatible way, that means they will work with standard arduino boards as well as with the AVR-Net-IO board.

##Details This section describes the technical aspects of my mods.

##Constants There is only two pre-processor constant:

#define AVR_NET_IO      0x20131003      /* Date 2013-10-03 */

which indicates that we compile for AVR-Net-IO board, and

#define AVR_Netino      0x20131003      /* Date 2012-10-03 */

to indicate that we us the avrnetio core files. They are used to activate my extensions in the modified libraries. If defined, pin numbers are read from the constants in the table above. The value of the AVR_Netino constant is the date of the avrnetio core files.

I've defined some more constants to describe the AVR-Net-IO hardware:

Constant Value Comment
LED_BUILTIN pins_LED_1
I2C_LCD_ADR 0x20 PCF8574=0x20 PCF8574A=0x38 (7Bit adr)
I2C_LCD_NBL 0 4Bit-Bus at P0-P3
I2C_LCD_RS 0x10 P4 D/I
I2C_LCD_RW 0x20 P5 R/W
I2C_LCD_E 0x40 P6 Enable
I2C_LCD_BL 0x80 P7 Back Light
ENC28J60_INR 2 Int Nr of ENC28J60
RFM12_INR 1 Int Nr of RFM12

The constants in the upper table beginning with pins_ are declared in pins_arduino.h via board.def file. They are all enum members, which are better constants than static const int

##The Xmacro Trick The pin definitions and board specific constants are all concentrated in the board.def file. For every pin there is a line like

pinDef( A, 4 , NOT_ON_TIMER,ADC4,ADC_1,4)

pinDef is a Xmacro, that means it will be redefined for different usage. The argument are:

  1. the port as single upper letter, so it can be concatenated to PIN, PORT andDDRregister names.
  2. the bit number in the port
  3. the timer used for pwm or NOT_ON_TIMER if this pin has no pwm capabilities
  4. the additional pin function from the ATmega datasheet
  5. the pin usage at the board, that is a pin name at a connector, or a label of a pin, or a specific funktion like RS232_RxD or a chip select.
  6. the pin-change-interrupt number
  7. ..., the macro definition should end with ..., so it can be extended in the future.

Let's look at an example:

For arduino we need three arrays to define the pin functions.

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {PD,PD,PD,...PC,...};

2. ```c 
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {_BV(0),_BV(1),_BV(2),...};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = { NOT_ON_TIMER, NOT_ON_TIMER,...};


These are extracted from board.def with the Xmacro pinDef by these defines:

1. ```c
#define pinDef(p,B,T,...)	(P##p),

#define pinDef(P,B,T,...) _BV(B),

3. ```c
#define pinDef(P,B,T,...)	(T),

In pins_arduino.h the enum with the pins_ constants is filled with

#define pinDef(P,B,T,F,...) pins_##F,

The prefix pins_ is needed, because some of the pin names like INT0 are defined as macros in the AVR header files, so I couldn't use them as enum members.

##The big advantage Putting all board specific things in one file makes it very easy to port the arduino IDE to other boards. For this to work, the files in the core must support all ATmega in use. With arduino-0022 a lot of the '#ifdef AVR_ATmegaXX' are replaced with #ifdef Register

I continued this strategy to support the 3. ext. Interrupt of the ATmega32/644(p). Second, it is very easy to change pin numbers, simply by changing the order of the pinDef lines in board.def. And, last but not least, I introduced a lot of constants with pins for special functions, which makes programming in a portable manner more clear.