Arduino For Atmega32

Satyavijay Jagannath Durgule. He is sub divisional engineer, IT Project Circle, BSNL, Pune. His interests include developing MCU based projects

51115
 

Software

Arduino software version 1.0.5 has some directories. For making it suitable for ATmega32 we have to modify/add some directories/files to it. The directory structure is given in Fig. 4.

Directory tree of Arduino 1.0.5 IDE
Fig. 4: Directory tree of Arduino 1.0.5 IDE

Check which directory/file needs to be modified/added. Details of modifications, that is, where/which lines are to be changed/added are given here for reference.

But first make a copy of Arduino version 1.0.5 software and make required changes in it. If you do not have 1.0.5 version, go to www.arduino.cc and click Download Link. From Previous Release box click Arduino 1.0.x and then click Windows option for version 1.0.5. Save this file and expand it.

Follow the instructions given below for making modifications

Directory structure of Arduino: Go through it and verify it with Arduino version 1.0.5 so that you get overall idea of the changes required in the files and folders of Arduino. For editing relevant files (like boards.txt, pins_arduino.h and so on), use Programmer’s Notepad and use/toggle line number display so that you can view line numbers in the opened file.

Modify the files in this directory structure as per the steps below.

Go to Hardware\Arduino directory: Open the text file named boards.txt and add the following lines at the end of this file:

atmega32.name=Arduino ATmega32
atmega32.upload.protocol=arduino
atmega32.upload.maximum_size=30720
atmega32.upload.speed=19200
atmega32.bootloader.low_fuses=0xFF
atmega32.bootloader.high_fuses=0xCA
atmega32.bootloader.path=atmega32
atmega32.bootloader.file=ATmega32BOOT.hex
atmega32.bootloader.unlock_bits=0x3F
atmega32.bootloader.lock_bits=0xCF
atmega32.build.mcu=atmega32
atmega32.build.f_cpu=16000000L
atmega32.build.core=arduino
atmega32.build.variant=mega32

Define the hardware of ATmega32: For this, search for directory location hardware\arduino\varients and create a new directory named mega32. Inside this new directory, add a new file named pins_arduino.h by copying it from Standard Directory.

This file includes digital pins, analogue pins, timer pins, pwm pins, ports and port bits. The numbers of digital pins, analogue pins and pwm pins are changed as below:

#define NUM_DIGITAL_PINS 32
#define NUM_ANALOG_INPUTS 8
#define analogInputToDigitalPin(p) ((p
< 8) ? (p) + 24 : -1)
#define digitalPinHasPWM(p) ((p) == 3 ||
(p) == 12 || (p) == 13 || (p) == 15)

Pin change interrupt (PCINT) is removed as it is not applicable for ATmega32. Constants are changed, that is, change for SS, MOSI, MISO, SCK, SDA and SCL as per ATmega32 hardware pin out.

static const uint8_t SS = 4;
static const uint8_t MOSI = 5;
static const uint8_t MISO = 6;
static const uint8_t SCK = 7;

static const uint8_t SDA = 17;
static const uint8_t SCL = 16;

Constants for analogue pins are defined as follows:

static const uint8_t A0 = 31;
static const uint8_t A1 = 30;
static const uint8_t A2 = 29;
static const uint8_t A3 = 28;
static const uint8_t A4 = 27;
static const uint8_t A5 = 26;
static const uint8_t A6 = 25;
static const uint8_t A7 = 24;[/stextbox]

Remaining modifications can be made as given below:

const uint16_t PROGMEM port_to_mode
_PGM[] = {
NOT_A_PORT,
(uint16_t) &DDRA,
(uint16_t) &DDRB,
(uint16_t) &DDRC,
(uint16_t) &DDRD,
};

const uint16_t PROGMEM port_to_
output_PGM[] = {
NOT_A_PORT,
(uint16_t) &PORTA,
(uint16_t) &PORTB,
(uint16_t) &PORTC,
(uint16_t) &PORTD,
};

const uint16_t PROGMEM port_to_input
_PGM[] = {
NOT_A_PORT,
(uint16_t) &PINA,
(uint16_t) &PINB,
(uint16_t) &PINC,
(uint16_t) &PIND,
};

const uint8_t PROGMEM digital_pin_to_
port_PGM[] = {
PB, /* B *0* */
PB,
PB,
PB,
PB,
PB,
PB,
PB,
PD, /* D *8* */
PD,
PD,
PD,
PD,
PD,
PD,
PD,
PC, /* C *16* */
PC,
PC,
PC,
PC,
PC,
PC,
PC,
PA, /* A *24* */
PA,
PA,
PA,
PA,
PA,
PA,
PA,
};
const uint8_t PROGMEM digital_pin_to_
bit_mask_PGM[] = {
_BV(0), /* digital pin 0, port
B */
_BV(1), //digital pin 1
_BV(2), //digital pin 2
_BV(3), //digital pin 3
_BV(4), //digital pin 4
_BV(5), //digital pin 5
_BV(6), //digital pin 6
_BV(7), //digital pin 7
_BV(0), /* digital pin 8, port
D */
_BV(1), //digital pin 9
_BV(2), //digital pin 10
_BV(3), //digital pin 11
_BV(4), //digital pin 12
_BV(5), //digital pin 13
_BV(6), //digital pin 14
_BV(7), //digital pin 15
_BV(0), /*digital pin 16, port
C */
_BV(1), //digital pin 17
_BV(2), //digital pin 18
_BV(3), //digital pin 19
_BV(4), //digital pin 20
_BV(5), //digital pin 21
_BV(6), //digital pin 22
_BV(7), //digital pin 23
_BV(7), /* digital pin 24,
port A, note descending order */
_BV(6), //digital pin 25
_BV(5), //digital pin 26
_BV(4), //digital pin 27
_BV(3), //digital pin 28
_BV(2), //digital pin 29
_BV(1), //digital pin 30
_BV(0), //digital pin 31
};

const uint8_t PROGMEM digital_pin_to_
timer_PGM[] = {
NOT_ON_TIMER, /* 0 – port B */
NOT_ON_TIMER, /*1*/
NOT_ON_TIMER, /*2*/
TIMER0 , /*3 8 bit*/
NOT_ON_TIMER, /*4*/
NOT_ON_TIMER, /*5*/
NOT_ON_TIMER, /*6*/
NOT_ON_TIMER, /*7*/
NOT_ON_TIMER, /* 8 – port D */
NOT_ON_TIMER, /*9*/
NOT_ON_TIMER, /*10*/
NOT_ON_TIMER, /*11*/
TIMER1B, /*12*/
TIMER1A, /*13*/
NOT_ON_TIMER, /*14*/
TIMER2, /*15* 8 bit/
NOT_ON_TIMER, /* 16 – port C */
NOT_ON_TIMER, /*17*/
NOT_ON_TIMER, /*18*/
NOT_ON_TIMER, /*19*/
NOT_ON_TIMER, /*20*/
NOT_ON_TIMER, /*21*/
NOT_ON_TIMER, /*22*/
NOT_ON_TIMER, /*23*/
NOT_ON_TIMER, /* 24 – port A */
NOT_ON_TIMER, /*25*/
NOT_ON_TIMER, /*26*/
NOT_ON_TIMER, /*27*/
NOT_ON_TIMER, /*28*/
NOT_ON_TIMER, /*29*/
NOT_ON_TIMER, /*30*/
NOT_ON_TIMER, /*31*/
};

8 COMMENTS

  1. Sir the article is excellent, however just like the prototype board we would like to use an FTDI chip to program it directly using a USB, please contact.

SHARE YOUR THOUGHTS & COMMENTS

Please enter your comment!
Please enter your name here