cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F030 Receiving UART Data Only Once

salvi.a
Associate II

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);
	}

1 ACCEPTED SOLUTION

Accepted Solutions

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

Thanks a lot.

View solution in original post

2 REPLIES 2
Karl Yamashita
Lead III

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.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.

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

Thanks a lot.