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.

1 ACCEPTED SOLUTION

Accepted Solutions
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

 

View solution in original post

12 REPLIES 12
Andrew Neil
Evangelist III

How are you attempting to observe the transmitted bytes?

Is this on an ST board?

  • If yes, which one?
  • If not, please provide schematics.
SofLit
ST Employee

Hello,

just trying to send bytes out of the UART and then receive them. Here is my setup code:

Send receive to which device? a PC HyperTerminal or what? or looping back Tx/Rx?

Need to give more details ..

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.

Send a readable string first, check on terminal.

For receive need to make sure any kind of receive error is cleared, ie noise, framing, parity, etc

PF6/PF7 AF7 for UART7 seem correct

Polled method are inherently half-duplex, there aren't deep buffers, not going to capture standing waves from signals transmitted 300 ms earlier. Even if TX/RX looped back.

Transmit a continuous 0x55 'U' pattern, confirm baud / bit timing with a scope.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I'm observing the output on an Analog discovery pro as a Logic analyzer. I have also hooked up a basic USB to serial TX pin on another channel as a sanity check that it is working.

It is not on an ST eval board it is on a proprietary CubeSat "On Board Computer".

 

Thanks!

 

Currently, I'm observing the TX pin on a logic analyzer. Just want to see it actually transmit something right now.

Thanks.

 

Send known patterns. 0x55 would be good for checking baud rates at 8N1

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Uhm… CubeSat On Board Computer is based on Microchip PIC32MZ M14K. Do you realise that this is the community of STMicroelectronics?

Regards
/Peter

In order 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.

So start by debugging the transmission.

As stated by @Tesla DeLorean send patterns 0x55 or 0xAA to at least be sure that you have a signal at Tx pin and you have the right bitrate.

In your first comment you said:

"just trying to send bytes out of the UART and then receive them"

I asked you how are you doing that? looping back Tx/Rx or send doing a communication with another device?.

Because in the second case you need to have the exact UART configuration at both sides: baudrate, parity, data length etc .. In the first case it's simple as it's the same config for the same UART. You can start by looping back Tx/Rx of UART7 by sending/receiving one byte ..

You can start by inspiring from that example: https://github.com/STMicroelectronics/STM32CubeH7/blob/master/Projects/STM32H743I-EVAL/Examples/UART/UART_Printf/Src/main.c

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.

This is not That CubeSat OBC. This is based on the STM32H753II