cancel
Showing results for 
Search instead for 
Did you mean: 

Failed STM32 Cube HAL for OLED SSD1306 with SPI

MSchl.2105
Associate II

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! ��

Device

0693W00000Bci7QQAR.jpg 

STM32CubeMX

0693W00000Bci6wQAB.png0693W00000Bci7BQAR.png

1 ACCEPTED SOLUTION

Accepted Solutions
MSchl.2105
Associate II

The problem was solved by correcting a delay_us(3) implementation. This delay was present in between some RESET (NSS) line toggles, and it seems to have appeared as a SPI serial problem (but it was not.)

View solution in original post

6 REPLIES 6

Check CS with respect to data and clocks.

Probably want to use TransmitReceive so all data is clocked out prior to CS rising.

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

The CubeMX screenshots are for STM32F405RGT...

That's right @Piranha​ , my screenshots show a F405 target while the photograph shows a F205 target. I have devices with both parts, so I mixed and matched. Of course, I have two projects and set the clocks accordingly.

Thanks a lot @Community member​ for the suggestion to check CS and replace HAL_SPI_Transmit(3) with HAL_SPI_TransmitReceive(3). There was no problem with the CS logic, and while I like the idea of researching transmit and receive I'll use that time instead to develop from the existing blocking to DMA methods.

MSchl.2105
Associate II

The problem was solved by correcting a delay_us(3) implementation. This delay was present in between some RESET (NSS) line toggles, and it seems to have appeared as a SPI serial problem (but it was not.)

JSven.2
Associate II

Hi all,

Trying to setup SPI for ssd1306 in STM32CubeIDE based on the code from "afiskon" in Github.

Problem is that I'm new to this processor and the IDE.

Could someone please help me?

I'm using the NUCLEO-F302R8 board and I have set up the following GPIO ports additional to the SPI3 bus.

0693W00000WLCfpQAH.pngDoes anyone have a good example, because I can't find an howto on Youtube or somewhere else.

BR

Johan