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_write_pattern_to_serial.c
1#include "arm/stm_usart.h"
2#include <libopencm3/stm32/gpio.h>
3#include <libopencm3/stm32/rcc.h>
4
5#define PORT_LED GPIOA
6#define PIN_LED GPIO5
7#define RCC_GPIO_LED RCC_GPIOA
8
9// USART2 should be connected through USB
10#define ASC_USART USART2
11
12static void gpio_setup(void) {
13 rcc_periph_clock_enable(RCC_GPIO_LED);
14
15 gpio_mode_setup(PORT_LED, GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, PIN_LED);
16}
17
18uint8_t counter = 0;
19
20int main(void) {
21
22 gpio_setup();
23
24 // USART2 TX: PA2 AF1
25 // USART2 RX: PA3 AF1
26 rcc_periph_clock_enable(RCC_GPIOA);
27 rcc_periph_clock_enable(RCC_USART2);
28 setup_usart(ASC_USART, 9600, GPIOA, GPIO2, GPIO_AF1, GPIOA, GPIO3, GPIO_AF1);
29 // usart_set_mode(ASC_USART,USART_MODE_TX); // this was here before, is it
30 // still needed?
31 usart_enable(ASC_USART);
32
33 while (1) {
34 usart_send_blocking(ASC_USART, '0' + counter);
35 if (counter >= 9) {
36 counter = 0;
37 // gpio_toggle(PORT_LED, PIN_LED);
38 } else {
39 counter++;
40 }
41 // for (int i = 0; i < 10000; i++) {
42 // __asm__("nop");
43 // }
44 }
45
46 return 0;
47}
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