Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Serial communication, USART, LUFA Library, AVR
#include <stdio.h>
#include <avr/interrupt.h>
#include <LUFA/Drivers/Peripheral/Serial.h>
#define MAX_BUFFER 32
char b[MAX_BUFFER];
uint8_t l = 0;
ISR(USART1_RX_vect) {
char c = fgetc(stdin);
printf("%c", c);
if (c == '\r') {
printf("\r\n<< %s\r\n>> ", b);
l = 0;
memset(b, 0, sizeof(b));
} else if (c != '\n' && l < MAX_BUFFER) {
b[l++] = c;
}
}
int main(void) {
Serial_Init(9600, false);
Serial_CreateStream(NULL);
sei();
UCSR1B |= (1 << RXCIE1);
printf("{{ Ready }}\r\n>> ");
for(;;);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment