interrupts messin' with vsprintf ?

I have a 1ms fixed time interrupt scanning and debouncing a couple of switches, and a 1200 baud port receiving blocks of 17 chars 4 times a sec.
Asynchronously at 5 times/sec, I'm assembling an 8 character string to display on an 8 character DM display.
This code now uses a vsprintf statement, and occasionally the output string gets leftshifted one character in the buffer.
Surrounding the vsprintf call by EA=0 and EA=1 solves the problem, but the resulting delay to my fixed time interrupt messes up the switch scan.
Anybody have any clues on why vsprintf is getting upset, and how to get around it?
Thanks in advance.

Parents
  • Julian,

    Without knowing the specifics of what interrupts that you are using and how they are set up, this may or may not help. My first guess, based on the fact that the problem only occurs sometimes and disabling interrupts removes the problem, is the timer ISR is being interrupted by another ISR or vice versa. You should be able to eliminate this problem by making sure that the timer that is critical to your switch scan is set to the highest possible priority and that it uses a register bank that is not used by any other ISRs (or at least any ISR that have the same or higher priority) or functions in your code. Also, if the vsprintf() is being called from the ISR, you may want to see if you can come up with a scheme to get this pulled out of there. It uses variable arguements, can be time consuming and could cause a variety of stack and state problems that would not be a problem outside of an ISR. I can come up with some other possibilities if this doesn't help any. If this is the case, please include whether code is SMALL, COMPACT or LARGE, what other interrupts you are using, and if you are using any directives or pragmas that effect function calling such as NOAREGS, MAXARGS set to a small value, etc.

    First time that I have offered my two cents and I hope it is helpful. I have never participated in any discussion forums and I am therefore not familiar with the etiquette or proper protocol of responding. Please let me know if this reply is not appropriate in any way whatsoever.

    Brian

Reply
  • Julian,

    Without knowing the specifics of what interrupts that you are using and how they are set up, this may or may not help. My first guess, based on the fact that the problem only occurs sometimes and disabling interrupts removes the problem, is the timer ISR is being interrupted by another ISR or vice versa. You should be able to eliminate this problem by making sure that the timer that is critical to your switch scan is set to the highest possible priority and that it uses a register bank that is not used by any other ISRs (or at least any ISR that have the same or higher priority) or functions in your code. Also, if the vsprintf() is being called from the ISR, you may want to see if you can come up with a scheme to get this pulled out of there. It uses variable arguements, can be time consuming and could cause a variety of stack and state problems that would not be a problem outside of an ISR. I can come up with some other possibilities if this doesn't help any. If this is the case, please include whether code is SMALL, COMPACT or LARGE, what other interrupts you are using, and if you are using any directives or pragmas that effect function calling such as NOAREGS, MAXARGS set to a small value, etc.

    First time that I have offered my two cents and I hope it is helpful. I have never participated in any discussion forums and I am therefore not familiar with the etiquette or proper protocol of responding. Please let me know if this reply is not appropriate in any way whatsoever.

    Brian

Children
More questions in this forum