Program:
DMA:
Direct Memory Access controller can transfer data between peripheral and memory or in between memories, allowing the CPU to be free to do other tasks and increase its efficiency.We will use DMA to get data from the memory instead of using for loop which would utilize CPU time, and transmit it over the UART.
Steps:
1. In reference manual, we can see that USART 1 is assigned channel 4 in DMA 1Enable the DMA 1 clock in RCC register and enable DMA in USART 1.
2. Configuration in DMA_CCR register:
- DIR: Direction of Transfer is from memory to peripheral register, in this case.
- CIRC: Circular mode is disabled - we are just just doing one time transfer
- PINC: We don't need to increment peripheral address, because the data from memory need
to be copied to the same register USART1 -> DR
- MINC: We need to increment the memory so as to transfer character by character from array, in our case
- PSIZE: Peripheral size (32 - bit register)
- MSIZE: Memory size (8 - bit data)
- PL: Channel priority level
Let's leave it at low as we are using only 1 channel
3. DMA_CNDTR register - No. of data to transfer
In our program, we are transferring 8 characters
4. DMA_CPAR - Peripheral register address
5. DMA_CMAR - Initial address of data to be transferred from or to memory
6. Enable the channel to start the DMA data transfer and then USART starts to transfer the data once data is written in the USART1 -> DR register.
For ADC in STM32, see this post
Comments
Post a Comment