cancel
Showing results for 
Search instead for 
Did you mean: 

Implement a usart1 receive interrupt without pressing a key

dvcosta43
Associate II
Posted on September 01, 2014 at 09:28

Hello Forum,

I have implemented a menu system on my app using the console

Main Menu Select A ....1   (e.g. prints Debug1)

Main Menu Select B.....2

2

     Sub Menu B Select A ......1

     Sub Menu B Select B.......2

1

 Carry out Sub Menu B Select A action....e.g print debug2

    Sub Menu B Select A ......1

    Sub Menu B Select B.......2

1

  

After selecting Main menu B by pressing '2',  I enter the sub menu from which I can select any of the sub menu options. Aften completing the sub menu action, I redisplay the sub menu to give the user the opportunity to select from it again if required. However when I press '1 ' again it takes me back into main menu '1' action where it prints Debug1. I can understand this as the usart interrupt just sees a '1' . However I want it to carry out the sub menu action.

After completing the sub menu action I think I need to make the usart1 receive interrupt think that a '2' has been pressed so that it resisplays the sub menu again. I tried the following but it doesn't seem to work.

char sub_menu_option = '2';

scanf(''%c'', &sub_menu_option);

Is there a way to do this or is this nonsense and is there an easier way?

Apologies if this is very convoluted but any help would be greatly appreciated.

Dave

#!psychic #stm32 #state-machine #fsm
3 REPLIES 3
Posted on September 01, 2014 at 14:48

Perhaps you want to look at the implementation more carefully. Use routines like getchar() or there equivalents, and check if scanf() is returning -1 before using the values returned.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Andrew Neil
Evangelist III
Posted on September 01, 2014 at 14:55

''the usart interrupt just sees a '1'''

Doing it in the ISR may well not be a good idea - but that's a separate issue.

If you want the ISR to be able to handle a '1' differently depending on which menu is currently displayed then, clearly, your ISR will have to be aware of  which menu is currently displayed!

In other words, the ISR needs a notion of state.

So a good technique could be a State Machine - aka Finite State Machine (FSM), or Finite State Automaton (plural: Automata)

dvcosta43
Associate II
Posted on September 02, 2014 at 08:45

Hi Guys,

Thanks for assisting. I'm implementing it as a state machine now, so it looks to be working OK now. It is probably is a bit safer than messing with the stack frame.

Dave.