ATmega 32 With MySmartUSB Light (Ubuntu)
by nikkischulz6 in Circuits > Microcontrollers
286 Views, 1 Favorites, 0 Comments
ATmega 32 With MySmartUSB Light (Ubuntu)
Goal: Program Atmega32 with mySmartUSB ligt ISP programmer
There are already similar tutorials.
I did it more as a documentation of my steps, so I can reproduce my own steps in future.
Plug in MySmartUSB Light
First plug the mySmartUSB light into USB
(I think SiSy Solutions GmbH creates them.)
https://shop.myavr.de/index.php?sp=article.sp.php&artID=200006
Ubuntu bash for checking the port:
$ sudo dmesg -w
When plugging it in you will se the port where it is connected.
In my case it is ttyUSB0
[29279.012225] usb 1-2.4: new full-speed USB device number 24 using xhci_hcd
[29279.272047] usb 1-2.4: New USB device found, idVendor=10c4, idProduct=ea60, bcdDevice= 2.04
[29279.272052] usb 1-2.4: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[29279.272053] usb 1-2.4: Product: myAVR - mySmartUSB light
[29279.272055] usb 1-2.4: Manufacturer: Silicon Labs
[29279.272056] usb 1-2.4: SerialNumber: mySmartUSBlight-0001
[29279.298064] cp210x 1-2.4:1.0: cp210x converter detected
[29279.310153] usb 1-2.4: cp210x converter now attached to ttyUSB0
Create a Atmega32 Project in Ubuntu
Create a folder for your first project...and enter the folder:
$ mkdir project1 && cd project1
Write Code for the Atmega32
I will present a C Code example for testing.
- Create a main.c file for your uC Programm.
- for example with nano. Or however it makes sense to you.
$ nano main.c
I found it here https://www.pololu.com/docs/0J61/6.3
I changed the CPU Speed to 8 MHz, because ... I thought it works with the internal 8 MHz oscillator.
- copy and paste (ctrl+strg+v) into main.c
#ifndef F_CPU
#define F_CPU 8000000UL // 8 MHz clock speed
#endif
#include <avr/io.h>
#include <util/delay.h>
int main(void)
{
DDRC = 0xFF; //Nakes PORTC as Output
while(1) //infinite loop
{
PORTC = 0xFF; //Turns ON All LEDs
_delay_ms(1000); //1 second delay
PORTC= 0x00; //Turns OFF All LEDs
_delay_ms(1000); //1 second delay
}
}
Connect 5V and the Programmer to Atmega32
- I connected the programmer (smart usb light) and 5v to the atmega32.
- I don't use a capacitor and I don't use a resistor. Because I don't know why it should be useful
- I will google it.
- Important is that 5V from the programmer are connected to AVCC without it didn't work
I hope you connect it right.
:D
I also added a LED to see the voltage go on and off..
It doesnt work at all pins. But for example at PC1!
I dont know why they made this example - or I dont know why PC2 does'nt work... but ok...
Toolchain Stuff
ok now for for compiling they use the avr-gcc compiler. It translates the code into an *.hex file which is then downloaded to the uC with the smartUSB light programmer.
You can either find out the little steps, or try makefile which can be ran and do the little steps for you...
Here is a makefile I found at https://www.pololu.com/docs/0J61/6.3
You can create one by typing in:
$nano makefile
It looks really strange but will run first the avr-gcc and then I think translate it into a *.hex file...
And then it will run the avrdude program to send it to the atmega
⚠️ TABS need to be correct if not the makefile doesnt work!
Here are the details: https://rn-wissen.de/wiki/index.php/Avr-gcc_und_avrdude_installieren
PORT=/dev/ttyUSB0
MCU=atmega32
CFLAGS=-g -Wall -mcall-prologues -mmcu=$(MCU) -Os
LDFLAGS=-Wl,-gc-sections -Wl,-relax
CC=avr-gcc
TARGET=main
OBJECT_FILES=main.o
all: $(TARGET).hex
clean:
rm -f *.o *.hex *.obj *.hex
%.hex: %.obj
avr-objcopy -R .eeprom -O ihex $< $@
%.obj: $(OBJECT_FILES)
$(CC) $(CFLAGS) $(OBJECT_FILES) $(LDFLAGS) -o $@
program: $(TARGET).hex
avrdude -p $(MCU) -c stk500 -P $(PORT) -U flash:w:$(TARGET).hex
To run the whole compilation and download to the atmega32 step you have to type in:
$make program
/project1$ make program
avrdude -p atmega32 -c stk500 -P /dev/ttyUSB1 -U flash:w:main.hex
avrdude: AVR device initialized and ready to accept instructions
Reading | ################################################## | 100% 0.01s
avrdude: Device signature = 0x1e9502 (probably m32)
avrdude: NOTE: "flash" memory has been specified, an erase cycle will be performed
To disable this feature, specify the -D option.
avrdude: erasing chip
avrdude: reading input file "main.hex"
avrdude: input file main.hex auto detected as Intel Hex
avrdude: writing flash (140 bytes):
Writing | ################################################## | 100% 0.10s
avrdude: 140 bytes of flash written
avrdude: verifying flash memory against main.hex:
avrdude: load data flash data from input file main.hex:
avrdude: input file main.hex auto detected as Intel Hex
avrdude: input file main.hex contains 140 bytes
avrdude: reading on-chip flash data:
Reading | ################################################## | 100% 0.18s
avrdude: verifying ...
avrdude: 140 bytes of flash verified
avrdude: safemode: Fuses OK (E:FF, H:99, L:E1)
avrdude done. Thank you.
In the attachment is also a pic of a program which works with it.. I did it on ttyUSB1 ... but the toolchain which is behind .. I mean the makefile behind the program is still the same i guess.. I mean you can see the called commands.