Arduino and spi

Arduino Mega2560
Arduino Mega2560 (Photo credit: Wikipedia)

I wanted to use SPI on Arduino Uno and after reading some documentation I used SPI.beginTransaction() command to start the SPI communication, but nothing.

 

After banging my head against the wall I decided to start older (not recommended) version of

 

SPI.begin()… and voila. It worked.

 

 

 

Go figure.

 

ATmega32 and Arduino

The Arduino NG board from arduino.cc. A circui...
The Arduino NG board from arduino.cc. A circuit board with an Atmel ATmega8 microcontroller. (Photo credit: Wikipedia)

I tested OLED display I bought on ebay just to see if it works. What better way to do it than use Arduino platform. Libraries are more or less available and you can do quick test. Unfortunately it took me some time, since there are a lot of different ways to connect displays – not to mention different pins.

Luckily – I managed to finally get the display working by using Adafruit library. Had to use SPI communication since the display uses only that.

Anyway – the success was nice, but what I really wanted was use ATMEL and connect the display to microcontroller and not use the whole board. So here we go with coding for the microcontroller, right?

Well, so I thought and then it dawned on me (I know, I know – obvious thing) – why not add Arduino bootloader to ATMEGA16 and do it like that. Unfortunately ATMEGA16 was too small (16k was not enough) and since I have ATMEGA32A lying around – let’s do it on the 32k micro, then.

And this is the story of how to do it:

You need to add the “board” (well, microcontroller in our case) to Arduino IDE. This can be easily done by following this. Although it is created for old version of Arduino IDE it works ok with latest one (1.6.4).  You just need to hack it to make it work with larger memory and (possibly) different fuses. I did that:

##############################################################
# Additional definitions for Arduino
# Author: Bostjan Jerko <http://www.japina.eu>
##############################################################
# Definitions for ATmega32A 8MHz 
##############################################################
atmega32a-8.name=Atmega32A (internal 8MHz clock)

atmega32a-8.upload.maximum_size=30720
atmega32a-8.upload.tool=arduino:avrdude
atmega32a-8.upload.verbose=true
atmega32a-8.bootloader.tool=arduino:avrdude

atmega32a-8.bootloader.low_fuses=0xc0
atmega32a-8.bootloader.high_fuses=0x99
atmega32a-8.bootloader.unlock_bits=0xff
#atmega32a-8.bootloader.lock_bits=0xef

atmega32a-8.build.mcu=atmega32
atmega32a-8.build.f_cpu=8000000L
atmega32a-8.build.core=arduino:arduino
atmega32a-8.build.variant=atmega32
atmega32a-8.bootloader.file=atmega/ATmegaBOOT_168_atmega328.hex

in boards.txt file (in /Applications/Arduino.app/Contents/Java/hardware/arduino/avr on Mac OSX).

I have just copied pins_arduino.h to new directory (name of the directory is under build.variant).

Connect the programmer to the scheme, select proper Board, Port and Programmer (AVRISP mkII in my case of stk500v2 programmer) in Arduino IDE. Click Burn Bootloader and hope for the best.

It didn’t work for me 🙁

So what now? Well, since I started Burn Bootloader I thought the .hex file should be created and it was (under bootloaders/atmega) and according to this you just need to do some manual programming.

I have used the ATmegaBOOT_168_atmega328.hex and it looks like it works ok. Well, at least OLED display works 🙂