cc2530协议栈里面实现串口收发数据
程序员文章站
2022-07-13 17:22:49
...
在初始化函数中添加一下代码,例如在void SampleApp_Init( uint8 task_id );中添加
/*串口初始化*/
halUARTCfg_t uart_config;
uart_config.configured = TRUE;
uart_config.flowControl = FALSE;
uart_config.baudRate = HAL_UART_BR_9600;
uart_config.callBackFunc = uart_My_Event; //回调函数,在前面记得声明
HalUARTOpen (HAL_UART_PORT_0,&uart_config);//使用的是串口0
回调函数部分:
void uart_My_Event(uint8 port, uint8 event)
{
uint8 buf[128] = {0};
if(port == HAL_UART_PORT_0)
{
if(event &(HAL_UART_RX_FULL|HAL_UART_RX_ABOUT_FULL|HAL_UART_RX_TIMEOUT))
{
HalUARTRead (HAL_UART_PORT_0,buf,128); //接收数据
HalUARTWrite (HAL_UART_PORT_0,buf,128); 发送数据
}
}
}
推荐阅读