下面是我寫的代碼,初始化後可以發送數據,但是一直不進接受中斷
`void uart1_init(u32 bound)
{
u32 bd;
u32 apbclk;
tls_sys_clk sysclk;
/* 1.配置IO */
wm_uart1_tx_config(WM_IO_PB_12);
wm_uart2_rx_config(WM_IO_PB_11);
/* 2.波特率設置:
ubdiv = (apbclk / (16 * bound) - 1)
ubdiv_frac = ((apbclk % (bound * 16)) / (bound)) */
tls_sys_clk_get(&sysclk);
apbclk = sysclk.apbclk * 1000000;
bd = (apbclk / (16 * bound) - 1) | (((apbclk % (bound * 16)) / (bound)) << 16);
tls_reg_write32(HR_UART0_BAUD_RATE_CTRL, bd);
/* 2.串口參數設置:8位數據位/1位停止位/無奇偶校驗位/發送使能/接收使能 */
tls_reg_write32(HR_UART1_LINE_CTRL, ULCON_WL8 | ULCON_TX_EN | ULCON_RX_EN);
/* 3.硬件流控關閉 */
tls_reg_write32(HR_UART1_FLOW_CTRL, 0);
/* 3.不使能DMA */
tls_reg_write32(HR_UART1_DMA_CTRL, 0);
/* 4.FIFO觸發設置:1個字節 */
tls_reg_write32(HR_UART1_FIFO_CTRL, 0);
/* 5.開啟RX中斷:接收觸發中斷和接收超時中斷*/
tls_reg_write32(HR_UART1_INT_MASK, 0xFF & (~(UIS_RX_FIFO | UIS_RX_FIFO_TIMEOUT)));
/* 6.串口接收中斷配置 */
NVIC_ClearPendingIRQ(UART1_IRQn);
NVIC_InitTypeDef NVIC_InitStruct;
NVIC_InitStruct.NVIC_IRQChannel = UART1_IRQn;
NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority = 7;
NVIC_InitStruct.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStruct);
}
void UART1_IRQHandler(void)
{
tls_reg_write32(HR_UART1_TX_WIN,'1');
tls_reg_write32(HR_UART1_TX_WIN,'\r');
tls_reg_write32(HR_UART1_TX_WIN,'\n');
if(tls_reg_read32(HR_UART1_INT_SRC) & UIS_RX_FIFO) //接收到數據
{
USART1_RX_BUF[USART1_RX_STA] = (u8)tls_reg_read32(HR_UART1_RX_WIN);
USART1_RX_STA++;
tls_reg_write32(HR_UART1_INT_SRC, UIS_RX_FIFO); //清除狀態標志位
}
}
`
謝謝了,我寫錯了串口號