SMAC / Interrupts scrambling Passed Variables
05-21-2007
09:18 PM
2,593 Views

mjcoury
Contributor I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It appears that the interrupts in the SMAC are scrambling the values of passed variabled. This of course is a problem - anyone seen this before and have a fix for it? I assumed that the codewarrior / SMAC demo code had provisions to safely store the register during an interrupt?
Thoughts?
Thanks
Mike
Thoughts?
Thanks
Mike
6 Replies
05-23-2007
02:39 PM
1,193 Views

mjcoury
Contributor I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Anyone? Bueler? Anyone?
05-23-2007
02:59 PM
1,193 Views
Alban
Senior Contributor II
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
You cannot PASS a variable to an interrupt on HC08 and S08.
Interrupts are declared as "void JojoISR(void)".
If content of CPU registers are not saved properly, check the compiler parameters (go into Edit -> TargetName... -> Compiler)
Regards,
Alban.
You cannot PASS a variable to an interrupt on HC08 and S08.
Interrupts are declared as "void JojoISR(void)".
If content of CPU registers are not saved properly, check the compiler parameters (go into Edit -> TargetName... -> Compiler)
Regards,
Alban.
05-23-2007
05:45 PM
1,193 Views

mjcoury
Contributor I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You mis understand - I am passing variables between normal functions, but when an interrupt is fired before the function is called, the passed value that is stored in the HX register is lost forever and is replaced by Junk that was used during the interrupt...
05-24-2007
04:04 AM
1,193 Views

CrasyCat
Specialist III
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello
Are you programming in ANSI C or in Assembler?
Normally when an interrupt occurs, the hardware is saving register A, X, SR, PC on the stack.
Register H is not saved automatically by the hardware.
If you are programming in assembler you need to save H on the stack at the beginning of the interrupt (instruction PSHH) and restore it at the end of the interrupt(instruction PULH).
If you are programming in ANSI C then it depends on the compiler you are using.
CodeWarrior compiler is automatically taking care of saving/restoring the register H is you define your interrupt function using interrupt keyword.
For Example:
interrupt void intFunc(void) {
For other compiler, please check your compiler vendor manual to check whether and how you can make sure register H is saved/ restored in interrupt functions.
I hope this helps.
CrasyCat
05-24-2007
03:02 PM
1,193 Views
Alban
Senior Contributor II
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi CrasyCat,
Funny, I had the same trouble on S12XE with the GPAGE register.
I think you can also put a #pragma SAVE_ALL_REGS before the ISR code. That worked for me.
But on CW HC08 and S08, the PUSHH is systematically done by CW, even if HX is not used in the ISR
Cheers,
Alban.
Funny, I had the same trouble on S12XE with the GPAGE register.
I think you can also put a #pragma SAVE_ALL_REGS before the ISR code. That worked for me.
But on CW HC08 and S08, the PUSHH is systematically done by CW, even if HX is not used in the ISR

Cheers,
Alban.
05-24-2007
04:20 PM
1,193 Views

mjcoury
Contributor I
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Crasy -
I am programming in Codewarrior version 3.0...
and all i know is that while I am using the Real Time Debugger - for some, not all, instances of passing variables... if there is a interrupt called, specifically ones related to SMAC / Zigbee interactions, when the code returns to the step before the JSR in the assembly the values in the Registers are not correct and after the JSR those incorrect values in the register are what end up getting passed / manipulated in my function... my only work around at those point is to use some nasty globals to store the values elsewhere during the JSR / Interrupt period....
I am programming in Codewarrior version 3.0...
and all i know is that while I am using the Real Time Debugger - for some, not all, instances of passing variables... if there is a interrupt called, specifically ones related to SMAC / Zigbee interactions, when the code returns to the step before the JSR in the assembly the values in the Registers are not correct and after the JSR those incorrect values in the register are what end up getting passed / manipulated in my function... my only work around at those point is to use some nasty globals to store the values elsewhere during the JSR / Interrupt period....
