Go Down

Topic: Burning Arduino to ATmega32A (Read 35701 times) previous topic - next topic

nightcrawler218

#15
Dec 28, 2013, 12:36 pm Last Edit: Dec 28, 2013, 12:52 pm by nightcrawler218 Reason: 1
Woke up & get started again to get things fixed. Found a number of threads on this topic.
Found temporary solution. https://github.com/eaconner/ATmega32-Arduino
Now my 32A is accepting the blink sketch. It is working BUT the pinmapping is...
Code: [Select]

// ATMEL ATMEGA32/32A
//
//                       +---\/---+
//           (D 0) PB0  1|        |40  PA0 (AI 0 / D24)
//           (D 1) PB1  2|        |39  PA1 (AI 1 / D25)
//      INT2 (D 2) PB2  3|        |38  PA2 (AI 2 / D26)
//       PWM (D 3) PB3  4|        |37  PA3 (AI 3 / D27)
//       /SS (D 4) PB4  5|        |36  PA4 (AI 4 / D28)
//      MOSI (D 5) PB5  6|        |35  PA5 (AI 5 / D29)
//     /MISO (D 6) PB6  7|        |34  PA6 (AI 6 / D30)
//      /SCK (D 7) PB7  8|        |33  PA7 (AI 7 / D31)
//                 RST  9|        |32  AREF
//                 VCC 10|        |31  GND
//                 GND 11|        |30  AVCC
//               XTAL2 12|        |29  PC7 (D 23)
//               XTAL1 13|        |28  PC6 (D 22)
//      RX0 (D 8)  PD0 14|        |27  PC5 (D 21) TDI
//      TX0 (D 9)  PD1 15|        |26  PC4 (D 20) TDO
// RX1/INT0 (D 10) PD2 16|        |25  PC3 (D 19) TMS
// TX1/INT1 (D 11) PD3 17|        |24  PC2 (D 18) TCK
//      PWM (D 12) PD4 18|        |23  PC1 (D 17) SDA
//      PWM (D 13) PD5 19|        |22  PC0 (D 16) SCL
//          (D 14) PD6 20|        |21  PD7 (D 15) PWM
//                       +--------+
//


Then followed this thread http://forum.arduino.cc/index.php?topic=174311.15 & found the 1284 core files including Bobuino pin mapping file. https://github.com/maniacbug/mighty-1284p
Code: [Select]

// ATMEL ATMEGA1284P on Bobuino
//
//                       +---\/---+
//           (D 4) PB0 1 |        | 40 PA0 (D 21) AI 7
//           (D 5) PB1 2 |        | 39 PA1 (D 20) AI 6
//      INT2 (D 6) PB2 3 |        | 38 PA2 (D 19) AI 5
//       PWM (D 7) PB3 4 |        | 37 PA3 (D 18) AI 4
//   PWM/SS (D 10) PB4 5 |        | 36 PA4 (D 17) AI 3
//     MOSI (D 11) PB5 6 |        | 35 PA5 (D 16) AI 2
// PWM/MISO (D 12) PB6 7 |        | 34 PA6 (D 15) AI 1
//  PWM/SCK (D 13) PB7 8 |        | 33 PA7 (D 14) AI 0
//                 RST 9 |        | 32 AREF
//                VCC 10 |        | 31 GND
//                GND 11 |        | 30 AVCC
//              XTAL2 12 |        | 29 PC7 (D 29)
//              XTAL1 13 |        | 28 PC6 (D 28)
//      RX0 (D 0) PD0 14 |        | 27 PC5 (D 27) TDI
//      TX0 (D 1) PD1 15 |        | 26 PC4 (D 26) TDO
// INT0 RX1 (D 2) PD2 16 |        | 25 PC3 (D 25) TMS
// INT1 TX1 (D 3) PD3 17 |        | 24 PC2 (D 24) TCK
//     PWM (D 30) PD4 18 |        | 23 PC1 (D 23) SDA
//      PWM (D 8) PD5 19 |        | 22 PC0 (D 22) SCL
//      PWM (D 9) PD6 20 |        | 21 PD7 (D 31) PWM
//                       +--------+
//


Can't get the bobuino pin_arduino.h work with my mega32A.

Procedure Followed for mega32 pin_arduino.h:
Put the pins_arduino.h file from the downloaded directory to arduino "core" folder.
Select board > ATmega32
Programmer > USBasp
File > Upload using programmer

Yes, It works Without needing any additional core files. BUT to make life easier I found the bobuino pin mapping is the best way to use a 40 pin AVR because it already optimised the port pin numbering to a standard uno interface, like the spi, serial ports, ADC ports etc.
I am unable to port the pin configuration in pins_arduino.h, from mega32 to bobuino pin mapping. May I get any help at that stage. The mega32 & bobuino pin mapping .h files are included here.
Your guidance is highly anticipated.
"Imagination is more important than knowledge."<br />-Einstein

CrossRoads

Have you put the pins_arduino.h in the right place?
You see how both the /arduino and /mighty1284 have a bootloaders.txt, and each has a /variants and a /bootloader folder? In each /variants folder there is a board type folder with a name that matches a name from a boards.txt section, and the /bootloader folder has a folder for each board type as well with the bootloader for that card.
Set yours up the same way, under the arduino path if that is what you are using, or under the mighty1284 path.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nightcrawler218

Thanks CrossRoads, I did mistake & put the "variant" folder contents into the "core" folder. I'm going to delete the existing extracted 1.0.5 IDE & unzip it again & start from the beginning.
"Imagination is more important than knowledge."<br />-Einstein

CrossRoads

Yes, can be a little tricky. I had it worked out under -0023, maniacbug got it worked out for IDE 1.0 & later.
This is what I have for Bobuino now, fixes PCINT mapping, might need similar for Atmega32 if PCINT & Analog are same pins as 1284.

These other 2 made changes to fix INPUT_PULLUP, definition was missing.
If you are Arduino/core, check them.
If you are in mighty1284 core, replace them.

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nightcrawler218

#19
Dec 28, 2013, 08:01 pm Last Edit: Dec 28, 2013, 10:31 pm by nightcrawler218 Reason: 1
Hello, I have followed two methods

First Method
I have put the mighty folder under "C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p" location.
Added 2 entries to boards.txt ( to the boards.txt preloaded with arduino, I did nothing with the mighty's board.txt)  [ http://forum.arduino.cc/index.php?topic=174311.15 (First post) ]
copied the mentioned optiboot .HEX files to C:\Users\Roy\Desktop\arduino-1.0.5\hardware\arduino\bootloaders\optiboot
Code: [Select]

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

atmega32_at16e.name=ATmega32/32A (16MHz, external)

atmega32_at16e.upload.protocol=arduino
atmega32_at16e.upload.maximum_size=32256
atmega32_at16e.upload.speed=115200

atmega32_at16e.bootloader.low_fuses=0xFF
atmega32_at16e.bootloader.high_fuses=0xD6
#make atmega32 AVR_FREQ=16000000L BAUD_RATE=115200 UART=0 LED=B7 LED_START_FLASHES=3
atmega32_at16e.bootloader.path=optiboot
atmega32_at16e.bootloader.file=optiboot_atmega32_16MHz.hex
atmega32_at16e.bootloader.unlock_bits=0x3F
atmega32_at16e.bootloader.lock_bits=0x0F

atmega32_at16e.build.mcu=atmega32
atmega32_at16e.build.f_cpu=16000000L
atmega32_at16e.build.core=mighty-1284p:standard
atmega32_at16e.build.variant=bobuino // I put the Bobuino folder to "C:\Users\Roy\Desktop\arduino-1.0.5\hardware\arduino\variants"

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

atmega32_at8i.name=ATmega32/32A (8MHz, internal)

atmega32_at8i.upload.protocol=arduino
atmega32_at8i.upload.maximum_size=32256
atmega32_at8i.upload.speed=57600

atmega32_at8i.bootloader.low_fuses=0xE4
atmega32_at8i.bootloader.high_fuses=0xD6
#make atmega32 AVR_FREQ=8000000L BAUD_RATE=115200 UART=0 LED=B7 LED_START_FLASHES=3
atmega32_at8i.bootloader.path=optiboot
atmega32_at8i.bootloader.file=optiboot_atmega32_8MHz.hex
atmega32_at8i.bootloader.unlock_bits=0x3F
atmega32_at8i.bootloader.lock_bits=0x0F

atmega32_at8i.build.mcu=atmega32
atmega32_at8i.build.f_cpu=8000000L
atmega32_at8i.build.core=mighty-1284p:standard
atmega32_at8i.build.variant=mega32


selected the "ATmega32/32A (16MHz, external)" board option & burnt the bootloader. It was successful.
Tools> boards> ATmega32/32A (16MHz, external)
Tools> programmers> USBasp
Tools> Burn Bootloader

Then tried to upload the blink sketch
Tools> boards> ATmega32/32A (16MHz, external)
Tools> programmers> USBasp
File> Upload Using Programmer

The error shows
Code: [Select]
In file included from C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\cores\standard\/Arduino.h:213,
                from C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\cores\standard\/wiring_private.h:33,
                from C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\cores\standard\wiring_digital.c:28:
C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\cores\standard\/pins_arduino.h:128: error: 'PCMSK0' undeclared here (not in a function)
C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\cores\standard\/pins_arduino.h:129: error: 'PCMSK1' undeclared here (not in a function)
C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\cores\standard\/pins_arduino.h:130: error: 'PCMSK2' undeclared here (not in a function)
C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\cores\standard\/pins_arduino.h:131: error: 'PCMSK3' undeclared here (not in a function)


All the errors are regarding "PCMSK" & after googling a bit I find it out to be something related to the pinchange interrupt. Then opened the pins_arduino.h file & get this
Code: [Select]

const uint16_t __pcmsk[] =
{
 (uint16_t)&PCMSK0,
 (uint16_t)&PCMSK1,
 (uint16_t)&PCMSK2,
 (uint16_t)&PCMSK3
};

I stopped here.

Second Method
Leaving all the changes done in the first attempt untouched except restoring the Bobuino folder to "C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\variants". I put & overwrite the attached files (arduino.h, wiring_digital.c & pins_arduino.h) to the following folder "C:\Users\Roy\Desktop\arduino-1.0.5\hardware\mighty-1284p\cores\standard"
then selected
Then tried to upload the blink sketch
Tools> boards> Bobuino
Tools> programmers> USBasp
File> Upload Using Programmer

As I am using the wrong chip (Mega32A), IDE shows error stating "Wrong microcontroller found"
Code: [Select]

Binary sketch size: 1,246 bytes (of a 130,048 byte maximum)
avrdude: Expected signature for ATMEGA1284P is 1E 97 05
        Double check chip, or use -F to override this check.

I stopped here.

I suppose I am doing something wrong with the "PCMSK" while using the bobuino pins_arduino.h with Mega32A.
Should I delete the "PCMSK" part from the bobuino pinmapping .h file?
Ummm.?


"mighty" folder location


Board selected in the first attempt


Board selected in the second attempt.

I can successfully upload sketches to Mega32A using the mega32 core files but I have to compromise with the pinmappings, I guess in that case I have to alter all the pin configurations for every arduino library. On the other hand bobuino features all  the pin numbers including the spi, i2c, uart, adc etc. in a standard manner that will make the use of arduino libraries less complicated. That's why I want to alter the pin mappings in my mega32A.
"Imagination is more important than knowledge."<br />-Einstein

CrossRoads

You're definitely on the right track, keep at it.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nightcrawler218

#21
Dec 28, 2013, 10:14 pm Last Edit: Dec 28, 2013, 10:18 pm by nightcrawler218 Reason: 1
Thanks a million times CrossRoads for the support & motivation throughout the experiment. Aaaahhhh... what a relief! I just commented out the "PCMSK" part of the pins_arduino.h file & the blink sketch works. I tried different pins & it works as desired.
I deleted the "mighty" folders completely & changed the core directory to "arduino", this pin mapping works with that too without any additional core files. Can't I use the interrupt feature in the mega32A chip? Will there be any problem while using the UART & other protocols with that setup? Should I have to add some other files to make these things work? I'm asking this because the new pin mapping works without any additional arduino.h, wiring_digital.c files. Any suggestions?

I'm using the optiboot_atmega32_16MHz.hex bootloader file. Tomorrow I'll try to upload sketches on the mega32 without using the bootloader so that I can use full 32kb space.
Once again, thanks a lot CrossRoads.
:)
"Imagination is more important than knowledge."<br />-Einstein

CrossRoads

I don't know, try things & see what works or doesn't. Add things back in as needed.  Good luck!
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nightcrawler218

Successfully uploaded sketches to the mega32A(with bobuino pin mapping) without using bootloader.
Now the next step is to implement the "playing tones based on micros()" project. Excited
:)
"Imagination is more important than knowledge."<br />-Einstein

CrossRoads

So you're just using File:Upload Using Programmer then and things are working ok? Cool.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nightcrawler218

#25
Dec 29, 2013, 07:46 pm Last Edit: Dec 29, 2013, 07:48 pm by nightcrawler218 Reason: 1
Yes, it is really working fine. saw some tutorials that said to edit the preference.txt file for changing the upload protocol to "USBasp". I just wanted to see what happens if I don't use the edit method. In the first attempt it worked!

Procedure followed:

Connected the chip to the computer with Usbasp programmer.
Added 16MHz crystal
opened "extremeburner" software (avrdude gui)
Selected the proper chip from chip settings
hit the "chip erase" option
then opened the arduino.exe
opened the blink sketch & changed the pin number to 31 to check both pin mapping & upload.
board & programmer setting are same as the first attempt settings
then hit "upload using programmer"
the sketch uploaded
I checked again with pin number 12 & trust me it worked!
:o
"Imagination is more important than knowledge."<br />-Einstein

CrossRoads

Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nightcrawler218

#27
Dec 29, 2013, 09:30 pm Last Edit: Dec 29, 2013, 09:34 pm by nightcrawler218 Reason: 1
I suppose the issue is with the lock bits. According to this discussion ( http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=59549 ), the "chip erase" function doesn't remove the fuse bits. But erases all the flash and lock bits if they are set, as well as EEPROM. 
I didn't reconfigured the fusebits for using the mega32 without bootloader, the fusebits were already set to require 16MHz external crystal when I uploaded the arduino bootloader. I think this the explanation of such behaviour of mega32. Please correct me if I'm getting it wrong.

The boards.txt content is this...
Code: [Select]

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

atmega32_at16e.name=ATmega32/32A (16MHz, external)

atmega32_at16e.upload.protocol=arduino
atmega32_at16e.upload.maximum_size=32256
atmega32_at16e.upload.speed=115200

atmega32_at16e.bootloader.low_fuses=0xFF
atmega32_at16e.bootloader.high_fuses=0xD6
#make atmega32 AVR_FREQ=8000000L BAUD_RATE=115200 UART=0 LED=B7 LED_START_FLASHES=3
atmega32_at16e.bootloader.path=optiboot
atmega32_at16e.bootloader.file=optiboot_atmega32_16MHz.hex
atmega32_at16e.bootloader.unlock_bits=0x3F
atmega32_at16e.bootloader.lock_bits=0x0F

atmega32_at16e.build.mcu=atmega32
atmega32_at16e.build.f_cpu=16000000L
atmega32_at16e.build.core=arduino
atmega32_at16e.build.variant=mega32

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

But the last post of the avrfreaks.com discussion put me in puzzle!


After doing a "Chip Erase" uploaded the blink sketch. Pin 12


After the chiperase I read the fusebits in the gui. The lock bits are changed.
Now this is getting mysterious. What is actually happening there? Can't get it.
Any tweaks on how to check if there is any bootloader in the chip?
"Imagination is more important than knowledge."<br />-Einstein

CrossRoads

The Extended, High, Low, and Lock bits may read back as 1 if they do not exist, don't be confused by non-existent bits.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nightcrawler218

After burning the arduino bootloader the "lock bits" are set to 0X0F
0X0F = 0000 1111
lock bits.........  7  6  5  4  3  2  1  0
bits allocated (-  -) 0  0  1   1  1  1
it should be     1   1  0  0  1   1   1  1 = 0XCF

But according to the datasheet, bits 6 & 7 are non-existent & default value is "1"
so the lockbit should be 1100 1111 or 0XCF. But in practice it is 0X0F. what is the reason?


What are the "Unlock bits"? Found a thread http://forum.arduino.cc/index.php?topic=23577.0. I quote
Quote

What error do you get? 

The "unlock" bits are just the value that's written to the lock bits before burning the bootloader.  Then the "lock" bits are written after burning the bootloader.

So, what is the significance of using the unlock bits in arduino?
"Imagination is more important than knowledge."<br />-Einstein

Go Up