You can read more about general DMA write-up here.
In my previous blog, i implemented PIC32 UART transmission using ring buffer and TXIF interrupt. Drawback of this approach is UART transmission still uses some processing time to transmit the data which is in the buffer.
To overcome this we can use DMA controller of PIC32 which will take care of the data transmission over UART without disturbing the CPU.
PIC32 DMA Block:
PIC32 DMA Block |
PIC32MX795F512L has
- 8 dedicated DMA channels for USB OTG, Ethernet, and CAN.
- 8 Channel General Hardware DMA Controller.
How DMA Works?
PIC32 DMA Source to Destination Transfer Diagram |
DMA controller to work needs source address where data is parked waiting to be transmitted and destination address to where data to be transmitted. In this case, vUARTMTXFIFO is source location where data is parked and TXREG of UART module is the destination.
UART is byte level serial protocol, i.e. it transmits one byte data serially at any given point of time. However, source buffer vUARTMTXFIFO is of 750 bytes in length.
So, we will use TXIF interrupt of the UART module to trigger the DMA controller on one byte data is transmitted. When UART module generates this interrupt, DMA will increase its source address pointer and will copy the next byte to TXREG. This will continue till all the bytes are transmitted.
All the above process of transmitting data using DMA occurs without interrupting CPU. Once all the data is transmitted, DMA will generate interrupt to indicate CPU that it has finished its job.
Download the source code here.