cancel
Showing results for 
Search instead for 
Did you mean: 

Problem on USART

lorenzo meneghello
Associate II
Posted on March 05, 2017 at 19:53

Hi, 

I'm working on STM32F091 MCU fora the first time and I'm trying to test the USART1 on PF0,1. I have just wrote the code and it works well, but now I can't receive the RXNE interrupt.. the tx line works normally.. if I try to set the port as an input I see the correct logic level on pin so the port works, it seems that the shift register of USART NOT WORK. Any idea?

Thanks.

lorenzo.

20 REPLIES 20
Posted on March 08, 2017 at 16:43

USART1->BRR = 0x1388; // set baudrate 9600BAUD 48Mhz/9600baud= 5000(0x1388)

Posted on March 08, 2017 at 17:07

Ok, my bad

have you tried just looping back the RX and TX? Is this a board of your own construction?

/* USART1 Echo-Loop PA.9 Tx, PA.10 Rx STM32F0-Discovery mailto:sourcer32@gmail.com */
#include 'stm32f0xx.h'
int main(void)
{
 uint16_t ch;
 USART_InitTypeDef USART_InitStructure;
 GPIO_InitTypeDef GPIO_InitStructure;
 RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
 RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1,ENABLE);
 GPIO_PinAFConfig(GPIOA, GPIO_PinSource9, GPIO_AF_1);
 GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_1);
 /* Configure USART1 pins: Rx and Tx ----------------------------*/
 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10;
 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
 GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
 GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
 GPIO_Init(GPIOA, &GPIO_InitStructure);
 USART_InitStructure.USART_BaudRate = 9600;
 USART_InitStructure.USART_WordLength = USART_WordLength_8b;
 USART_InitStructure.USART_StopBits = USART_StopBits_1;
 USART_InitStructure.USART_Parity = USART_Parity_No;
 USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
 USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
 USART_Init(USART1, &USART_InitStructure);
 USART_Cmd(USART1,ENABLE);
 ch = 0x49; // 'I'
 while(1)
 {
 if (USART_GetFlagStatus(USART1, USART_FLAG_TXE) != RESET) // Check for Empty
 USART_SendData(USART1, ch); // Send Character
 if (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET) // Check for Full
 ch = USART_ReceiveData(USART1); // Receive Character
 }
}
#ifdef USE_FULL_ASSERT
/**
 * @brief Reports the name of the source file and the source line number
 * where the assert_param error has occurred.
 * @param file: pointer to the source file name
 * @param line: assert_param error line source number
 * @retval None
 */
void assert_failed(uint8_t* file, uint32_t line)
{
 /* User can add his own implementation to report the file name and line number,
 ex: printf('Wrong parameters value: file %s on line %d

', file, line) */
 /* Infinite loop */
 while (1)
 {
 }
}
#endif
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 09, 2017 at 11:49

I dont look enable clock for GPIOA

Posted on March 09, 2017 at 12:34

Already set in a previous file

lorenzo meneghello
Associate II
Posted on March 14, 2017 at 12:00

Any other idea? Thanks.

Posted on March 14, 2017 at 13:27

Not really much to work with here, kind of hard to debug through the keyhole.

Perhaps present some diagnostic/analysis you've done, like plots from a scope or logic analyzer. Schematic for the circuit.

Perhaps you have a colleague who can review things with you or try other known working code/hardware.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
lorenzo meneghello
Associate II
Posted on March 22, 2017 at 17:05

Hi all,

2 weeks that I'm trying to comunicate with this UART.. Now I've a new news! If found that if I disable the TE bit I can receive from the PC... Any idea?

Thanks.

Posted on March 23, 2017 at 01:26

Perhaps there is some language difficultly here, I've asked for specific things, I've provided some example code, and you're still playing this 'guess what's wrong game'.

Present the problem so someone on the other side of the Atlantic can review the code and hardware you are working with. If you spend 20-30 mins doing this you might be able to see the problem for yourself.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 23, 2017 at 09:55

Ok I've create a folder with the code and schematic.

Thanks!

________________

Attachments :

USART problem.zip : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HylC&d=%2Fa%2F0X0000000bCA%2FEi_wXIZsxzlAfBshclBi0AQIvCRpYQKln1WXD8PgDEU&asPdf=false
lorenzo meneghello
Associate II
Posted on March 24, 2017 at 15:46

Ok don't know why but the solution is to use the another USART.... I've used the USART3 and now it works perfectly! setted on the same manner.