cancel
Showing results for 
Search instead for 
Did you mean: 

Hello everyone, I am using stm32f207zg with usb ttl converter with ftdi chip. I want use the usart1 for communication with PA9 e PA10 pins as TX and RX of usart1. I use as virtual terminal, termite, and when i play the program, appear weird characters.

FCa.1
Associate II

#define RCC_CFGR *((long*)0x40023808)

#define RCC_CR *((long*)0x40023800)

#define RCC_AHB1ENR *((long*)0x40023830)

#define GPIOC_ODR *((long*)0x40020814)

#define GPIOA_MODER *((long*)0x40020000)

#define GPIOA_OTYPER *((long*)0x40020004)

#define GPIOA_AFRL *((long*)0x40020020)

#define GPIOA_AFRH *((long*)0x40020024)

#define GPIOA_IDR *((long*)0x40020010)

#define RCC_APB1ENR *((long*)0x40023840)

#define RCC_APB2ENR *((long*)0x40023844)

#define USART1_BRR *((long*)0x40011008)

#define USART1_SR *((long*)0x40011000)

#define USART1_DR *((long*)0x40011004)

#define USART1_CR1 *((long*)0x4001100C)

#define USART1_CR2 *((long*)0x40011010)

//APB clock frequency=16MHz

//no APB prescaler

int main(void){

int k,i=1;

RCC_APB2ENR=RCC_APB2ENR|0x10; //USART1 enable

RCC_AHB1ENR=0x1;         //abilitazione clock GPIOA

RCC_CFGR=0x0;

RCC_CR=RCC_CR|0x1;

GPIOA_MODER=GPIOA_MODER|0x280000; //PA9(USART1 TX) e PA10(USART1 RX) in alternate function mode

GPIOA_AFRH=0x770; //PA9 e PA10 connected to USART1

USART1_BRR=USART1_BRR|0x8B; // fisso un baud rate pari a 115200 simb/s

//USART1_BRR=USART1_BRR|0x341;  // fisso un baud rate pari a 9600 simb/s

USART1_CR1=USART1_CR1|0x200C;

k=USART1_SR;

USART1_DR ='C';

while((USART1_SR&0x40)!=(0x40));

USART1_DR ='I';

while((USART1_SR&0x40)!=(0x40)); 

USART1_DR ='A';

while((USART1_SR&0x40)!=(0x40)); 

USART1_DR ='O';

while((USART1_SR&0x40)!=(0x40));  

}

11 REPLIES 11
Piranha
Chief II

Use predefined register and bit names. And this is how you send a single character:

while (!(USART1->SR & USART_SR_TXE));
USART1->DR = 'X';

Pavel A.
Evangelist III

>  I didn't understand this:GPIOA_AFRH=(GPIOA_AFRH & ~0xFF0) | 0x770; // PA9/PA10 AF7

What looks like a dash before 0xFF0 is a tilde ~0xFF0 <---- It is better seen in bold font.

A 'feature" of the brain dead salesforce forum.

-- pa