Skip to main content
salvi.a
Associate II
December 15, 2022
Solved

STM32F030 Receiving UART Data Only Once

Hello,

I'm trying to send data to STM32 from NodeMCU. My project is simply controlling WS2812B LEDs by using SPI from STM32 and receiving commands by using UART to STM32 from NodeMCU.

LED's working fine by SPI but I can only receive data once at start. Then UART stops. I can still send commands to nodeMCU but it doesn't transmit to STM32 after first command.

What might cause this problem? Here is my SPI and UART setting

hspi1.Instance = SPI1;
 hspi1.Init.Mode = SPI_MODE_MASTER;
 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
 hspi1.Init.NSS = SPI_NSS_SOFT;
 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_16;
 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
 hspi1.Init.CRCPolynomial = 7;
 hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
 hspi1.Init.NSSPMode = SPI_NSS_PULSE_DISABLE;
huart1.Instance = USART1;
 huart1.Init.BaudRate = 115200;
 huart1.Init.WordLength = UART_WORDLENGTH_8B;
 huart1.Init.StopBits = UART_STOPBITS_1;
 huart1.Init.Parity = UART_PARITY_NONE;
 huart1.Init.Mode = UART_MODE_RX;
 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
 huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
 huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
HAL_UART_Receive(&huart1, rxData, 1, 100);
 
	if(rxData[0] == '1'){
		setPixelColor(1,250,0,0);
		HAL_GPIO_WritePin(LED_YESIL_GPIO_Port, LED_YESIL_Pin, GPIO_PIN_SET);
	}else if(rxData[0] == '0'){
		setPixelColor(1,0,0,0);
		HAL_GPIO_WritePin(LED_YESIL_GPIO_Port, LED_YESIL_Pin, GPIO_PIN_RESET);
	}

This topic has been closed for replies.
salvi.a
salvi.aBest answer
Associate II
December 16, 2022

I fixed it. It wasn't about code. I just used UART by DMA and it working well now.

Thanks a lot.

2 replies

Karl Yamashita
Principal
December 16, 2022

Your third snippet doesn't show what you're doing after you test for character '1' or '0'.

You have to post a more complete snippet.

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source
salvi.a
salvi.aAuthorBest answer
Associate II
December 16, 2022

I fixed it. It wasn't about code. I just used UART by DMA and it working well now.

Thanks a lot.