注册 登录
电子工程世界-论坛 返回首页 EEWORLD首页 频道 EE大学堂 下载中心 Datasheet 专题
尹小舟的个人空间 https://home.eeworld.com.cn/space-uid-1076653.html [收藏] [复制] [分享] [RSS]
日志

CLM32L003 串口波特率问题解决

已有 170 次阅读2024-1-22 16:33

1、芯片问题  

      CLM32L003 串口波特率115200 设置无效

2、手册描述

 

 

 

 

 

                     DBAUD  寄存器需要设置为双波特率

3、代码修改

 

/**
  * @brief UART Init Structure definition
  */
typedef struct
{
  uint32_t BaudRate;                  /*!< This member configures the UART communication baud rate.
                                           The baud rate is computed using the following formula:
                                           - IntegerDivider = ((PCLKx) / (16 * (huart->Init.BaudRate)))
                                           - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */

	uint32_t BaudDouble;                /*!< Specifies whether baudrate is doubled.
                                           This parameter can be a value of @ref UART_BaudDouble */	
	
	uint32_t HalfDuplexMode;						/*!< Specifies whether halfduplex mode is enabled.
                                           This parameter can be a value of @ref UART_HalfDuplex */	
	
  uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
                                           This parameter can be a value of @ref UART_Word_Length */	
	
  uint32_t Parity;                    /*!< Specifies the parity mode.
                                           This parameter can be a value of @ref UART_Parity
                                           @note When parity is enabled, the computed parity is set
                                                 at the MSB position of the transmitted data (9th bit only when
                                                 the word length is set to 9 data bits;*/	
	
  uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
                                           This parameter can be a value of @ref UART_Mode */

}UART_InitTypeDef;

BaudDouble   :指定波特率是否加倍

 

#define UART_BAUDDOUBLE_ENABLE              ((uint32_t)UART_SCON_DBAUD)
#define UART_BAUDDOUBLE_DISABLE             (0x00000000U)

可以使用这两个宏函数

 

 

/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();		
	
  /* Configure the system clock to HIRC 24MHz*/
  SystemClock_Config();
			
  /* Peripheral clock enable */
  __HAL_RCC_UARTx_CLK_ENABLE();	
	
	sUartxHandle.Instance = UARTx;
	sUartxHandle.Init.BaudRate = BAUDRATE;
	sUartxHandle.Init.BaudDouble = UART_BAUDDOUBLE_ENABLE;	
	sUartxHandle.Init.WordLength = UART_WORDLENGTH_8B;
	sUartxHandle.Init.Parity = UART_PARITY_NONE;
	sUartxHandle.Init.Mode = UART_MODE_TX_RX;
	HAL_UART_Init(&sUartxHandle);
	
	HAL_UART_Transmit_IT(&sUartxHandle, ucSendData, sizeof(ucSendData));
	HAL_UART_Receive_IT(&sUartxHandle, ucReceiveData, sizeof(ucReceiveData));	
	HAL_NVIC_EnableIRQ(UARTx_IRQn);
	
  while (1)
	{
		/* UART receive LENGTH datas then transmit the received datas */		
		if(ucRxCompleteFlag == 1)
		{
			ucRxCompleteFlag = 0;
			HAL_UART_Transmit_IT(&sUartxHandle, ucReceiveData, sizeof(ucReceiveData));	
			HAL_UART_Receive_IT(&sUartxHandle, ucReceiveData, sizeof(ucReceiveData));				
		}
	}
}

 

本文来自论坛,点击查看完整帖子内容。

全部作者的其他最新日志
评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

热门文章