Skip to main content
PB S.1
Associate II
Sep 28, 2021 10:31 AM UTC
Question

How to use RGB LED in STM32WB5MMG-DK?

/*SPI Initialization*/
static void MX_SPI1_Init(void)
{
 
 /* SPI1 parameter configuration*/
 hspi1.Instance = SPI1;
 hspi1.Init.Mode = SPI_MODE_MASTER;
 hspi1.Init.Direction = SPI_DIRECTION_2LINES;//SPI_DIRECTION_2LINES;
 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;//SPI_POLARITY_LOW;
 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
 hspi1.Init.NSS = SPI_NSS_SOFT;
 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;//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_ENABLE;
 if (HAL_SPI_Init(&hspi1) != HAL_OK)
 {
 Error_Handler();
 }
 
}
 
/*RGB LED CONTROL*/
 HAL_GPIO_WritePin(GPIOH, GPIO_PIN_1, GPIO_PIN_SET);
 HAL_Delay(100);
 HAL_SPI_Transmit(&hspi1, "0x3A", 1, 100);
 HAL_SPI_Transmit(&hspi1, "0x7F", 1, 100);
 HAL_SPI_Transmit(&hspi1, "0x00", 1, 100);
 HAL_SPI_Transmit(&hspi1, "0x00", 1, 100);

Hi I am using STM32WB5MMG-DK for my project development activities. I wanted to control RGB LED(LD4). Is there any code example which to perform the required operation?

This topic has been closed for replies.

1 reply

TDK
Sep 28, 2021 1:00 PM UTC

> HAL_SPI_Transmit(&hspi1, "0x3A", 1, 100);

This is a string value with 4 characters in it (plus a null terminator). Your code actually sends the ASCII character "0" here.

If you want to send the value 58 (0x3A), don't use the quotes. You also need to pass a pointer to the value rather than raw data.

uint8_t data = 0x3A;
HAL_SPI_Transmit(&hspi1, &data, 1, 100);

Also, if PH1 is a CS line, it should be high (set) before the transaction and low (reset) just prior to sending data. Not sure of it's function here.

"If you feel a post has answered your question, please click ""Accept as Solution""."