2014-09-28 07:12 AM
Hi friends,
I have nio clue why I can't send anu data to usart. I use a stm32 Nucleo F401 on the usart 2 and absolutly no signal on GPIOA Pin 2 and 3. If you could help me. Thanks a lotMy source code is very simple :
UART_HandleTypeDef UartHandle; void HAL_UART_MspInit(UART_HandleTypeDef *huart) { GPIO_InitTypeDef GPIO_InitStruct; __GPIOA_CLK_ENABLE(); __USART2_CLK_ENABLE(); GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); GPIO_InitStruct.Pin = GPIO_PIN_3; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_FAST; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); } void init_usart(void) { UartHandle.Instance = USART2; UartHandle.Init.BaudRate = 9600; UartHandle.Init.WordLength = UART_WORDLENGTH_8B; UartHandle.Init.StopBits = UART_STOPBITS_1; UartHandle.Init.Parity = UART_PARITY_NONE; UartHandle.Init.HwFlowCtl = UART_HWCONTROL_NONE; UartHandle.Init.Mode = UART_MODE_TX_RX; HAL_UART_Init(&UartHandle); __HAL_UART_ENABLE(&UartHandle); } int main(int argc, char* argv[]) { char str[5] = { ''tests'' }; init_usart(); HAL_UART_Transmit(&UartHandle, (uint8_t*) str, 1, 0XFFFF); HAL_UART_Transmit(&UartHandle, (uint8_t*) str, 1, 0XFFFF); while (1) { //HAL_UART_Transmit(&UartHandle, &ch, 1, 0XFFFF); } } #nucleo-f4012014-09-28 08:25 AM
Can't help you will HAL, this is how I did it with the Standard Peripheral Library.
[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/USART%20example%20code%20for%20Nucleo%20F401RE&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=353]https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=%2Fpublic%2FSTe2ecommunities%2Fmcu%2FLists%2FSTM32Discovery%2FUSART%20example%20code%20for%20Nucleo%20F401RE&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F¤tviews=3532014-09-28 08:52 AM
Thanks a lot for your help. It is quite the same in using HAL. Could you tell me what ''USART_Cmd'' does. I problably forget something to start USART.
Once again thanks2014-09-28 09:03 AM
Equivalent to __HAL_UART_ENABLE
2014-09-29 03:01 AM
Hi denis.lamard,
After analysing your code I've the following suggestions :PS: To have more insight into USART transmission please check the following example: \Projects\STM32F401RE-Nucleo\Examples\UART within the
package.Regards,Heisenberg.2014-09-29 06:43 AM
Thanks for those tips. I'll try as soon as possible. I'm beginning to understand how ADC works. I need to use it to capture data from a ultrasonic sensor.
Best regards2014-09-29 07:03 AM
It seems also that you've missed the call of the following functions under your main() function: