Question
USART Problem with nucleo L152
Posted on November 07, 2014 at 12:41
Hello!
I'vegot an issue with using USART on Nucleo L152LE and need some help. Symptoms are: RX and TX pins are hardware connected, but reading from input register with USART_ReceiveData(USART1) returns zero instead of transmitted value. IDE is Atolic Lite with project settings coresponding to used board. I've tried both USART1 (PIO A, pins 9 and 10) and USART2 (PIO A, PINS 2 and 3) with the same result.Here is initialization code for USART1: /* USART configuration structure for USART1 */ USART_InitTypeDef USART1_init_struct; /* Bit configuration structure for GPIOA PIN9 and PIN10 */ GPIO_InitTypeDef gpioa_init_struct; USART_ClockInitTypeDef USART_ClockInitStructure; USART_ClockStructInit(&USART_ClockInitStructure); USART_ClockInit(USART1, &USART_ClockInitStructure); /* Enable clock for USART1, AFIO and GPIOA */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* GPIOA PIN9 alternative function Tx */ gpioa_init_struct.GPIO_Pin = GPIO_Pin_9; gpioa_init_struct.GPIO_Speed = GPIO_Speed_40MHz; gpioa_init_struct.GPIO_Mode = GPIO_Mode_AF; gpioa_init_struct.GPIO_OType = GPIO_OType_PP; gpioa_init_struct.GPIO_PuPd=GPIO_PuPd_DOWN; GPIO_Init(GPIOA, &gpioa_init_struct); /* GPIOA PIN10 alternative function Rx */ gpioa_init_struct.GPIO_Pin = GPIO_Pin_10; gpioa_init_struct.GPIO_Speed = GPIO_Speed_40MHz; gpioa_init_struct.GPIO_Mode = GPIO_Mode_IN; gpioa_init_struct.GPIO_PuPd=GPIO_PuPd_DOWN; gpioa_init_struct.GPIO_OType = GPIO_OType_PP; GPIO_Init(GPIOA, &gpioa_init_struct); GPIO_PinAFConfig(GPIOA, GPIO_PinSource9|GPIO_PinSource10, GPIO_AF_USART1); /* Baud rate 9600, 8-bit data, One stop bit * No parity, Do both Rx and Tx, No HW flow control */ USART1_init_struct.USART_BaudRate = 9600; USART1_init_struct.USART_WordLength = USART_WordLength_8b; USART1_init_struct.USART_StopBits = USART_StopBits_1; USART1_init_struct.USART_Parity = USART_Parity_No ; USART1_init_struct.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART1_init_struct.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /* Configure USART1 */ USART_Init(USART1, &USART1_init_struct); /* Enable USART1 */ USART_Cmd(USART1, ENABLE); /* Enable RXNE interrupt */// USART_ITConfig(USART1, USART_IT_RXNE, ENABLE);/* NVIC_EnableIRQ(USART1_IRQn);*/ }And transmittion code:int UartWriteWithEcho(unsigned char *pBuf,unsigned DataLen){ unsigned cnt; uint16_t RetVal; for(cnt=0; cnt<DataLen; cnt++) { USART_SendData(USART1, pBuf[cnt]); while (USART_GetFlagStatus(USART1, USART_FLAG_TC) == RESET) { //Do nothing. Just wait } RetVal=USART_ReceiveData(USART1); if( (unsigned char)RetVal!= pBuf[cnt]) //Checking echo is correct return 0; } return 1;}Would anyone be so kind to point me what is wrong? #nucleo-stm32l152-uart-txe #nucleo-stm32le-usart-problem