ASCII Serial Com
Serial communication library between computers, microcontrollers, FPGAs, etc. Uses only ASCII. Not the most efficient protocol, but meant to be easy to read
Loading...
Searching...
No Matches
arduino_uno_cb_loopback.c
1#include "asc_exception.h"
2#include "asc_helpers.h"
3#include "avr/avr_uart.h"
4#include "circular_buffer.h"
5#include <avr/io.h>
6
7#define FOSC 16000000L
8#define BAUD 9600
9#define UART_NO 0
10#define MYUBRR (FOSC / 16 / BAUD - 1)
11
12#define bufCap 64
13
14uint8_t byteBuffer;
15uint8_t rawBuffer[bufCap];
17CEXCEPTION_T e;
18
19int main(void) {
20
21 Try { circular_buffer_init_uint8(&cb, bufCap, rawBuffer); }
22 Catch(e) { return e; }
23
24 UART_Init(UART_NO, MYUBRR, 0);
25
26 while (1) {
27 Try {
28 uart_rx_to_circ_buf(UART_NO, &cb);
29 uart_tx_from_circ_buf(UART_NO, &cb);
30 }
31 Catch(e) { return e; }
32 }
33 return 0;
34}
#define uart_rx_to_circ_buf(uart_no, circ_buf_ptr)
Receive a byte from UART into circular buffer.
#define uart_tx_from_circ_buf(uart_no, circ_buf_ptr)
Transmit a byte from the circular buffer.
#define UART_Init(uart_no, ubrr, rxIntEnable)
Initialize USART.
Definition avr_uart.h:20
void circular_buffer_init_uint8(circular_buffer_uint8 *circ_buf, const size_t capacity, uint8_t *buffer)
circular buffer init method
circular buffer struct