cancel
Showing results for 
Search instead for 
Did you mean: 

UART RECEIVE PROBLEM / STM32G061C6

thegentdev
Associate

Hi all,

I am using a STM32G061C6T6 MCU. I'm trying to contact Nextion HMI. My data sending is successful, but I can't get any data. I couldn't run any of the Pooling and interrupt methods when receiving data. When I follow the RX pin with the oscilloscope, the data comes, but I can't read it with MCU. 

I tried the display on the Nucleo-F103RB card with a simple HAL code. I can read the data from the screen. Do I need to do a special operation on this MCU(STM32G061C6) to be able to read with UART? I'd appreciate it if you could help me.

#include "main.h"
 
/* Private includes ----------------------------------------------------------*/
/* USER CODE BEGIN Includes */
 
/* USER CODE END Includes */
 
/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN PTD */
 
/* USER CODE END PTD */
 
/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN PD */
/* USER CODE END PD */
 
/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN PM */
 
/* USER CODE END PM */
 
/* Private variables ---------------------------------------------------------*/
UART_HandleTypeDef huart1;
 
/* USER CODE BEGIN PV */
uint8_t nextion_rx[10];
/* USER CODE END PV */
 
/* Private function prototypes -----------------------------------------------*/
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
 
/* USER CODE END PFP */
 
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
 
/* USER CODE END 0 */
 
/**
  * @brief  The application entry point.
  * @retval int
  */
int main(void)
{
  /* USER CODE BEGIN 1 */
 
  /* USER CODE END 1 */
 
  /* MCU Configuration--------------------------------------------------------*/
 
  /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
  HAL_Init();
 
  /* USER CODE BEGIN Init */
 
  /* USER CODE END Init */
 
  /* Configure the system clock */
  SystemClock_Config();
 
  /* USER CODE BEGIN SysInit */
 
  /* USER CODE END SysInit */
 
  /* Initialize all configured peripherals */
  MX_GPIO_Init();
  MX_USART1_UART_Init();
  /* USER CODE BEGIN 2 */
  HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
  /* USER CODE END 2 */
 
  /* Infinite loop */
  /* USER CODE BEGIN WHILE */
  while (1)
  {
 
  HAL_UART_Receive(&huart1, (uint8_t *)nextion_rx, 10, 1000);
 
    /* USER CODE END WHILE */
 
    /* USER CODE BEGIN 3 */
  }
  /* USER CODE END 3 */
}

0693W00000DmdEtQAJ.png

1 ACCEPTED SOLUTION

Accepted Solutions
Bruno_ST
ST Employee

Hello @Fatih Erdoğan​ 

Do you have the floowing line of code in bold in stm32g0xx_hal_msp.c ?

  /**USART1 GPIO Configuration

  PA9   ------> USART1_TX

  PA10   ------> USART1_RX

  */

  GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF1_USART1;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

If not, please add it.

BR,

Bruno

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

View solution in original post

2 REPLIES 2
Bruno_ST
ST Employee

Hello @Fatih Erdoğan​ 

Do you have the floowing line of code in bold in stm32g0xx_hal_msp.c ?

  /**USART1 GPIO Configuration

  PA9   ------> USART1_TX

  PA10   ------> USART1_RX

  */

  GPIO_InitStruct.Pin = GPIO_PIN_9|GPIO_PIN_10;

  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

  GPIO_InitStruct.Pull = GPIO_NOPULL;

  GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;

  GPIO_InitStruct.Alternate = GPIO_AF1_USART1;

  HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

If not, please add it.

BR,

Bruno

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi @Bruno_ST​ ,

I'm grateful to you, the problem is solved. Thank you very much.