We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello! I've an Timer-Interrupt Routine (timer 3 with reload) with will served every 10 ms! In this Interrupt-Routine, I send 2 Messages via the CAN Interface. Now, I send the second message straight after the first, and the problem is, that the second message won't send in a 10 ms rhytm but often longer (up to 400 ms!). Now I use a global variable, where I decide which message to send; when the value is 0, send the first message, und change the value to 1, then send message 2 and set the value to 0 and so on! I declared an int (I also tried unsigned int, char ...). I have set the value of the variable to 0 in the "main" function, but in the Interrupt Service-Routine, the value ist "FF", and when I try to change to value inside the Interrupt-Service Routine, it has no effect! Is there any other way to transfer data between th "main" and the Interrupt Routine? THX in advance! Have a nice day! SVEN
1. use an unsigned char, it can be updated atomically (in one instruction) by your main() function. If it only needs to be true or false, delcare it as 'bit'. 2. declare the function volatile so that the compiler is forced to reload the variable's contents from RAM each time it is checked in main().
Ex: volatile unsigned char data g_flag;
Um, I didn't notice the 166 toolset, so some of the 8051 biased stuff doesn't apply. Sorry.