cancel
Showing results for 
Search instead for 
Did you mean: 

Simple UART problem STM32H753

GlennH
Associate III

Hi,
I'm relatively new to the STM32 world and I'm becoming frustrated that I can't make a simple UART work. No DMA, no interrupts just trying to send bytes out of the UART and then receive them. Here is my setup code:

 

 

 

 

 

 

void UART7_Init(void)
{

	GPIO_InitTypeDef GPIO_InitStruct;

		HAL_Init();


	    /* Peripheral clock enable */
    __HAL_RCC_UART7_CLK_ENABLE();
    __HAL_RCC_GPIOF_CLK_ENABLE();

    /**UART7 GPIO Configuration
    PF6     ------> UART7_RX
    PF7     ------> UART7_TX
    PF8     ------> UART7_RTS
    PF9     ------> UART7_CTS
    */
    GPIO_InitStruct.Pin = U7_PAY_RX_SPI5_NSS_Pin|U7_PAY_TX_SPI5_SCK_Pin;
    GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
    GPIO_InitStruct.Pull = GPIO_NOPULL;
    GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
    GPIO_InitStruct.Alternate = GPIO_AF7_UART7;
    HAL_GPIO_Init(GPIOF, &GPIO_InitStruct);


    huart7.Instance = UART7;
    huart7.Init.BaudRate = 115200;
    huart7.Init.WordLength = UART_WORDLENGTH_8B;
    huart7.Init.StopBits = UART_STOPBITS_1;
    huart7.Init.Parity = UART_PARITY_NONE;
    huart7.Init.Mode = UART_MODE_TX_RX;
    huart7.Init.HwFlowCtl = UART_HWCONTROL_NONE;
    huart7.Init.OverSampling = UART_OVERSAMPLING_16;
    huart7.Init.OneBitSampling = UART_ONEBIT_SAMPLING_DISABLED;
    huart7.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;

    	if(HAL_UART_Init(&huart7) != HAL_OK)
    	{
    		asm("bkpt 255"); // Just for degugging
    		Error_Handler();
    	}

    /* UART7 interrupt Init */
    //HAL_NVIC_SetPriority(UART7_IRQn, 5, 0);
    //HAL_NVIC_EnableIRQ(UART7_IRQn);
  /* USER CODE BEGIN UART7_MspInit 1 */

  /* USER CODE END UART7_MspInit 1 */
  }

 

 

 

 

And here is the actual transmit code:

 

 

 

do
	{
	drv_led_toggle(DRV_LED_ID_AMBER);
	HAL_UART_Transmit(&huart7, receiveBuffer, sizeof(receiveBuffer), TIMEOUT);
	HAL_Delay(300);
	//HAL_UART_Receive(&huart7, receiveBuffer, 1, TIMEOUT);
	drv_led_toggle(DRV_LED_ID_AMBER);
	HAL_Delay(300);

	if(UART7->ISR & (1<<5))
	    {
		HAL_UART_Receive(&huart7, receiveBuffer  , 1 /*sizeof(receiveBuffer)*/, TIMEOUT);
	    }

	if(i%2)drv_led_toggle(DRV_LED_ID_AMBER);


	} while(i<5);

 

 

 

 

I'm pretty sure that it's something simple and I'm just missing it. Any advice is appreciated.

Thanks.

12 REPLIES 12

I understand very well how UARTs work. I'm only unfamiliar with the STM32 implementation. I was looking to see the pin wiggle at all on the logic analyzer, and not seeing anything. At that point, it doesn't matter what the Baud, bits, parity, or stop are as long as the baud and bits have a value other than zero. Once the pin wiggles, Of course, I can then set up receive or loopback.

I believe I just have one simple thing wrong, and I don't see what that is. I was hoping someone more familiar with the platform might spot it right away.

 

Thanks!

 

Can you just toggle the pin you're hoping to use as UART Tx as a simple GPIO?

To check that it's not something on your board preventing the pin from moving.

GlennH
Associate III

Thank you all for the suggestions. I found that I was looking at the wrong pins on the PC-104 connector. It's working fine now!

 

Thanks again,

Glenn