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
stm32f091nucleo64_char_loopback.c
1#include "arm/stm_usart.h"
2#include <libopencm3/stm32/rcc.h>
3
4// USART2 should be connected through USB
5#define ASC_USART USART2
6
7uint8_t tmp_byte = 0;
8
9int main(void) {
10
11 // USART2 TX: PA2 AF1
12 // USART2 RX: PA3 AF1
13 rcc_periph_clock_enable(RCC_GPIOA);
14 rcc_periph_clock_enable(RCC_USART2);
15 setup_usart(ASC_USART, 9600, GPIOA, GPIO2, GPIO_AF1, GPIOA, GPIO3, GPIO_AF1);
16 usart_enable(ASC_USART);
17
18 while (1) {
19 if ((USART_ISR(ASC_USART) & USART_ISR_RXNE)) {
20 tmp_byte = (uint8_t)usart_recv(ASC_USART) & 0xFF;
21 }
22 if (tmp_byte && (USART_ISR(ASC_USART) & USART_ISR_TXE)) {
23 usart_send(ASC_USART, tmp_byte);
24 tmp_byte = 0;
25 }
26 }
27
28 return 0;
29}
To be used with the USART peripherals on STM32 microcontrollers.
#define setup_usart(usart, baud, tx_port, tx_pin, tx_af, rx_port, rx_pin, rx_af)
Setup a USART.
Definition stm_usart.h:52