I am working with STM32L152VD. After waking up from sleep and switching to 8Mhz. everything work properly (SPI,I2C,..) except UART. I configure it using following function:
void uart1_configuration(void) { 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_USART1); GPIO_PinAFConfig(GPIOA, GPIO_PinSource10, GPIO_AF_USART1); /* Configure USART2 pins: Rx and Tx ----------------------------*/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9 | GPIO_Pin_10; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz; 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); /* Enable RXNE interrupt */ USART_ITConfig(USART1, USART_IT_RXNE, ENABLE); /* Enable USART1 global interrupt */ NVIC_EnableIRQ(USART1_IRQn); }
It Seems UART is disabled.
I don't work with your processor but you write "and switching to 8Mhz."
How will the processor know the clock frequency used by the UART, so it knows how to compute the register values needing to fulfill this line?
USART_InitStructure.USART_BaudRate = 9600;
The UART is asynchronous, so baudrate errors means failure. SPI is synchronous so a change of master clock frequency will not be noticed unless you either overclock some device or the baudrate becomes too low to manage your required transfer needs. And a SPI slave doesn't need same internal clocking - just fast enough clocking so the internal state machine can keep up with the master SPI clock.
I have used SystemCoreClockSetHSI(); to switch to high frequency. I measured this frequency from timers operation and concluded that it is exactly 8MHz. how ever it is still a question for me why it is not 16Mhz? this may be the issue USART fails to work.
View all questions in Keil forum