32 lines
742 B
C
32 lines
742 B
C
#ifndef UART_H
|
|
#define UART_H
|
|
|
|
#include <stdint.h>
|
|
|
|
// RS485 baud rate
|
|
#define UART1_BAUD_RATE 9600
|
|
#define UART2_BAUD_RATE 115200
|
|
|
|
// APB1 bus clock is half the system core clock
|
|
#define APB1_CLOCK (FUNCONF_SYSTEM_CORE_CLOCK / 2)
|
|
|
|
// Calculate baud rate divisors
|
|
// Adds BAUD_RATE/2 for rounding to nearest integer
|
|
#define UART_BRR_APB1 \
|
|
(((APB1_CLOCK) + (UART2_BAUD_RATE / 2)) / (UART2_BAUD_RATE))
|
|
#define UART_BRR_APB2 \
|
|
(((FUNCONF_SYSTEM_CORE_CLOCK) + (UART1_BAUD_RATE / 2)) / (UART1_BAUD_RATE))
|
|
|
|
// Function prototypes
|
|
|
|
// UART2
|
|
void uart2_init(int uart_brr);
|
|
|
|
// RS485 functions
|
|
void rs485_init(int uart_brr);
|
|
void rs485_send(uint8_t *buf, uint16_t len);
|
|
uint8_t rs485_available(void);
|
|
uint8_t rs485_read(void);
|
|
|
|
#endif // UART_H
|