2016-10-23 03:29 AM
Hello,
I have a problem with sending data from/to my STM32F103C8T6 using USART connection. I'm using USB2TTL PL2303 converter. I connected it to RX1 and TX1 on the board. I can send .hex files with STM Flash Loader Demonstrator and it works (like LED blink etc.). This is how it looks like:http://image.prntscr.com/image/0d03529e29c64d78b6c3fb08bbaf57f8.png
http://image.prntscr.com/image/0d03529e29c64d78b6c3fb08bbaf57f8.png
This is my code:
void
startUsart(){
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA,
ENABLE
);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,
ENABLE
);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO,
ENABLE
);
GPIO_InitTypeDef
GPIO_InitStructure;
GPIO_InitStructure.
GPIO_Pin
= GPIO_Pin_9;
GPIO_InitStructure.
GPIO_Mode
=
GPIO_Mode_AF_PP
;
GPIO_InitStructure.
GPIO_Speed
=
GPIO_Speed_50MHz
;
GPIO_Init(GPIOA, &GPIO_InitStructure);
GPIO_InitStructure.
GPIO_Pin
= GPIO_Pin_10;
GPIO_InitStructure.
GPIO_Mode
=
GPIO_Mode_IN_FLOATING
;
GPIO_Init(GPIOA, &GPIO_InitStructure);
USART_InitTypeDef
uart;
uart.
USART_BaudRate
= 115200;
uart.
USART_HardwareFlowControl
= USART_HardwareFlowControl_None;
uart.
USART_Mode
= USART_Mode_Rx | USART_Mode_Tx;
uart.
USART_Parity
= USART_Parity_No;
uart.
USART_StopBits
= USART_StopBits_1;
uart.
USART_WordLength
= USART_WordLength_8b;
USART_Init(USART1, &uart);
USART_Cmd(USART1,
ENABLE
);
}
void
send_char(
char
c)
{
while
(USART_GetFlagStatus(USART1, USART_FLAG_TXE) ==
RESET
);
USART_SendData(USART1, c);
}
int
main(
int
argc,
char
* argv[])
{
startUsart();
while
(1)
{
send_char(
'y'
);
timer_sleep(2000);
send_char(
'a'
);
timer_sleep(2000);
}
}
What I receive is:
http://image.prntscr.com/image/4c508ec85ff9476f99689ce8e1a5epng
I was looking for similar problem but couldn’t find any working solution.
I tried lower baudrate like 9600 but still not working.
stm32 usart stm32f1032016-10-23 06:00 AM
You'd need to review HSE_VALUE used for the project vs whatever crystal your board uses. You could try just using the HSI clock rather than the HSE/PLL
Suggest you output a U characters, and look at the TX signal on a scope to verify/understand the bit clock it is using.2016-10-23 08:57 AM
My HSE_VALUE = 8000000.
I generated code with STM32Cube for this task and it works (characters received from the board are correct). I can see that there is the same HSE_VALUE. I would prefer to have my own code rather than generated though but I'm note sure what to change in my project. Any tips?2016-10-23 10:53 AM
Code doesn't look unreasonable, not sure of the tool chain used or if SystemInit is called. I'd scope the pin and review the clocks.