2018-04-03 06:22 AM
Hi
I got a problem with a switch in my MCU. I use custom board with STM32F030C8T6.
This here is part of my program:
void rozkaz3(void) {
switch(bufor[3]){ case 0: HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_RESET); HAL_Delay(1000); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_4, GPIO_PIN_SET); break; case 1: HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_RESET); HAL_Delay(1000); HAL_GPIO_WritePin(GPIOB, GPIO_PIN_3, GPIO_PIN_SET); break; case 2: HAL_GPIO_WritePin(GPIOF, GPIO_PIN_7, GPIO_PIN_RESET); HAL_Delay(1000); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_7, GPIO_PIN_SET); break; case 3: HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_RESET); HAL_Delay(1000); HAL_GPIO_WritePin(GPIOF, GPIO_PIN_6, GPIO_PIN_SET); break; case 5: HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_RESET); HAL_Delay(1000); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_11, GPIO_PIN_SET); break; case 6: HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_RESET); HAL_Delay(1000); HAL_GPIO_WritePin(GPIOA, GPIO_PIN_8, GPIO_PIN_SET); break; case 7: case 4: default: break; case 12: NVIC_SystemReset(); break;it switches on and off outputs i chose based on number. My board has 6 outputs. Case 4 and case 7 are not configured and not connected.
If i order case 0,1,2,3,5,6,11,12 all works well.
If i order case 4 or 7 my program works on case 0 then case 4/7. If i delete case 0 it will work on case 1 and then case 4/7 and so on.
It works first available case in switch then case i ordered.
Now if i change only this:
case 7:
case 4: default:HAL_Delay(1000);
break;I works ok.
And with HAL_Delay(1) its not working again.
Whats happening and how to make it work right without HAL_Delay ?
Note: this post was migrated and contained many threaded conversations, some content may be missing.2018-04-03 07:25 AM
I say the problem is in that part of code we don't see.
JW
2018-04-03 04:17 PM
case 4 is out of order,
you must either leave it out,
or put it in order.
Case 12 is also out of order.
do you like Dials or Knobs ?
2018-04-04 02:22 AM
case 4 works fine like that. Ive put it in order for test now and nothing changed.
i checked order of cases and i can switch hovewer i want it and it doesnt matter.
I did put for fun cases in order 1253067 and i worked with no changes.
edit: im a knob man
2018-04-04 02:22 AM
2018-04-04 02:27 AM
i deleted those cases that shouldnt be available (4 and 7) and first from top is used when order 4 or 7, default does nothing for me...
2018-04-04 02:34 AM
If i order case 4 or 7 my program works on
case 0 then case 4/7.
Are you describing what happens when you step the code in the debugger?
If so, this could be just down to optimisation:
https://www.avrfreaks.net/forum/shortcuts-taken-optimized-code-may-occasionally-sic-be-surprising
Do you actually see the correct pins being toggled ?
2018-04-04 02:44 AM
case 4 is out of order, ...
No, it is not.
There is no requirement of the C language to put cases in a specific order.
I agree with Jan, there seems to be a problem with the code not shown.
Is there perhaps something changing the contents of the switch variable
(bufor[3])
in the background ?2018-04-04 02:48 AM
i checked the process in debugger and bufor[3] is not changed before exiting this part of code.
2018-04-04 02:50 AM
artistically , knob is the better word, but its just a bit too colourful these days..