ING91680C BLE5.3 芯片怎么实现串口中断收发数据,
```c
写了这些代码,
#define UART_INTBIT_RECEIVE 0x10 //receive interrupt
#define UART_INTBIT_TRANSMIT 0x20 //transmit interrupt
char dst[256];
int index = 0;
void apUART_BaudRateSet(
UART_TypeDef* pBase, //UART参数结构体&设备地址
uint32_t ClockFrequency, //时钟信号的频率
uint32_t BaudRate //波特率
);
void apUART_Initialize(
UART_TypeDef* pBase,
UART_sStateStruct* UARTx, //uart状态结构体
uint32_t IntMask //中断掩码
);
void config_uart(uint32_t freq, uint32_t baud)
{
UART_sStateStruct config;
config.word_length = UART_WLEN_8_BITS;
config.parity = UART_PARITY_NOT_CHECK;
config.fifo_enable = 1;
config.two_stop_bits = 0;
config.receive_en = 1;
config.transmit_en = 1;
config.UART_en = 1;
config.cts_en = 0;
config.rts_en = 0;
config.rxfifo_waterlevel = 1;
config.txfifo_waterlevel = 1;
config.ClockFrequency = freq;
config.BaudRate = baud;
apUART_Initialize(APB_UART0, &config, UART_INTBIT_RECEIVE | UART_INTBIT_TRANSMIT);
}
void setup_peripheral_uart()
{
APB_UART0->FifoSelect = (0 << bsUART_TRANS_INT_LEVEL ) |
(0X10 << bsUART_RECV_INT_LEVEL ) ;
APB_UART0->IntMask = (1 << bsUART_RECEIVE_INTENAB) | (0 << bsUART_TRANSMIT_INTENAB) |
(1 << bsUART_TIMEOUT_INTENAB);
APB_UART0->Control = 1 << bsUART_RECEIVE_ENABLE |
1 << bsUART_TRANSMIT_ENABLE |
1 << bsUART_ENABLE |
0 << bsUART_CTS_ENA |
0 << bsUART_RTS_ENA;
}
uint32_t uart_isr(void *user_data)
{
uint32_t status;
while(1)
{
status = apUART_Get_all_raw_int_stat(APB_UART0);
if (status == 0)
break;
APB_UART0->IntClear = status;
// rx int
if (status & (1 << bsUART_RECEIVE_INTENAB))
{
while (apUART_Check_RXFIFO_EMPTY(APB_UART0) != 1)
{
char c = APB_UART0->DataRead;
dst[index] = c;
index++;
}
}
// rx timeout_int
if (status & (1 << bsUART_TIMEOUT_INTENAB))
{
while (apUART_Check_RXFIFO_EMPTY(APB_UART0) != 1)
{
char c = APB_UART0->DataRead;
dst[index] = c;
index++;
}
}
printf("\ndst = %s\n",dst);
}
return 0;
}
void uart_peripherals_read_data()
{
//注册uart0中断
platform_set_irq_callback(PLATFORM_CB_IRQ_UART0, uart_isr, NULL);
setup_peripheral_uart();
}
static void watchdog_task(void *pdata)
{
for (;;)
{
printf("hello1\r\n");
vTaskDelay(pdMS_TO_TICKS(2500));
TMR_WatchDogRestart();
}
}
主函数是这样的
int app_main()
{
cube_soc_init();
config_uart(OSC_CLK_FREQ, 115200);
uart_peripherals_read_data();
// setup event handlers
platform_set_evt_callback_table(&evt_cb_table);
SYSCTRL_Init();
setup_peripherals();
xTaskCreate(watchdog_task,
"w",
configMINIMAL_STACK_SIZE,
NULL,
(configMAX_PRIORITIES - 1),
NULL);
trace_rtt_init(&trace_ctx);
// TODO: config trace mask
platform_config(PLATFORM_CFG_TRACE_MASK, 0);
return 0;
}
然后他只能做到定时发送数据,但是接收不到数据,我先在就想实现一个接收到数据马上把接收到的数据打印出来的功能