Skip to main content
Associate II
August 18, 2024
Solved

SPI driven 74595 shift register produces random output

  • August 18, 2024
  • 2 replies
  • 3193 views

Hi folks,

For the past 2 days, i tried to setup a simple SPI communication to feed a shift register with 7-segment data.

I already have done this in the arduino IDE, using shiftOut.

Now I want to make this more elegant with the CubeIDE. I set up an SPI1 and connected it to the SER input. Clk also connected to SPI Clk. I habe even a separate GPIO pin for the shift register latch SRCLK.

Here is some code (it should count from 0-9, the segment data is in the digArray):

 

 spiBuffer[0] = digArray[count++];
 if (count==10) {
 count=0;
 }

 HAL_GPIO_WritePin(SRCLK_GPIO_Port, SRCLK_Pin, GPIO_PIN_RESET);
 HAL_SPI_Transmit(&hspi1, spiBuffer, 1, 10);
 HAL_GPIO_WritePin(SRCLK_GPIO_Port, SRCLK_Pin, GPIO_PIN_SET);

 

The thing is, the 7-segment displays almost always random ***. I measured every signal with oscilloscope.

The SPI is setup with MSB first which is like in my Arduino program. I struggle with the clock (I think it should have some "delay" and we need a rising edge). I set polarity low and high, dont know what is correct. I think it should be high. Nothing works.

Is there a known issue about SPI and shift registers? I tried to lower the baudrate ridiculously, that was not the problem.

Anyone an idea? Thanks for your comments!

PS:  I think I connected everything very well, even verified each segment connection. The result is quite random (yes, every open input is connected on the 74hc595).

Best answer by Stipe

Thanks for the hint. I think it's any hardware issue. The scope looks good:

IMG_20240818_151304645_HDR.jpg

Edit:

The problem was that I swapped RCLK and SRCLK pins. I hate the data sheet, the description says 

RCLK 12 14 I RCLK Input
SRCLK 11 14 I SRCLK Input

Man, this is not very helpful actually 8-(

2 replies

MM..1
Chief III
August 18, 2024

Is your 595 on 5V or 3V3 ?

StipeAuthor
Associate II
August 18, 2024

Everything is 3.3V supplied. That worked fine in my old arduino setup...

MM..1
Chief III
August 18, 2024

Then HC is ok and you only require scope signals and setup SPI config right.

Too good practice is check return value from 

HAL_SPI_Transmit(&hspi1, spiBuffer, 1, 10);
StipeAuthorBest answer
Associate II
August 18, 2024

Thanks for the hint. I think it's any hardware issue. The scope looks good:

IMG_20240818_151304645_HDR.jpg

Edit:

The problem was that I swapped RCLK and SRCLK pins. I hate the data sheet, the description says 

RCLK 12 14 I RCLK Input
SRCLK 11 14 I SRCLK Input

Man, this is not very helpful actually 8-(