Forum: Mikrocontroller und Digitale Elektronik STM32F207: USART + DMA


von leon (Gast)


Angehängte Dateien:

Lesenswert?

Hallo ich bin seit einigen Stunden damit beschäftigt, den USART3 mit DMA 
für den Empfang von Daten einzurichten. Leider gelingt es mir nicht. Der 
Interrupt Handler DMA1_Stream1_IRQHandler wird nicht angesprungen. Woran 
könnte hier das Problem liegen.

Für jede Hilfe bedanke ich mich schonmal im Vorfeld.

von leon (Gast)


Lesenswert?

Es müsste doch möglich sein, Daten von der RS232 an den stm32 über den 
DMA zu empfangen. Es gelingt mir einfach nicht.

von 6A66 (Gast)


Lesenswert?

leon schrieb:
> Es müsste doch möglich sein, Daten von der RS232 an den stm32 über den
> DMA zu empfangen. Es gelingt mir einfach nicht.

Hallo leon,

prüfe im Debugger (Registersicht)
- ob die interrupt request bits kommen
- ob die DMA bits kommen
- ob die nötigen Interrupt enable bits gesetzt sind
...

rgds

von Richard (Gast)


Lesenswert?

wie schaut deine stm32...._IT.c config aus ?

von Moritz M. (Gast)


Lesenswert?

Hallo,

Wo werden den die GPIO´s eingestellt für UART (Alternative Function?)

Moritz

von Moritz M. (Gast)


Lesenswert?

Hallo nochmal,

ich hatte mal was einfaches programmiert für den F4er:
1
#include "stm32f4xx.h"
2
3
4
void USART3_Init(void);
5
void DMAStream3_Channel4_Init();
6
7
unsigned char buffer[129] = "Hello World, this is a DMA test. If you can read this the DMA is still working!\n";
8
9
int main(void)
10
{
11
  USART3_Init();
12
  DMAStream3_Channel4_Init();
13
  USART_DMACmd(USART3, USART_DMAReq_Tx, ENABLE);
14
  DMA_Cmd(DMA1_Stream3, ENABLE);
15
  while(1);
16
}
17
18
void USART3_Init(void)
19
{
20
  GPIO_InitTypeDef GPIOC_10_11_InitStructure;
21
  USART_InitTypeDef USART3_InitStructure;
22
23
  //GPIO C 10/11 Init
24
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOC, ENABLE);
25
26
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3);
27
  GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3);
28
29
  GPIOC_10_11_InitStructure.GPIO_Mode = GPIO_Mode_AF;
30
  GPIOC_10_11_InitStructure.GPIO_OType = GPIO_OType_PP;
31
  GPIOC_10_11_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
32
  GPIOC_10_11_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
33
  GPIOC_10_11_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
34
35
  GPIO_Init(GPIOC, &GPIOC_10_11_InitStructure);
36
37
  //USART 3 Init
38
  RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE);
39
40
  USART3_InitStructure.USART_BaudRate = 9600;
41
  USART3_InitStructure.USART_WordLength = USART_WordLength_8b;
42
  USART3_InitStructure.USART_StopBits = USART_StopBits_1;
43
  USART3_InitStructure.USART_Parity = USART_Parity_No;
44
  USART3_InitStructure.USART_HardwareFlowControl =
45
USART_HardwareFlowControl_None;
46
  USART3_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
47
48
  USART_Init(USART3, &USART3_InitStructure);
49
  USART_Cmd(USART3, ENABLE);
50
}
51
void DMAStream3_Channel4_Init(void)
52
{
53
  RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA1, ENABLE);
54
55
  DMA_InitTypeDef DMA_InitStruct;
56
  DMA_StructInit(&DMA_InitStruct);
57
  DMA_InitStruct.DMA_Channel = DMA_Channel_4;
58
  DMA_InitStruct.DMA_PeripheralBaseAddr = (uint32_t)&(USART3->DR);
59
  DMA_InitStruct.DMA_Memory0BaseAddr = (uint32_t)&buffer;
60
  DMA_InitStruct.DMA_DIR = DMA_DIR_MemoryToPeripheral;
61
  DMA_InitStruct.DMA_BufferSize = 129;
62
  DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
63
  DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
64
  DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
65
  DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
66
  DMA_InitStruct.DMA_Mode = DMA_Mode_Circular;
67
  DMA_InitStruct.DMA_Priority = DMA_Priority_Medium;
68
  DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Disable;
69
  DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull;
70
  DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single;
71
  DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
72
  DMA_Init(DMA1_Stream3, &DMA_InitStruct);
73
}

Sendet aber einfach nur ein String.
Vllt. Hilft es dir ein bisschen weiter.

Moritz M.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.