2024-08-18 05:13 AM - edited 2024-08-18 05:14 AM
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).
Solved! Go to Solution.
2024-08-18 07:06 AM - edited 2024-08-18 11:30 AM
Thanks for the hint. I think it's any hardware issue. The scope looks good:
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-(
2024-08-18 05:37 AM
Is your 595 on 5V or 3V3 ?
2024-08-18 05:50 AM
Everything is 3.3V supplied. That worked fine in my old arduino setup...
2024-08-18 05:59 AM
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);
2024-08-18 07:06 AM - edited 2024-08-18 11:30 AM
Thanks for the hint. I think it's any hardware issue. The scope looks good:
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-(