2018-10-03 01:58 AM
Hi,
I'm using the evaluation board STEVAL-IDS001V4M which has a STM32L152 mounted on.
I'm having some trouble on the initialization of the UART2 peripheral.
I'm using the ST library contained into the STSW-CONNECT009 packet.
To initialize the UART2, I'm doing the following steps:
>> RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA); //activate clock on peripheral
>> USART_StructInit(&USART_InitStruct); //initialize parameters (parity, stop bit, bauderate....)
>> USART_Init(USART2, &USART_InitStruct); //initialize USART2 parameters
>> USART_Cmd(USART2, ENABLE); //enable usart2
Then I use the following function to send multiple times a character 'A' to my PC.
void USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
{
/* Check the parameters */
assert_param(IS_USART_ALL_PERIPH(USARTx));
assert_param(IS_USART_DATA(Data));
/* Transmit Data */
USARTx->DR = (Data & (uint16_t)0x01FF);
}
But nothing arrives at my COM port!
What did I miss in the initialization?
Solved! Go to Solution.
2018-10-03 06:03 AM
Thank you all for the answers!
Unfortunately I'm working with the STM32L152C, and the library of the STM32CubeL1 are based on the STM32L152D, so i don't have the "HAL" based library which is used in the examples.
Still I managed to solve the problem.
Initialize the UART by:
>> USART_InitTypeDef USART_InitStruct; //see stm32l1xx_usart.h
>> USART_StructInit(&USART_InitStruct); //set parameters of USART2, see stm32l1xx_usart.c to modify the values
>> SdkEvalComInit(COM1, &USART_InitStruct);//initialize UART2, see SDK_EVAL_Com.c
Then to send a char use:
USART_SendData(USART_TypeDef* USARTx, uint16_t Data)
2018-10-03 02:21 AM
Hi @mikmary ,
I'd highly advise you to refer to UART examples under the STM32CubeL1 firmware package.
It's found under the path below:
STM32Cube_FW_L1_V1.8.1\Projects\STM32L152D_EVAL\Examples\UART
You may take the examples as a reference to correctly configure your peripheral.
Link to download the cube package:
Khouloud.
2018-10-03 03:00 AM
The SPL-based firmware libraries for the L152 MCU and the L152_discovery are still available for download. The contain UART examples, as far as I remember.
> But nothing arrives at my COM port!
Do you see anything at the TX pin of USART 2 ?
The way to the receiver COM port is long ...
2018-10-03 05:53 AM
So I don't have to pull the manuals, PA2 and PA3?
You will need to enable the clocks for the GPIOA and USART2
You will need to configure the pins to associate with USART2
Before you call SendData you must check that the status flags TXE to let you know the USART is ready for the next byte
2018-10-03 06:03 AM
Thank you all for the answers!
Unfortunately I'm working with the STM32L152C, and the library of the STM32CubeL1 are based on the STM32L152D, so i don't have the "HAL" based library which is used in the examples.
Still I managed to solve the problem.
Initialize the UART by:
>> USART_InitTypeDef USART_InitStruct; //see stm32l1xx_usart.h
>> USART_StructInit(&USART_InitStruct); //set parameters of USART2, see stm32l1xx_usart.c to modify the values
>> SdkEvalComInit(COM1, &USART_InitStruct);//initialize UART2, see SDK_EVAL_Com.c
Then to send a char use:
USART_SendData(USART_TypeDef* USARTx, uint16_t Data)