lpcware

DMA with usart

Discussion created by lpcware Employee on Jun 15, 2016
Content originally posted in LPCWare by ramniraj10 on Tue Dec 09 06:50:53 MST 2014
Using DMA for uart Tx and RX data.
Sample:
1. Data len is 9 bit.
2. Using DMA and UART1 IRQ
3. DMA is used to recv the expected buffer size.
4. In 9-bit mode, UARt interrupt is generated. Check the first byte if address. Disable RXRDY interrupt.
5. DMA is always running to receive all data.
6. Recv all data and enable RXRDY interrupt for further address detection.

Sample:

UART1_Handler()
{
    if ( Status & UART_STAT_RXRDY )
{
if ( ((regVal=Chip_UART_ReadByte(LPC_USART1)) & 0x100) && (Chip_UART_GetCTRLRegister(LPC_USART1) & UART_CTRL_ADDRDET) )
{
AddrDetected = regVal & 0x1FF;
Chip_UART_IntDisable(LPC_USART1, UART_INTEN_RXRDY);//Disable UART RXRDY Interrupt
}
}
}

void DMA_IRQHandler(void)
{
/* Check DMA interrupts of UART 0 RX channel */
if ((errors | pending) & (1 << DMAREQ_USART0_RX)) {
/* Clear DMA interrupt for the channel */
Chip_DMA_ClearActiveIntAChannel(LPC_DMA, DMAREQ_USART0_RX);

/* Handle errors if needed */
if (errors & (1 << DMAREQ_USART0_RX)) {
/* DMA error, channel needs to be reset */
dmaClearChannel(DMAREQ_USART0_RX);
dmaRXSetup0();
dmaRXQueue0();
}
else {
uartRxAvail0 = true;
}
}

}


Recv_function(void)
{
int bytes;
uint8_t buff[UARTRXBUFFSIZE1];
bytes = checkRxData1(buff);//Recv expected buffer size

//Ques: Does this buffer contain first byte as address received in UART1_Handler?

//Re-enable UART RXRDY Interrupt for addr detection
Chip_UART_IntEnable(LPC_USART1, UART_INTEN_RXRDY);
}

Outcomes