You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.2 KiB

3 months ago
#include "uart.h"
#include "delay.h"
#include "r_cg_adc.h"
#include <string.h>
volatile uint8_t g_uart1_tx_done = 1;
extern volatile uint16_t g_uart1_tx_count;
/* UART1 송신용 내부 버퍼 */
static uint8_t s_uart1_txbuf[1024];
static void UART1_WaitTxIdle(void)
{
unsigned long guard = 0;
while (g_uart1_tx_count != 0U) {
if (guard++ > 3000000UL) {
break;
}
}
}
void uart1_send_string(const char *str)
{
uint16_t len = 0;
if (str == 0) return;
while (str[len] != '\0') len++;
UART1_WaitTxIdle();
g_uart1_tx_done = 0;
if (len >= (uint16_t)sizeof(s_uart1_txbuf)) {
len = (uint16_t)(sizeof(s_uart1_txbuf) - 1);
}
memcpy(s_uart1_txbuf, str, len);
R_UART1_Send(s_uart1_txbuf, len);
}
void uart1_send_hex(uint8_t val)
{
static uint8_t hex[2];
uint8_t high = (uint8_t)((val >> 4) & 0x0F);
uint8_t low = (uint8_t)(val & 0x0F);
hex[0] = (high < 10U) ? (uint8_t)('0' + high) : (uint8_t)('A' + (high - 10U));
hex[1] = (low < 10U) ? (uint8_t)('0' + low ) : (uint8_t)('A' + (low - 10U));
UART1_WaitTxIdle();
g_uart1_tx_done = 0;
R_UART1_Send(hex, 2);
}