779 views|1 replies

157

Posts

0

Resources
The OP
 

【STM32F746 Nucleo】 MxCube develops serial communication [Copy link]

  • CubeMX configuration development driver
    1. Chip Search

Because this development board is officially designed and launched, there are development board resources in the tool software, and you can directly select the development board currently in use.

    1. Clock Configuration

You can choose the constant frequency according to your actual situation. The maximum constant frequency is 216MHz

    1. Clock source configuration

This environment has already been configured, so just check it.

    1. SYS Settings Debug

The SW mode is selected

    1. Serial port configuration

Involves baud rate setting, pin setting and interrupt setting

1.6 Code Generation

This is a foreshadowing and the next article will give a brief description.

2. Keil Project

2.1. (MDK) keil project generated by CubeMX

2.2 Schematic Pinout

2.3、Serial port implementation

CubeMX software generates HAL library program code in a graphical way. The HAL library program code is very different from the standard library.

void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart)

For example, this line of code is the function of the serial port putting back data. The bottom layer uses interrupts to process, but the standard library uses direct interrupt calls, while the HAL library uses callback functions. The design concept of HAL is actually more practical.

1. Add receiving and sending function code

/* USER CODE BEGIN 1 */

/**

 * [url=home.php?mod=space&uid=159083]@brief[/url] Usart1Send

 * @param pUSARTx: Specified serial port

 * @param str:Send data content

 * @param strlen:Send data len

 * @retval None

 */

voidUsart2_Send( char*str,uint8_tstrlen)

{

 unsignedintk=0;

 do

 {

   HAL_UART_Transmit(&huart2,(uint8_t*)(str+k),1,1000);

   k++;

 } while(k<strlen);





}

/**

 * @brief Usart1Send

 * @param pUSARTx: Specified serial port

 * @param str:Send data content

 * @param strlen:Send data len

 * @retval None

 */

voidUsart3_Send( char*str,uint8_tstrlen)

{

 unsignedintk=0;

 do

 {

   HAL_UART_Transmit(&huart3,(uint8_t*)(str+k),1,1000);

   k++;

 } while(k<strlen);





}



/**

 * @brief HAL_UART_RxCpltCallback

 * @param huart: Specified serial port

 * @retval None

 */

voidHAL_UART_RxCpltCallback(UART_HandleTypeDef*huart)

{



 if(huart->Instance==USART2)

 {



   if(Uart2_Rx_Cnt>254)

   {

   Uart2_Rx_Cnt=0;

   memset(RxBuffer_2,0x00,sizeof(RxBuffer_2));

  

   } 

   else

   {

    RxBuffer_2[Uart2_Rx_Cnt++] =aRxBuffer_2;

   

  }

  HAL_UART_Receive_IT(&huart2, (uint8_t*)&aRxBuffer_2, 1); 

 }elseif(huart->Instance==USART3)

 {



   if(Uart3_Rx_Cnt>254)

   {

   Uart3_Rx_Cnt=0;

   memset(RxBuffer_3,0x00,sizeof(RxBuffer_3));

   } 

   else

   {

    RxBuffer_3[Uart3_Rx_Cnt++] =aRxBuffer_3;

   

   

   }

   HAL_UART_Receive_IT(&huart3, (uint8_t*)&aRxBuffer_3, 1); 



 }



UNUSED(huart);

}
  1. Add H file declaration code
externvoidUsart2_Send( char*str,uint8_tstrlen);

externvoidUsart2_Send( char*str,uint8_tstrlen);

  1. Add definition number code
uint8_taRxBuffer_2=0;

uint8_taRxBuffer_3=0;

unsignedcharaRxBuffer_hlp=0;

unsignedcharUart2_Rx_Cnt=0;

unsignedcharUart3_Rx_Cnt=0;

unsignedcharRxBuffer_2[RXBUFFERSIZE];

unsignedcharRxBuffer_3[RXBUFFERSIZE];

unsignedcharhlpUart1_Rx_Cnt=0;

unsignedcharRxBuffer_hlp[RXBUFFERSIZE];

2.4. Serial communication test

This post is from stm32/stm8
 

157

Posts

0

Resources
2
 

usart(1).rar (25.32 MB, downloads: 0)
This post is from stm32/stm8
 
 

Guess Your Favourite
Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list