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
FCa.1
Associate II

the weird character is this: ÿ. I use a baud rate of 115200.

Most registers are unsigned long, or uint32_t, not "long"

UART1_DR is 16-bit wide not 32

GPIOA_AFRH=(GPIOA_AFRH & ~0xFF0) | 0x770; // PA9/PA10 AF7

USART1_BRR = 0x8A; // 115200, write required divider, not OR on bits

Front check for TXE

Outputs are 3V CMOS levels, not RS232 ones

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
FCa.1
Associate II

Hi, thanks for your answer. I didn't use the OR, but there is the weird character. I didn't understand this:GPIOA_AFRH=(GPIOA_AFRH & ~0xFF0) | 0x770; // PA9/PA10 AF7

I used int for registers but nothing...WIthout the adapter the circuit cannot works...

Read out and check the USART registers content.

Observe the Tx pin using oscilloscope/logic analyzer.

JW

OK, but i haven't oscilloscope or logic analyzer....​

S.Ma
Principal

If you don't have debug tools, then start from a nucleo USART proven example. Might require less effort than doing wild guesses on something that can't be mastered.

FCa.1
Associate II

ok, but this is a very uart example.......i am sending a single character. I can use the keil debug

Start using standard library examples rather than your hacky register level implementation, people here have better things to do than unpack every line here.

If more standard approaches work on the hardware you can then focus on why your approach is failing, and if not look at hardware issues related to connectivity or voltage levels, expectations, etc.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Hi, if "people here have better things to do than unpack every line here" as you said simply do not answer me or other people. If someone has problems / doubts it is because he has reached a point where he no longer knows which solution to adopt and I have not written here just out of curiosity or to disturb those who have other things to do. Goodbye.

If you make suggestions and someone does not understand it is because perhaps you have not explained yourself simply.

Or that it is simpler to rewrite the code properly rather than match the naive coding style you have adopted. There are certainly plenty of "fix my broken code" type posts, when the real solution is to use existing examples that already work, or at the very least illustrate if the problem is on the SW or HW side. With something working, you can introspect about why your code isn't working, or why it is doing things differently.

With register level coding you've picked the most complex approach and have no method or test equipment. You've also not diagrammed your hardware, or indicated if it is a board others might have access too.

If you're going to take a unique and difficult approach, expect to do it on your own.

You've resisted several suggestions to take a different tack, or provide register level content, it makes you hard to help.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..