 | Discussion Forum |  |
|
|
Can variable be accessed in interrupt service function?Simple question!Next Thread | Thread List | Previous Thread Start a Thread | Settings | Details | Message |
|---|
Read-Only Author Perry Liu Posted 8-Aug-2002 03:41 GMT Toolset C166 |  Can variable be accessed in interrupt service function?Simple question! Perry Liu Problem: I use timer interrup to send data to ASC.In timer interrupt function if do like this (eg. S0TBUF = 0xXX),it works.but if do like this (eg. S0TBUF = data2send),There's always 0xff in S0TBUF.My routine has three parts: main.c gt1.c asc.c,variable data2send is defined in gt1.c. So i doubt that data2send can not be accessed in GT1 TIMER3 service routine.
// gt1.c
#include "MAIN.H"
#include "intrins.h"
static unsigned char data2send = 0xfe;
void GT1_vInit(void)
{
T3CON = 0x0006;
T3 = 0x6768; // load timer 3 register
T3IC = 0x005E;
T2CON = 0x0000;
T2 = 0x0000; // load timer 2 register
T4CON = 0x0027;
T4 = 0x6768; // load timer 4 register
T3R = 1; // set timer 3 run bit
}
void GT1_viIsrTmr3(void) interrupt T3INT
{
data2send = _crol_(data2send,1);
S0TBUF = data2send;
}
| | Read-Only Author Mark Odell Posted 8-Aug-2002 15:36 GMT Toolset C166 |  RE: Can variable be accessed in interrupt service function?Simple question! Mark Odell Whenever you share write access between ISR and non-ISR code to a variable you must declare the variable volatile.
volatile static unsigned char data2send;
Don't give this an initial compile time variable as it adds to the size of your ROM image. I suspect this value changes often so why initialize it at compile time?
Remember, you cannot really read back the value of Tx_S0BUF since it points to Rx_S0BUF on reads.
| | Read-Only Author Perry Liu Posted 9-Aug-2002 04:03 GMT Toolset C166 |  RE: Can variable be accessed in interrupt service function?Simple question! Perry Liu I have raveled out the problem,the point is that DAvE 2.0 does not config ADDRSELx and BUSCONx for keil correctly,so routine can't access external ram.After I initiated ADDRSEL1 and BUSCON1 my program worked well.
Thank you for your help,Mark Odell | | Read-Only Author Mark Odell Posted 9-Aug-2002 14:03 GMT Toolset C166 |  RE: Can variable be accessed in interrupt service function?Simple question! Mark Odell You should not need Dave. Are you an embedded developer or not? :-)
I'm sure you can add your own init. code to the Dave generated code to set up these extra bits. | |
Next Thread | Thread List | Previous Thread Start a Thread | Settings |
|