下面是我写的代码, 初始化后可以发送数据, 但是一直不进接受中断
`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) ; //清除状态标志位
}
}
`
谢谢了, 我写错了串口号