W601裸機配置串口1可以發送數據但是不能接受數據

發布於 2022-09-23 16:16:35

下面是我寫的代碼,初始化後可以發送數據,但是一直不進接受中斷
`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);        //清除狀態標志位
}    

}
`

查看更多

關注者
0
被浏覽
1.8k
ZYQ
ZYQ 2022-09-25
我已不再支持W80X任何相關問題的回複,請大家不要私信,有問題找 isme 謝謝

沒搞明白你為什麼這樣做
image.png

1 個回答

撰寫答案

請登錄後再發布答案,點擊登錄

發布
問題

分享
好友

手機
浏覽

掃碼手機浏覽