Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.
|
Forum Index : Microcontroller and PC projects : Interrupts and loops....
Page 1 of 2 | |||||
Author | Message | ||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Hi all. Interrupts are supposed to take effect at any point, if I understand things correctly. Setting up an interrupt on COM2 for serial input, this is working great - until the program runs into a DO/LOOP routine. Once in the DO/LOOP routine, the interrupt never works. In my case, the DO/LOOP is a keypress checking one: Do:Loop Until Inkey$<>"" Once I press a key, and the code is outside of the loop, the interrupt immediately takes effect, but this is not what I need - I need the interrupt to take effect, no matter where the program is in the scheme of things - INCLUDING within a loop. Is this normal behaviour? IE: That interrupts don't work during loops? If it is, then I need to find a way to check for keypresses in another way, so that the interrupts still can happen. Thanks for any pointers. Smoke makes things work. When the smoke gets out, it stops! |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
You may have yourself a bug. Here is a quote from the manual. What version of MMBasic are you running? |
||||
MicroBlocks Guru Joined: 12/05/2012 Location: ThailandPosts: 2209 |
You could setup an interrupt for the key detection using the ON KEY statement. (This is one of the reasons i suggested a HALT (or whatever name is better) statement in another topic, to make intention clear that there is no more program flow, only interrupts.) Microblocks. Build with logic. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Owwwwwww a bug! I've never found one before. I am using MMBASIC version 4.3 Smoke makes things work. When the smoke gets out, it stops! |
||||
TassyJim Guru Joined: 07/08/2011 Location: AustraliaPosts: 6100 |
Just for a test, put the DO LOOP Until Inkey$<>"" on different lines. It may only check for interrupts between lines. I don't have the hardware to test it with me. Back home in a few days... Jim VK7JH MMedit MMBasic Help |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Excellent idea - will do, and will post back. EDIT: Nope, did not work. Any serial coming in on COM2 with it's interrupt is totally ignored within the loop process. As soon as I press a key to get out of the loop, the code immediately goes to the interrupt routine with the expected data, but not until I press a key, meaning that the interrupt is not actually interrupting... Smoke makes things work. When the smoke gets out, it stops! |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
You said that you were on V4.3. Have you considered going to the latest stable release? I think that is V4.3a but that needs confirmation. |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
I will try that and let the thread know what happens. EDIT: Successfully updated to version 4.3A - no improvement, unfortunately. Exactly the same issue. Smoke makes things work. When the smoke gets out, it stops! |
||||
Blackened Regular Member Joined: 11/08/2012 Location: AustraliaPosts: 66 |
I'm using 4.3a on a Duinomite and am successfully using a SETTICK interrupt, declared prior to entering the same DO - LOOP INKEY$ loop structure. Is there any difference in the way the different interrupts should work? |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
I have a feeling that the issue is with the SERIAL PORT interrupt. Seems like normal interrupts such as on an I/O pin work fine during loops, but the serial-port one does not, based on your comments. I will cook up a test push-button on an I/O pin shortly, which I will setup an interrupt on, just to test this idea. Smoke makes things work. When the smoke gets out, it stops! |
||||
Geoffg Guru Joined: 06/06/2011 Location: AustraliaPosts: 3194 |
This is strange. I am not in a position to test it now but there should be no difference between processing a COM interrupt and a SETTICK one. I will be interested in the result of your test with an I/O pin interrupt. Geoff Geoff Graham - http://geoffg.net |
||||
cwilt Senior Member Joined: 20/03/2012 Location: United StatesPosts: 147 |
Try adding a small pause in the do loop. Do:pause 10:loop until..... |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Pause 10 added, did not help, but thanks for the idea. I did not get a chance to do the switch thing yesterday - will do that today. Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
OK, an update for you all. DEFINITELY ONLY A PROBLEM WITH SERIAL INTERRUPTS. The button interrupt works just fine during the DO/LOOP Here is my testing code - just so everyone can see what I am doing, but it is only a tester code, and does not actually do anything useful, it just interrupts and shows the data on the screen when I send some to COM2. ...provided I am not in the "Press any key..." DO/LOOP! But in case I am doing something fundamentally wrong with the code which would explain the problems I am having, I post it here. Mode 4 Open "com2:2400, 42, SerialInt, 21" As #2 SetPin 10,7,PushInt start: Cls Print CLR$(Green) "Waiting for data..." Loopything: If Len(A$)<>0 Then GoTo ShowData Print @(50,150) + CLR$(Blue) Time$ GoTo loopything ShowData: Cls If Mid$(A$,1,6)<>"[ABCD]" Then GoTo ERR Print A$ A$="":Print Print CLR$(Red) "PRESS ANY KEY..." Do:Pause 10:Loop Until Inkey$<>"" GoTo Start ERR: Print "Incorrect qualifier." Print Mid$(A$,1,6) A$="":Print Print CLR$(Red) "PRESS ANY KEY..." Do:Pause 10:Loop Until Inkey$<>"" GoTo Start End SerialInt: A$=Input$(21,#2) IReturn PushInt: Print: Print "Push button interrupt.": Print IReturn While I am here, the manual says that you can use D0-D8 for interrupts too, but if I issue a command such as Setpin D8,7,PushInt, the interpreter immediately halts when I try to run the program with a syntax error. Not a problem, as I just used pin10 instead, and simply used a jumper shunt, to short out pin10 to it's adjacent GND pin directly on the I/O socket...(which worked fine) Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Wait a minute......... It's funny sometimes, how you never see errors in you code, UNTIL you post the bloody stuff for everyone else. I think that the serial interrupt IS actually working fine. Pseudo operation: - Code in DO/LOOP - Serial interrupt happens - As SerialInt is only a case of "Suck bytes from buffer and stick them in A$", but NO ON-SCREEN OUTPUT OF ANY KIND, once it has done that, it returns to the DO/LOOP to wait for a keypress. I am going to test this now, but I think I am the instrument of my own problems here..... Smoke makes things work. When the smoke gets out, it stops! |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
F--k! Ahem........ Ah, yes, well..... Opps. I changed the SerialInt routine to: SerialInt: A$=Input$(21,#2) Print "RXD." IReturn ...and surprise, surprise - while in the DO/LOOP, if I send more data, I get an "RXD." on the screen... I'm sorry everyone. My problem was that I am very new to interrupts - I have never ever used them before, so I am learning all about this as I go, AND I should have posted the code back in post #1 - someone would have no-doubt picked up on it long before now. Smoke makes things work. When the smoke gets out, it stops! |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
What are you saying? That it was always working but you didn't know it because you didn't actually program it to do something with the data that you as a human could recognise. |
||||
cwilt Senior Member Joined: 20/03/2012 Location: United StatesPosts: 147 |
I see the error now. Program executes down to the loop. While in the loop the interrupt fires and returns to the loop without printing. something like.... do if a$<>"" then print a$ a$="" endif loop until inkey$<>"" |
||||
Grogster Admin Group Joined: 31/12/2012 Location: New ZealandPosts: 9308 |
Pretty much.... It WAS a bug, but it was MY bug. As I said - I am just learning interrupts now for the first time, and I have made a classic schoolboy mistake. However, one learns from one's mistakes - I just hope I don't have too many like that one. Smoke makes things work. When the smoke gets out, it stops! |
||||
BobD Guru Joined: 07/12/2011 Location: AustraliaPosts: 935 |
Don't beat yourself up too much. You weren't the first and you won't be the last. |
||||
Page 1 of 2 |
Print this page |