2021-07-02 01:00 PM
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
STM32CubeMX
Solved! Go to Solution.
2021-07-04 01:50 AM
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.)
2021-07-02 02:33 PM
Check CS with respect to data and clocks.
Probably want to use TransmitReceive so all data is clocked out prior to CS rising.
2021-07-03 03:07 AM
The CubeMX screenshots are for STM32F405RGT...
2021-07-04 01:43 AM
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.
2021-07-04 01:47 AM
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.
2021-07-04 01:50 AM
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.)
2022-12-16 07:24 AM
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.
Does anyone have a good example, because I can't find an howto on Youtube or somewhere else.
BR
Johan