SPI driven 74595 shift register produces random output
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).

