cancel
Showing results for 
Search instead for 
Did you mean: 

STM32C8T6 UART Not working

rtek
Associate II
Posted on March 23, 2018 at 06:40

Trying to get 

STM32C8T6 UART to send data but nothing comes through. I configured the RCC, SYS, USART1 (baud 9600) and the integrated led on cubemx.  Tx connected to A9, Rx to A10. My code is as follows:   

UART_HandleTypeDef huart1;

uint8_t bufftx[10]='HELLO';

void SystemClock_Config(void);

int main(void)

{

HAL_Init();

SystemClock_Config();

MX_GPIO_Init();

MX_DMA_Init();

MX_USART1_UART_Init();

while (1)

{

HAL_GPIO_TogglePin(LED_GPIO_Port,LED_Pin);

HAL_UART_Transmit(&huart1, bufftx,10,100);

HAL_Delay(200);

}

}

As you can see there's not much to it. Im using the same code in my nucleo f103 and it works fine. Why doesnt it work on the blue pill?
6 REPLIES 6
AvaTar
Lead
Posted on March 23, 2018 at 08:24

Trying to get 

STM32C8T6 UART to

...

What part you are talking about ?

There is something crucial missing, the name is supposed to be

STM32F

XXX

C8T6, assuming an F series MCU.
Posted on March 23, 2018 at 14:14

Oh yes sorry. Stm32f103c8t6. Typo.

Posted on March 23, 2018 at 16:25

HAL_UART_Transmit(&huart1, bufftx, strlen(bufftx),100);

>>Why doesnt it work on the blue pill?

Don't know, how do you have the thing wired up and to what? How are you determining that it is 'not working'?

The USART uses CMOS levels, these are not compatible with RS232 level, you would need a converter, or use a USB-to-CMOS Serial type dongle.

Can you output a continuous stream of 'U' characters and confirm the bit pattern and timing on a scope?

Have you double checked things like HSE_VALUE in the context of your board's clock source?

What does the actual pin and USART initialization code look like? Are you enabling all the required clocks?

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on March 23, 2018 at 16:42

Stm32f103c8t6 powered with usb. Xbee tx,rx,vcc,gnd connected to mcu. Also tried with ftdi232 clk,dio and ground connected to the mcu but nothing comes up on the serial monitor and the receiving xbee rx led doesnt indicate a recieved package. Both of these ways work on the nucleo f103. I just have no idea what's the problem here. No issues with the nucleo and I configured this the same way.

HSE_VALUE 8000000 like it should. 

__HAL_RCC_USART1_CLK_ENABLE();

Here's my USART ini codes:

void MX_USART1_UART_Init(void)

{

huart1.Instance = USART1;

huart1.Init.BaudRate = 9600;

huart1.Init.WordLength = UART_WORDLENGTH_8B;

huart1.Init.StopBits = UART_STOPBITS_1;

huart1.Init.Parity = UART_PARITY_NONE;

huart1.Init.Mode = UART_MODE_TX_RX;

huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart1.Init.OverSampling = UART_OVERSAMPLING_16;

if (HAL_UART_Init(&huart1) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

}

void HAL_UART_MspInit(UART_HandleTypeDef* uartHandle)

{

GPIO_InitTypeDef GPIO_InitStruct;

if(uartHandle->Instance==USART1)

{

/* USER CODE BEGIN USART1_MspInit 0 */

/* USER CODE END USART1_MspInit 0 */

/* USART1 clock enable */

__HAL_RCC_USART1_CLK_ENABLE();

/**USART1 GPIO Configuration

PA9 ------> USART1_TX

PA10 ------> USART1_RX

*/

GPIO_InitStruct.Pin = GPIO_PIN_9;

GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;

GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

GPIO_InitStruct.Pin = GPIO_PIN_10;

GPIO_InitStruct.Mode = GPIO_MODE_INPUT;

GPIO_InitStruct.Pull = GPIO_NOPULL;

HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);

/* USART1 interrupt Init */

HAL_NVIC_SetPriority(USART1_IRQn, 0, 0);

HAL_NVIC_EnableIRQ(USART1_IRQn);

/* USER CODE BEGIN USART1_MspInit 1 */

/* USER CODE END USART1_MspInit 1 */

}

}

Here's my sysclock config:

void SystemClock_Config(void)

{

RCC_OscInitTypeDef RCC_OscInitStruct;

RCC_ClkInitTypeDef RCC_ClkInitStruct;

/**Initializes the CPU, AHB and APB busses clocks

*/

RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;

RCC_OscInitStruct.HSIState = RCC_HSI_ON;

RCC_OscInitStruct.HSICalibrationValue = 16;

RCC_OscInitStruct.PLL.PLLState = RCC_PLL_NONE;

if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Initializes the CPU, AHB and APB busses clocks

*/

RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK

|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;

RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_HSI;

RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;

RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;

RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;

if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_0) != HAL_OK)

{

_Error_Handler(__FILE__, __LINE__);

}

/**Configure the Systick interrupt time

*/

HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/1000);

/**Configure the Systick

*/

HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK);

/* SysTick_IRQn interrupt configuration */

HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

}

rtek
Associate II
Posted on March 23, 2018 at 19:18

So the TX pin is alive. Here's a scope from just sending a letter ''S''. Looks about right doesnt it? Why doesnt the FTDI232 or Xbee react to this message then?

0690X00000604VRQAY.jpg
Posted on March 24, 2018 at 14:06

I'd probably make sure the GPIOA clock is enabled, assume it must be some place else if you see pin signals on scope.

Signal looks reasonable enough for 0x53 01010011 'S' at 9600 baud.

Is the Transmit from the STM32 connected to the receive pin of the receiving device.

XBee radio link involved in the connectivity?

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