2017-03-05 10:53 AM
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.
2017-03-08 08:43 AM
USART1->BRR = 0x1388; // set baudrate 9600BAUD 48Mhz/9600baud= 5000(0x1388)
2017-03-08 09:07 AM
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
�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?
2017-03-09 03:49 AM
I dont look enable clock for GPIOA
2017-03-09 04:34 AM
Already set in a previous file
2017-03-14 04:00 AM
Any other idea? Thanks.
2017-03-14 06:27 AM
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.
2017-03-22 09:05 AM
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.
2017-03-22 06:26 PM
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.
2017-03-23 02:55 AM
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=false2017-03-24 07:46 AM
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.