Noch ein STM32F303 USART3 geht nicht

OP #4588048
Servus,

Im Forum gibt's ja schon ein paar "Mein USART geht nicht"-Posts - leider 
hat mir keiner geholfen. In denen, die ich gefunden habe lag's z.B. am 
fehlenden RCC_APB2Periph_AFIO oder falsch eingestellten alternate 
functions GPIO_Mode_AF_PP. Beides kennt meine Version der st-lib nicht. 
Ich finde meinen Fehler einfach nicht. Eigendlich sollte PB10 wackeln, 
tut er aber nicht:
1
  INTERRUPTS_OFF();
2

3
  //Define all of the periphals we use.
4
  uint32_t apb1Peripherals = ( RCC_APB1Periph_PWR  |
5
                               RCC_APB1Periph_USART3
6
                                 );
7
  uint32_t apb2Peripherals = ( 0 );
8
  uint32_t ahbPeripherals = ( RCC_AHBPeriph_GPIOA |
9
                              RCC_AHBPeriph_GPIOB |
10
                              RCC_AHBPeriph_GPIOC);
11

12
  //Enable clocks to all of our peripherals.
13
  RCC_APB1PeriphClockCmd(apb1Peripherals, ENABLE);
14
  RCC_APB2PeriphClockCmd(apb2Peripherals, ENABLE);
15
  RCC_AHBPeriphClockCmd(ahbPeripherals, ENABLE );
16

17
  //Allow access to BKP Domain
18
  PWR_BackupAccessCmd(ENABLE);
19

20
  //De-initialize our peripherals here so each module only has to
21
  //worry about initializing them as needed.  DeInit works by toggling
22
  //PeriphResetCmd enable/disable.
23
  EXTI_DeInit();
24

25
  GPIO_DeInit(GPIOA);
26
  GPIO_DeInit(GPIOB);
27
  GPIO_DeInit(GPIOC);
28
  GPIO_DeInit(GPIOD);
29

30
  USART_DeInit(USART3);
31

32
  //Configure USART TX GPIO as alternate function push-pull
33
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
34
  GPIO_InitStructure.GPIO_Pin =  GPIO_Pin_10;
35
  GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
36
  GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
37
  GPIO_Init(GPIOB, &GPIO_InitStructure);
38
  GPIO_PinAFConfig(GPIOB, GPIO_Pin_10, GPIO_AF_7);
39

40
  //Configure USART RX GPIO as input floating
41
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
42
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
43
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
44
  GPIO_Init(GPIOB, &GPIO_InitStructure);
45
  GPIO_PinAFConfig(GPIOB, GPIO_Pin_11, GPIO_AF_7);
46

47
  //Configure USART (but without enabling it)
48
  USART_InitStructure.USART_BaudRate = 9600;
49
  USART_InitStructure.USART_WordLength = USART_WordLength_8b;
50
  USART_InitStructure.USART_Parity = USART_Parity_No;
51
  USART_InitStructure.USART_StopBits = USART_StopBits_1;
52
  USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
53
  USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
54
  USART_Init(USART3, &USART_InitStructure);
55

56
  USART_Cmd(USART3, ENABLE);
57

58
  INTERRUPTS_ON();  // Safe to enable interrupts at this point
59

60
  while( true )
61
  {
62
      while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
63
      USART_SendData(USART3, 0xAA);
64
      while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET);
65
      USART_SendData(USART3, 0x55);
66
  }

Könnt Ihr mir bitte von der Leitung helfen auf der ich stehe?
Danke :)
OP
Egal ob das Scherz oder Hilfe ist, beides verstehe ich nicht :(

Zeile 42 wäre:
1
  //Configure USART RX GPIO as input floating
2
  GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
3
  GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;       // 42
4
  GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
5
  GPIO_Init(GPIOB, &GPIO_InitStructure);
6
  GPIO_PinAFConfig(GPIOB, GPIO_Pin_11, GPIO_AF_7);

Da wird RxD auf PB11 konfiguriert - es kommt aber bei TxD nix raus...

(Die Anspielung auf THGTTG verstünde ich wohl, wäre nur nicht 
hilfreich.)
(Firma: matzetronics)
Ich muss sagen, das ich mit den F3 nix mache, sondern nur mit den F4. Da 
sieht meine Senderoutine so aus:
1
#define USART USART3
2
void uart_put(char data){
3
 while (USART_GetFlagStatus(USART, USART_FLAG_TC) == RESET) {};
4
 USART_SendData(USART, (uint8_t) data);
5
}

Ist
1
GPIO_PinAFConfig(GPIOB, GPIO_Pin_11, GPIO_AF_7);
 über jeden Verdacht erhaben? Also ist die AF7 Schiene auch wirklich die 
richtige für USART3 und ist GPIO_Pin_11 auch wirklich die Source? Bei 
mir heissen die Dinger z.B. 'GPIO_PinSource2'?
Ich poste (nur zum Vegleichen) einfach meine USART Init:
1
// aus setup.h
2
/* USART Definitions */
3
#define USART_TX_PIN       GPIO_Pin_2
4
#define USART_RX_PIN      GPIO_Pin_3
5
#define USART_TX_SOURCE      GPIO_PinSource2
6
#define USART_RX_SOURCE      GPIO_PinSource3
7
#define USART          USART2
8
#define USART_PORT        GPIOA
9
// aus main.c
10

11
void USARTInit(uint32_t baudrate) {
12
GPIO_InitTypeDef GPIO_InitStructure;
13
USART_InitTypeDef USART_InitStructure;
14
// Clock Enable of usart pins
15
RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOA, ENABLE);
16
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
17
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, ENABLE);
18
RCC_APB1PeriphResetCmd(RCC_APB1Periph_USART2, DISABLE);
19
GPIO_PinAFConfig(USART_PORT, USART_RX_SOURCE, GPIO_AF_USART2);
20
GPIO_PinAFConfig(USART_PORT, USART_TX_SOURCE, GPIO_AF_USART2);
21

22
GPIO_InitStructure.GPIO_Pin = USART_TX_PIN;
23
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
24
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
25
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
26
GPIO_InitStructure.GPIO_PuPd  = GPIO_PuPd_NOPULL;
27
GPIO_Init(USART_PORT, &GPIO_InitStructure);
28
GPIO_InitStructure.GPIO_Pin =  USART_RX_PIN; 
29
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
30
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
31
GPIO_InitStructure.GPIO_OType = GPIO_OType_OD;
32
GPIO_Init(USART_PORT, &GPIO_InitStructure);
33
/* Configure USART)
34
 *
35
 */
36
USART_DeInit(USART);
37
USART_StructInit(&USART_InitStructure);
38
USART_InitStructure.USART_BaudRate = baudrate;
39
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
40
USART_InitStructure.USART_StopBits = USART_StopBits_1;
41
USART_InitStructure.USART_Parity = USART_Parity_No;
42
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
43
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
44
USART_Init(USART,&USART_InitStructure);
45
/* Enable USART */
46
USART_Cmd(USART, ENABLE);
47

48
}
Den Formalkrams mache ich nur, damit ich das schnell mal auf andere Pins 
umbiegen kann.

Antwort schreiben

Eine eigene Frage? Dieser Thread ist über 10 Jahre alt. Stell sie in einem eigenen Thread – dort lesen mehr Leute mit, und sie wird öfter und schneller beantwortet.

Neuen Thread starten

Eine Lösung, Ergänzung oder Rückmeldung zu diesem Thread? Dann antworte hier.

Formatierung
  • [c]C-Code[/c]
  • [code]Code in anderen Sprachen, ASCII-Zeichnungen[/code]
  • [math]Formel in LaTeX-Syntax[/math]
  • [[Titel]] – Link zu einem Artikel
  • Verweis auf einen anderen Beitrag: Rechtsklick auf dessen Beitrags-ID (#8078628), „Adresse kopieren“, in den Text einfügen

Mehr zur Formatierung

Längeren Sourcecode als Anhang, nicht in den Text. JPG nur für Fotos und Scans; Zeichnungen und Screenshots als PNG oder GIF. Siehe Bildformate.

Schon registriert? Anmelden

Wird nicht angezeigt. Wir schicken dir einen Link; sobald du damit bestätigst, erscheint dein Beitrag.

Mit dem Abschicken legst du einen kostenlosen Account an und erkennst die Nutzungsbedingungen und die Datenschutzerklärung an.