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_asc_write_pattern_to_serial.c
1#include "asc_exception.h"
2#include "asc_helpers.h"
3#include "ascii_serial_com.h"
4#include "avr/avr_uart.h"
5#include <avr/io.h>
6#define UART_NO 0
7
8#define F_CPU 16000000L
9#include <util/delay.h>
10#define FOSC 16000000L
11#define BAUD 9600
12#define MYUBRR (FOSC / 16 / BAUD - 1)
13
14CEXCEPTION_T e;
15uint16_t nExceptions;
16
18circular_buffer_uint8 *asc_out_buf;
19const char ascVersion = '0';
20const char appVersion = '0';
21char dataBuffer[2];
22const size_t dataLen = 2;
23
24int main(void) {
25
26 Try {
28 ascii_serial_com_set_ignore_CRC_mismatch(&asc);
29 asc_out_buf = ascii_serial_com_get_output_buffer(&asc);
30 dataBuffer[0] = '0';
31 dataBuffer[1] = '0';
32 }
33 Catch(e) { return e; }
34
35 UART_Init(UART_NO, MYUBRR, 0);
36
37 while (true) {
38 Try {
39 if (circular_buffer_is_empty_uint8(asc_out_buf)) {
41 &asc, ascVersion, appVersion, dataBuffer, dataLen);
42 if (dataBuffer[0] == '9') {
43 dataBuffer[0] = '0';
44 } else {
45 dataBuffer[0]++;
46 }
47 }
48 uart_tx_from_circ_buf(UART_NO, asc_out_buf);
49 }
50 Catch(e) { nExceptions++; }
51 }
52
53 return 0;
54}
#define uart_tx_from_circ_buf(uart_no, circ_buf_ptr)
Transmit a byte from the circular buffer.
circular_buffer_uint8 * ascii_serial_com_get_output_buffer(ascii_serial_com *asc)
ASCII Serial Com get output buffer.
void ascii_serial_com_put_s_message_in_output_buffer(ascii_serial_com *asc, char ascVersion, char appVersion, const char *data, size_t dataLen)
ASCII Serial Com Pack and put 's' message in output buffer.
void ascii_serial_com_init(ascii_serial_com *asc)
ASCII Serial Com Interface init method.
#define UART_Init(uart_no, ubrr, rxIntEnable)
Initialize USART.
Definition avr_uart.h:20
bool circular_buffer_is_empty_uint8(const circular_buffer_uint8 *circ_buf)
circular buffer get if empty
ASCII Serial Com Interface State struct.
circular buffer struct