Created
January 13, 2018 20:01
-
-
Save ebith/68f2b6ecd65a5705fc24b1fea7b62702 to your computer and use it in GitHub Desktop.
Serial communication, USART, LUFA Library, AVR
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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