Skip to content

Instantly share code, notes, and snippets.

@hadleyrich
Created August 27, 2014 09:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hadleyrich/f1d0d151d260d724545c to your computer and use it in GitHub Desktop.
Save hadleyrich/f1d0d151d260d724545c to your computer and use it in GitHub Desktop.
/* usart hello world example */
/* This is a simple demo of avr-libc based usart comms. Once a port is initialised
* and mapped into a handle or stdio, you can use common libc functions
* like printf() to interact with the serial port.
*/
#define F_CPU 32000000
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdlib.h>
#include <stdio.h>
#include "kakapo.h"
#include "usart.h"
#include "clock.h"
#include "xbootapi.h"
/* out main code */
int main(void) {
/* ensure we're running at the expected clock rate */
kakapo_init();
sei();
/* configure the usart for 9600,8,N,1 */
/* usart_d0 is attached to USB */
usart_init(usart_d0, 128, 128); /* 128 byte RX and TX buffers */
usart_conf(usart_d0, 9600, 8, none, 1, 0, NULL); /* 9600,8,N,1; no feat; no callback */
usart_map_stdio(usart_d0); /* first allocated one is stdin/stdout/stderr */
usart_run(usart_d0); /* get it going */
PORTE.DIRSET = PIN3_bm;
printf("Start\r\n");
_delay_ms(2000);
xboot_app_temp_erase(); // DEBUG
printf("Done!\r\n");
_delay_ms(50);
/* blink an LED for each time we write */
while (1) {
printf("Hello, World!\r\n"); /* note trailing return/newline */
PORTE.OUTTGL = PIN3_bm; /* toggle yellow LED */
_delay_ms(300);
}
/* never reached */
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment