0
\$\begingroup\$

I got this arduino shield with four 7 segment display what I'm trying to make work with STM32 nucleo. The displays are driven with two 74HC595 shift registers.

I wrote the following code to control it, but somehow it doesn't work, always shows the same pattern whatever I modify in the array.

int digits[16] = {1,1,1,1,1,0,1,0,1,0,1,1,0,1,1,0}; while (1) { HAL_GPIO_WritePin(STCP_GPIO_Port, STCP_Pin, GPIO_PIN_RESET); for(int i=0;i>=15;i--) { HAL_GPIO_WritePin(SHCP_GPIO_Port, SHCP_Pin, GPIO_PIN_RESET); if(digits[i]==1) { HAL_GPIO_WritePin(DS_GPIO_Port, DS_Pin, GPIO_PIN_SET); }else { HAL_GPIO_WritePin(DS_GPIO_Port, DS_Pin, GPIO_PIN_RESET); } HAL_GPIO_WritePin(SHCP_GPIO_Port, SHCP_Pin, GPIO_PIN_SET); } HAL_GPIO_WritePin(STCP_GPIO_Port, STCP_Pin, GPIO_PIN_SET); } 

SHCP: Shift register clock

STCP: Storage register Clock

DS: Data

What could be the problem?

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

Your for loop has an error. It would try to count backwards from 0 until it is larger than 14. My rough estimate is that it takes about 2^31 loops until the count reaches largest negative number and rolls back to largest positive number before the for loop exits.

\$\endgroup\$
1
  • \$\begingroup\$ Indeed, that was the solution. Thank you! \$\endgroup\$ Commented Mar 7, 2021 at 21:08

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.