Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[ARM] STM32 UART Rx with DMA

Status
Not open for further replies.

surendran_raj

Junior Member level 2
Joined
Aug 8, 2022
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
235
Hi,

I'm trying to set up UART communication with DMA using the STM32f103C8 controller.
I'm trying to receive data with DMA but I can't able to receive data continuously.

Can anyone correct me if I made a mistake?
I'm using STM32f103C8 registers to code.
  • communication :USART3
  • pins PB10-TX, PB11-RX
  • DMA channels - DMA1_channel1 for TX , DMA1_channel3 for RX

Thank you.


Code C++ - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include<stm32f10x.h>
uint8_t rx_data[13];
 
 
void USART3_config(void)
    {
        RCC->APB1ENR |= RCC_APB1ENR_USART3EN;
        RCC->AHBENR |= RCC_AHBENR_DMA1EN;
 
        USART3->BRR = 0x0EA6;  //for 9600 baurd rate
        USART3->CR1 |= USART_CR1_TE | USART_CR1_RXNEIE | USART_CR1_RE;
        USART3->CR3 |= USART_CR3_DMAT | USART_CR3_DMAR ;
        USART3->CR1 |= USART_CR1_UE;
        NVIC_EnableIRQ(USART3_IRQn);
    }
 
void USART_DMA_RX_init(void)
{
  RCC->AHBENR |= RCC_AHBENR_DMA1EN;
  DMA1_Channel3->CPAR = (uint32_t)&USART3->DR;
  DMA1_Channel3->CMAR = (uint32_t)rx_data;
  DMA1_Channel3->CNDTR = 20;
  DMA1_Channel3->CCR |= DMA_CCR3_MINC | DMA_CCR3_TCIE | DMA_CCR3_HTIE  ;
  DMA1_Channel3->CCR |= DMA_CCR3_EN;
  NVIC_EnableIRQ(DMA1_Channel3_IRQn);
}
 
int main(void)
{
  RCC->APB2ENR |= RCC_APB2ENR_IOPBEN | RCC_APB2ENR_AFIOEN;
  GPIOB->CRH = 0x00008B00;
  USART_DMA_RX_init();
  USART3_config();
 
 while(1)
 {
 
 }
}
 
void DMA1_Channel3_IRQHandler(void)
{
  if((DMA1->ISR & DMA_ISR_HTIF3) == DMA_ISR_HTIF3)
  {
    DMA1->IFCR = DMA_IFCR_CHTIF3;
  }
  else if((DMA1->ISR & DMA_ISR_TCIF3)== DMA_ISR_TCIF3)
  {
    DMA1->IFCR = DMA_IFCR_CGIF3 | DMA_IFCR_CTCIF3;
  }
}
void USART3_IRQHandler(void)
{
  if((USART3->SR & USART_SR_RXNE) == USART_SR_RXNE)
  {
    USART3->SR &= ~ USART_SR_RXNE;
  }
}

 
Last edited by a moderator:

Hello!
You could consider using CubeMX which generates everything you need.
Now a DMA has to be either "armed" manually or re-arm itself automatically,
and you get interrupts everytime you got a full of half buffer. All this is configurable
in CubeMX.
Dora.
 

Hello!
You could consider using CubeMX which generates everything you need.
Now a DMA has to be either "armed" manually or re-arm itself automatically,
and you get interrupts everytime you got a full of half buffer. All this is configurable
in CubeMX.

Thanks for your reply. I need to know about using registers.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top