LED clock
 All Files Functions Variables Macros Groups
Macros | Functions | Variables
usart.c File Reference

library for USART communication (code) More...

Go to the source code of this file.

Macros

#define USART   USART1
 USART peripheral.
 
#define USART_RCC   RCC_USART1
 USART peripheral clock.
 
#define USART_IRQ   NVIC_USART1_IRQ
 USART peripheral interrupt signal.
 
#define USART_ISR   usart1_isr
 USART interrupt service routine.
 
#define USART_PORT   GPIOA
 USART port.
 
#define USART_PORT_RCC   RCC_GPIOA
 USART port peripheral clock.
 
#define USART_PIN_TX   GPIO_USART1_TX
 USART transmit pin (PA9)
 
#define USART_PIN_RX   GPIO_USART1_RX
 USART receive pin (PA10)
 
#define USART_BAUDRATE   115200
 serial baudrate, in bits per second (with 8N1 8 bits, no parity bit, 1 stop bit settings)
 

Functions

void usart_setup (void)
 setup USART peripheral
 
void usart_putchar_blocking (char c)
 send character over USART (blocking) More...
 
void usart_flush (void)
 ensure all data has been transmitted (blocking) More...
 
char usart_getchar (void)
 get character received over USART (blocking) More...
 
void usart_putchar_nonblocking (char c)
 send character over USART (non-blocking) More...
 
void USART_ISR (void)
 USART interrupt service routine called when data has been transmitted or received.
 

Variables

static uint8_t rx_buffer [USART_BUFFER] = {0}
 ring buffer for received data
 
static volatile uint8_t rx_i = 0
 current position of read received data
 
static volatile uint8_t rx_used = 0
 how much data has been received and not red
 
static uint8_t tx_buffer [USART_BUFFER] = {0}
 ring buffer for data to transmit
 
static volatile uint8_t tx_i = 0
 current position if transmitted data
 
static volatile uint8_t tx_used = 0
 how much data needs to be transmitted
 
volatile uint8_t usart_received = 0
 how many bytes available in the received buffer since last read
 

Detailed Description

library for USART communication (code)

Author
King Kévin kingk.nosp@m.evin.nosp@m.@cuvo.nosp@m.odoo.nosp@m..info
Date
2016
Note
peripherals used: USART USART peripheral used for UART communication

Definition in file usart.c.

Function Documentation

void usart_flush ( void  )

ensure all data has been transmitted (blocking)

Note
block until all data has been transmitted

Definition at line 95 of file usart.c.

char usart_getchar ( void  )

get character received over USART (blocking)

Returns
character received over USART
Note
blocks until character is received over USART when received buffer is empty

Definition at line 103 of file usart.c.

void usart_putchar_blocking ( char  c)

send character over USART (blocking)

Parameters
[in]ccharacter to send
Note
blocks until character transmission started

Definition at line 89 of file usart.c.

void usart_putchar_nonblocking ( char  c)

send character over USART (non-blocking)

Parameters
[in]ccharacter to send
Note
blocks if transmit buffer is full, else puts in buffer and returns

Definition at line 117 of file usart.c.