Failed STM32 Cube HAL for OLED SSD1306 with SPI
I'm configuring a STM32F205RET for SPI:
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_8;
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
hspi1.Init.CRCPolynomial = 10;
HAL_SPI_Init(&hspi1);...with the relevant pins:
MCU Pin SPI Function
PA4 (Pin-20) Chip select (CS)
PA5 (Pin-21) SPI1 SCK (D0)
PA7 (Pin-23) SPI1 MOSI (D1)
PB0 (Pin-26) Data command (DC)
PB1 (Pin-27) Reset (RES)
3V3 —
GND —
I'm using blocking functions like:
HAL_GPIO_WritePin(OLED_DC_GPIO_Port, OLED_DC_Pin, GPIO_PIN_SET);
HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_RESET);
if ((HAL_SPI_Transmit(&hspi1, pData, nBytes, SPI_TIMEOUT_MAX)) != HAL_OK)
Error_Handler();
HAL_GPIO_WritePin(OLED_CS_GPIO_Port, OLED_CS_Pin, GPIO_PIN_SET);
To write commands like:
#define OLED_DISPLAYOFF 0xAE
#define OLED_DISPLAYON 0xAF
...and many more.
Working
When I send the same command sequence with libopencm3(3) the display lights up as expected.
Problem
When I program the STM32F205RET chip with the above HAL code, the display remains dark and inactive.
Question
What do you think I should troubleshoot first, and what's the best way to solve this problem? Thanks! :smiling_face_with_smiling_eyes:
Device
STM32CubeMX


