cancel
Showing results for 
Search instead for 
Did you mean: 

SPI driven 74595 shift register produces random output

Stipe
Associate II

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).

1 ACCEPTED SOLUTION

Accepted Solutions
Stipe
Associate II

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-(

View solution in original post

4 REPLIES 4
MM..1
Chief II

Is your 595 on 5V or 3V3 ?

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

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);
Stipe
Associate II

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-(