- For STK600 board and ATmega2560 chips
(click to expand/hide)
- Install WSL(Windows Subsystem for Linux) and Ubuntu LTS
- Connect the STK600 board power source USB to your computer
- Connect Atmel ICE to the STK600 board's JTAG port and USB side to your computer
- Now that both devices(Atmel ICE and STK600) are only connected to your local computer, WSL has not yet attached to both devices yet
- To allow WSL to attach to Atmel ICE and STK600
- Run Windows power shell/command prompt as administrator mode
- Run command below to check the bus ID of Atmel ICE and STK600
usbipd wsl list
- Once you get both devices' bus ID, run:
command above will ask for sudo permission, enter password to allow device connect to WSL.
usbipd wsl attach -b <busid>
- To check if both devices(Atmel ICE and STK600) connected to WSL, run command below on WSL:
lsusb
- To detach the devices, run:
usbipd wsl detach --busid <busid>
(click to expand/hide)
cp <path to file in your local computer> <path for files to be store on your WSL>
- example
cp /mnt/c/Users/AA/Desktop/avr_code.c /home/aa
(click to expand/hide)
- Make sure to run your WSL as administrator
- Make sure to setup a Makefile that will transfer your code to the microcontroller, sample Makefile file included in this repository
- Transfer your code and Makefile to the WSL
- If you are using the sample Makefile, run the below commands:
- First run make to build the executable
make
- Then transfer code to microcontroller
make <name you set on Makefile>-install
- If you get the error below:
make error
Please use the command below
sudo make <name you set on Makefile>-install
- If you get the error below:
make error
Please use the command below
- First run make to build the executable
(click to expand/hide)
#include <avr/io.h>
int main(void)
{
while (1) {
// infinite loop
// perform task(s) here
}
return 0;
}
(click to expand/hide)
- To turn LEDs, first set portB as output then change the 8bit value on variable PORTB
- each bit on the PORTB variable represent a LED
- 0 : turn on LED
- 1 : turn off LED
- each bit on the PORTB variable represent a LED
#include <avr/io.h>
int main(void) {
//Set PORTB as output
DDRB = 0xff;
PORTB = 0x00; //turn on all LEDs
while (1) {
// infinite loop
// perform task(s) here
}
return 0;
}
(click to expand/hide)
- A timer interrupt that fires every 1 millisecond
#include <avr/io.h>
#include <avr/interrupt.h>
uint8_t interrupt_counter = 0; // counter uses to count how many interrupt occurred
//initial setup
void init_setup()
{
// Set timer 0 to use CTC mode
TCCR0A = (1 << WGM01);
// Set timer 0 to use a 64 prescaler
TCCR0B = (1 << CS01);
// Set timer 1 compare match 250 ticks
OCR0A = 125;
// Enable timer compare match interrupt
TIMSK0 = (1 << OCIE0A);
// Enable global interrupts
sei();
ADMUX = (1 << REFS1) | (1 << REFS0); //setup for using 2.56 internal voltage reference
ADCSRA = (1 << ADEN) | (1 << ADPS2) | (1 << ADPS1) | (1 << ADPS0); // setup 128 prescaler
}
int main(void)
{
init_setup();
while(1) {
if(interrupt_counter >= 100){ // update led level every 100ms
interrupt_counter = 0; //reset interrupt counter to 0
//perform task here
}
//perform task here
}
return 0;
}
ISR(TIMER0_COMPA_vect) { // interrupt for heartbeat
// increment time_counter every 1 millisecond
interrupt_counter++;
}
- To calculate to fire interrupt at an exact time, visit link below: