Yes, and it's rather simple. DI (); // entering critical section EI (); // ISR can use them now. Andy Michael Rigby-Jones on 11/06/2000 09:46:54 AM Please respond to pic microcontroller discussion list To: PICLIST@MITVMA.MIT.EDU cc: (bcc: Andrew Kunz/TDI_NOTES) Subject: [PIC]: Multibyte words and Interrupts If I have a main loop that uses a lot of 16 and 32 bit variables which need to be accessed (but not changed) in the ISR for sending the values accross an I2C bus. Is there a good way to ensure a whole word has been loaded before an Interrupt is serviced? i.e. if a 16 bit word is being updated in the main loop, this will obviously take at least 2 operations, probably more like 4. If an interrupt occurrs in the middle of this, the word will neither contain the new value or the old value, but a bit of each, which is obvioiusly undesirable. Switching off interrupts for every multibyte operation dosen't seem very practical. I'm thinking that maybe I should double buffer the variables I'm interested in, and only use the buffered copies in the ISR... e.g. int a,b,c,d; int buff_a,buff_b,buff_c,buff_d; void main() { while(1) { /* lots of 16/32 bit operations in main loop */ a = (b*c)+d; /* etc....etc....*/ /* end of loop */ while(GIE) GIE = 0; /* disable interrupts */ buff_a = a; /* copy variables to buffers */ buff_b = b; buff_c = c; buff_d = d; GIE = 1; /* enable interrupts */ } } So, what I would like to know is if there a better way of doing things that dosen't use so much RAM? Cheers Mike -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! use mailto:listserv@mitvma.mit.edu?body=SET%20PICList%20DIGEST -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! use mailto:listserv@mitvma.mit.edu?body=SET%20PICList%20DIGEST