stm32F3 Uart

OP #3298670
Lesenswert?

Hallo,
Ich habe ein Problem mit der Initialisierung einer Uart-Kommunikation 
auf dem STM32F3 Board. Ich möchte eine Uart-Kommunikation einrichten um 
mit meinen Pc zu Kommunizieren jedoch möchte ich nicht die std-libraries 
verwenden sondern auf Register Niveau arbeiten, aber es funktioniert 
noch nicht ganz hat jemand eine Ahnung ?
1
#include "stm32f30x.h"
2

3
void USART_PutChar(uint8_t ch)
4
{
5
  while(!(USART1->ISR & USART_ISR_TXE));
6
  USART1->TDR = ch;
7
}
8

9

10
int main(void)
11
{       USART1->CR1 &= ~USART_CR1_UE;
12
  RCC->APB2RSTR |= RCC_APB2RSTR_USART1RST;
13
  RCC->APB2RSTR &= (~RCC_APB2RSTR_USART1RST);
14
  RCC->AHBENR |= RCC_AHBENR_GPIOAEN;
15
  RCC->APB2ENR |= RCC_APB2ENR_USART1EN;
16
  RCC->CFGR3 |= RCC_CFGR3_USART1SW_0;
17
  RCC->CFGR3 &= ~RCC_CFGR3_USART1SW_1;
18

19

20

21

22
  GPIOA->MODER |=GPIO_MODER_MODER9_1|GPIO_MODER_MODER10_1 ;
23
       //p9(TX)&p10(RX) Alternative function mode
24
  GPIOA->MODER &=~GPIO_MODER_MODER9_0&~GPIO_MODER_MODER10_0 ;
25

26
  USART_RX_GPIO->OSPEEDR |=   GPIO_OSPEEDER_OSPEEDR9_0|GPIO_OSPEEDER_OSPEEDR9_1|
27
                       GPIO_OSPEEDER_OSPEEDR10_0|GPIO_OSPEEDER_OSPEEDR10_1;
28
  
29
  GPIOA->AFRH |= GPIO_AFRH_AFRH2_0|GPIO_AFRH_AFRH2_1|GPIO_AFRH_AFRH2_2|
30
           GPIO_AFRH_AFRH3_0|GPIO_AFRH_AFRH3_1|GPIO_AFRH_AFRH3_2;
31
  
32
  GPIOA->AFRH &= ~GPIO_AFRH_AFRH2_3&~GPIO_AFRH_AFRH3_3;
33

34

35
  USART1->CR1 &= ~USART_CR1_M  ;
36
  USART1->BRR = (SystemCoreClock / 9600);
37
  USART1->CR2&= ~USART_CR2_STOP_0&~USART_CR2_STOP_1;
38
  USART1->CR1 |=  USART_CR1_UE;
39
  USART1->CR1 |=  USART_CR1_TE |USART_CR1_RE ;
40
  
41
  while (1)
42
  {
43
    USART_PutChar('a');
44
    for(dly = 0; dly < 1000000; dly++);
45

46
  }
47
  
48

49
  return 0;
50
}
Gast #3298705
Lesenswert?

Nimm den Beispielcode von ST mit Standard Periphal Library, und ersetze 
ihn nach und nach durch die direkten Register-Zugriffe. Wenn es an einer 
Stelle nicht mehr funktioniert weißt du warum.

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren