M453开发UART功能中使用DMA实现串口功能。
目前只有到达设定的长度后才触发DMA中断,如何实现当接收到的数据小于UART0_DMA_LEN时也能检测到
大家有没有什么好的方法实现,我现在的方法如下,但是实现不了,无法检测到HWTOINT中断
M453芯片手册中UART_INTSTS手册中,有介绍到HWTOINT中断,目前无法进入该中断
具体代码如下:
PDMA通道初始化函数
void UART0_PMDA(void)
{
SYS_ResetModule(PDMA_RST);
PDMA_Open(DMA_CH0);
PDMA_SetTransferAddr(0,(unsigned int)(&(UART0->DAT)),PDMA_SAR_FIX,
(unsigned int)UART0_DMA_Buf1,PDMA_DAR_INC);
PDMA_SetTransferCnt(0,PDMA_WIDTH_8,UART0_DMA_LEN); //8位,总长2字节
PDMA_SetTransferMode(0,PDMA_UART0_RX,FALSE,0); //通道0设置为UART0_RX
PDMA_SetBurstType(0,PDMA_REQ_SINGLE,PDMA_BURST_1);
PDMA_EnableInt(0, 0);
NVIC_EnableIRQ(PDMA_IRQn);
}
PDMA中断处理函数
void PDMA_IRQHandler(void)
{
FIFO_QUNE *pUart_rx_fifo = NULL;
uint32_t cnt;
uint32_t status = PDMA_GET_INT_STATUS();
if(status & 0x1) /* abort */
{
PDMA_CLR_ABORT_FLAG(PDMA_ABTSTS_ABTIFx_Msk);
}
else if(status & 0x2) /* done */
{
pUart_rx_fifo = &Uart0_rx_fifo;
cnt = pUart_rx_fifo->size - pUart_rx_fifo->rear;
if(cnt > UART0_DMA_LEN)
{
memcpy(pUart_rx_fifo->dat+pUart_rx_fifo->rear,UART0_DMA_Buf1,UART0_DMA_LEN);
pUart_rx_fifo->rear += UART0_DMA_LEN;
}
else
{
memcpy(pUart_rx_fifo->dat+pUart_rx_fifo->rear,UART0_DMA_Buf1,cnt);
pUart_rx_fifo->rear = 0;
memcpy(pUart_rx_fifo->dat+pUart_rx_fifo->rear,&UART0_DMA_Buf1[cnt] ,UART0_DMA_LEN-cnt);
pUart_rx_fifo->rear += UART0_DMA_LEN-cnt;
}
PDMA_CLR_TD_FLAG(PDMA_TDSTS_TDIFx_Msk);
//重新设置模式,映射地址。这样可实现循环接收
PDMA_SetTransferAddr(0,(unsigned int)(&(UART0->DAT)),PDMA_SAR_FIX,
(unsigned int)UART0_DMA_Buf1,PDMA_DAR_INC);
PDMA_SetTransferCnt(0,PDMA_WIDTH_8,UART0_DMA_LEN);
PDMA_SetTransferMode(0,PDMA_UART0_RX,FALSE,0);
}
}
main函数中中断使能函数
UART_EnableInt(UART0, (UART_INTEN_RDAIEN_Msk | UART_INTEN_RXPDMAEN_Msk |
UART_INTEN_TOCNTEN_Msk | UART_INTEN_RXTOIEN_Msk));
串口中断处理函数
void UART0_IRQHandler(void)
{
uint8_t nByte = 0xFF;
if(UART0->INTSTS & (UART_INTSTS_RDAINT_Msk | UART_INTSTS_RXTOIF_Msk |
UART_INTSTS_HWTOINT_Msk))
{
/* Get all the input characters */
while(!(UART0->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk))
{
/* Get the character from UART Buffer */
nByte = UART0->DAT;
/* Check if buffer full */
if(FIFO_NOT_FULL == Queue_is_Full(&Uart0_rx_fifo))
{
Queue_In(&Uart0_rx_fifo, nByte);
}
}
}
}
|