本帖最后由 学电子的小峰源 于 2022-1-20 11:57 编辑
官方例程函数内容肯定是没有写错的,但是为什么发送0x1E我收到的却是80?怎么才能收到正确的数值呢?
主函数:
void main()
{
DisableGlobalIRQ(); //¹Ø±Õ×ÜÖжÏ
board_init();
//uart_init(DEBUG_UART,DEBUG_UART_BAUD,DEBUG_UART_RX_TX_PIN);
//UART1ÒÑÔÚboard_init Öгõʼ»¯£¬²¨ÌØÂÊ115200
EnableGlobalIRQ(); //¿ªÆô×ÜÖжÏ
while(1)
{
uart_putchar(DEBUG_UART,0x1E);
delay_ms(100);
}
}
串口发送数据的函数
//-------------------------------------------------------------------------------------------------------------------
// @brief ´串口字节输出
// @param uart_n 串口模块号(USART_1,USART_2,USART_3,USART_4)
// @param dat 需要发送的字节
// @return void
// Sample usage: uart_putchar(UART_1,0xA5); //串口1发送0xA5
//-------------------------------------------------------------------------------------------------------------------
void uart_putchar(UARTN_enum uart_n,uint8 dat)
{
switch(uart_n)
{
case UART_1:
while (busy[1]);
busy[1] = 1;
SBUF = dat;
break;
case UART_2:
while (busy[2]);
busy[2] = 1;
S2BUF = dat;
break;
case UART_3:
while (busy[3]);
busy[3] = 1;
S3BUF = dat;
break;
case UART_4:
while (busy[4]);
busy[4] = 1;
S4BUF = dat;
break;
}
}
宏定义
#define DEBUG_UART UART_1
#define DEBUG_UART_BAUD 115200
#define DEBUG_UART_RX_PIN UART1_RX_P30
#define DEBUG_UART_TX_PIN UART1_TX_P31
#define DEBUG_UART_TIM TIM_2
串口界面如图
|