2012-05-14 02:54 PM
hi everybody,
i have to cinfigure an uart interface of my stm32l152 on STM32l-discovery or STM32-sk evaluation board. I have used to configure the uart peripheral interface the example in the stm32 library called HyperTerminal_Interrupt. The uart peripheral configuration consist of these code lines:USART_InitStructure.USART_BaudRate = 9600;
USART_InitStructure.USART_WordLength = USART_WordLength_8b; USART_InitStructure.USART_StopBits = USART_StopBits_2; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;STM_EVAL_COMInit(COMX, &USART_InitStructure);
The STM_EVAL_COMInit is a function defined in the stm32l152d_eval.h or stm32l152_eval.h file. Than I have modified the main to transmit continuousily the 0xAA byte with a pooling of the TC flag. The source code that I have included in the main file after at the uart configuration consist of: while(1) { USART_SendData(USART3, 0xAA); while(USART_GetFlagStatus(USART3, USART_FLAG_TC) == RESET) { USART_GetFlagStatus(USART3, USART_FLAG_TXE); } } I don't see any data transmission on the tx pin of the uart peripheral. Also, I don't find any change in the Uart Data Register (in the register tab of the IAR EWARM). Can sameone help me to configure the uart on the stm32l152?...I can use the STM32l-discovery or the STM32-SK evaluation board to test it. Best Regards Valerio Giamp� #usart1 #uart1 #stm32l152-uart-configuration2012-05-14 05:09 PM
No doubt because the routine you are using, at least of V1.1.1, enables the clocks on the wrong APB.
Something like this should be workable.// sourcer32@gmail.com - STM32L15x USART3 Demo
#include ''stm32l1xx.h'' main() { /* Enable GPIO clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOC, ENABLE); /* Enable USART3 clock */ RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART3, ENABLE); /* Configure USART Rx & Tx as alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOC, &GPIO_InitStructure); /* Mux out USART3 Rx & Tx */ GPIO_PinAFConfig(GPIOC, GPIO_PinSource10, GPIO_AF_USART3); GPIO_PinAFConfig(GPIOC, GPIO_PinSource11, GPIO_AF_USART3); USART_InitStructure.USART_BaudRate = 9600; USART_InitStructure.USART_WordLength = USART_WordLength_9b; USART_InitStructure.USART_StopBits = USART_StopBits_2; USART_InitStructure.USART_Parity = USART_Parity_Odd; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx; /* USART configuration */ USART_Init(USART3, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART3, ENABLE); while(1) { while(USART_GetFlagStatus(USART3, USART_FLAG_TXE) == RESET); /* Waitwhile TX full */ USART_SendData(USART3, 0xAA); } }2013-05-02 10:44 AM
2013-05-02 11:10 AM
Quick blind mod for USART2 PA2/PA3
// sourcer32@gmail.com - STM32L15x USART2 Demo 9600 8N1
#include ''stm32l1xx.h''
void main(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
USART_InitTypeDef USART_InitStructure;
/* Assumes CMSIS and SystemInit() set up clocks before calling main() */
/* Enable GPIO A clock */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOA, ENABLE);
/* Enable USART2 clock */
RCC_APB1PeriphClockCmd(RCC_APB1Periph_USART2, ENABLE);
/* Configure USART Rx & Tx as alternate function */
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(GPIOA, &GPIO_InitStructure);
/* Mux out USART2 Rx & Tx */
GPIO_PinAFConfig(GPIOA, GPIO_PinSource2, GPIO_AF_USART2); // PA2 USART2_TX
GPIO_PinAFConfig(GPIOA, GPIO_PinSource3, GPIO_AF_USART2); // PA3 USART2_RX
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_None;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Rx | USART_Mode_Tx;
/* USART configuration */
USART_Init(USART2, &USART_InitStructure);
/* Enable USART */
USART_Cmd(USART2, ENABLE);
while(1)
{
while(USART_GetFlagStatus(USART2, USART_FLAG_TXE) == RESET); /* Waitwhile TX full */
USART_SendData(USART2, 0xAA);
}
}
2014-02-25 06:38 AM
Hi again clive^^
Iam asking u for the same think, but for usart1. Im on the stm32L152. I want to use usart1. Their is my code. Nothing happened on PB6. What i did : void USART_Configure_GPIO() { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef* USART_InitStruct; /* Enable APB2 peripheral clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* Enable GPIOB clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); /* USART1 : TX->PB6,PA9 USART2 : TX->PA2 USART3 : TX->PB10,PC10 RX->PB7,PA10 RX->PA3 RX->PB11,PC11 */ /* Configure GPIO port 6 pins TX USART1*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; //NOPULL/DOWN/UP GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; //PP/OD GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Connect the pin to the desired peripherals' Alternate Function*/ GPIO_PinAFConfig(GPIOB, GPIO_PinSource6,GPIO_AF_USART1) ; //TX /* USART_InitStruct members default value */ USART_InitStruct->USART_BaudRate = 9600; USART_InitStruct->USART_WordLength = USART_WordLength_8b; USART_InitStruct->USART_StopBits = USART_StopBits_1; USART_InitStruct->USART_Parity = USART_Parity_No ; USART_InitStruct->USART_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStruct->USART_HardwareFlowControl = USART_HardwareFlowControl_None; USART_Init(USART1, USART_InitStruct); // finally this enables the complete USART1 peripheral USART_Cmd(USART1, ENABLE); /* Disable GPIOs clock */ // RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, DISABLE); // RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, DISABLE); } and in my main : .... .... /* Initializes the GPIO for USART1*/ USART_Configure_GPIO(); /* Disable SysTick IRQ and SysTick Timer */ SysTick->CTRL &= ~ ( SysTick_CTRL_TICKINT_Msk | SysTick_CTRL_ENABLE_Msk ); /* Configure Wakeup from sleep using RTC event*/ configureWakeup(); LCD_GLASS_Clear(); LCD_GLASS_DisplayString( (unsigned char *) ''ok'' ); while(1){ USART_SendData(USART1, 'T'); }2014-02-25 07:22 AM
Hi Mr Clive,
I fixed the problem, but i didnt find what was wrong!! If u can helpme to know what was the probleme, it will be very nice! Because i made a copy/paste and just change the parameter for usart1. But i would like to knwo what i made wrong in my first code! Thank you for ure help! Have a good afternoon. My code: void USART1_Configure() { GPIO_InitTypeDef GPIO_InitStructure; USART_InitTypeDef USART_InitStructure; /* Enable GPIO B clock */ RCC_AHBPeriphClockCmd(RCC_AHBPeriph_GPIOB, ENABLE); /* Enable USART1 clock */ RCC_APB2PeriphClockCmd(RCC_APB2Periph_USART1, ENABLE); /* Configure USART Rx & Tx as alternate function */ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 | GPIO_Pin_7; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_40MHz; GPIO_InitStructure.GPIO_OType = GPIO_OType_PP; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP; GPIO_Init(GPIOB, &GPIO_InitStructure); /* Connect the pin to the desired peripherals' Alternate Function*/ GPIO_PinAFConfig(GPIOB, GPIO_PinSource6,GPIO_AF_USART1) ; //TX /* Mux out USART1 Rx (PB7) & Tx (PB6) */ GPIO_PinAFConfig(GPIOB, GPIO_PinSource6, GPIO_AF_USART1); GPIO_PinAFConfig(GPIOB, GPIO_PinSource7, GPIO_AF_USART1); /* USART_InitStruct members default value */ 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_Mode = USART_Mode_Rx | USART_Mode_Tx; USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None; /* USART configuration */ USART_Init(USART1, &USART_InitStructure); /* Enable USART */ USART_Cmd(USART1, ENABLE); }2014-02-25 07:33 AM
Jamming out data with USART_SendData() misses the point that TXE needs to be asserted to indicate it's ready to accept data.
2014-02-25 08:26 AM
Ok!! Thank you for youre fast response!
Have a good end day. And thank you again for the time you waste with my stupid miss!2016-03-01 01:41 AM
2016-03-01 02:40 AM
The GPIO clocks are on APB2 and if you remap pins you must enable the AFIO clock.