Join our technical discussions about Freescale Microcontrollers: M68HC12. (Freescale Semiconductor is a Subsidiary of Motorola).
|
Hi all, I was hoping that someone could point me to information they used to learn how to work with interrupts in ICC12. I've been fighting with this for days and can't find any helpful information on the web. Basically, I need: 1) to figure out how to enable and process SCI0 interrupts 2) to figure out how to do the same for timer interrupts 3) and finally, external interrupts. If there is sample code avialable, all the better. So far I've played with my vectors.c file and the asm("cli") command. I haven't had a twitch of success though. I'm sure there is some global mask variable I have to fiddle with, but searching through the 14 PDFs motorola provides offered no hope. BTW, I'm using the DP256 flavor. Thanks all! -Gary ps. help! hehehe |
|
|
|
In a message dated 8/29/02 12:11:13 PM Eastern Daylight Time, writes: > I was hoping that someone could point me to information they used > to learn how to work with interrupts in ICC12. //-------------------------- #pragma nonpaged_function _HC12Setup void _HC12Setup(void){ //init hc12 regs for 128k rom and paging char jnk; // INITRG=0x08; //regs at 0x0800 instead of 0x0000 // INITRM=0x00; //512byte sram at 0x0000-0x03ff instead of 0x0800-0x0c00 COPCTL=0x08; //COP off // COPCTL=0x07; //COP on, 1sec timeout CSCTL0=0x30; //csd, csp0 enab CSCTL1=0x10; //chip select covers half the map CLKCTL=0x00; //8mhz WINDEF=0xc0; //data and prog window enab CSSTR0=0x00; //rom,ram str 0=00 00 1=00 01 4=01 00 5=01 01 8=10 00 9=10 01 a=10 10 b=10 11 CSSTR1=0x00; //cs3,2,1,0 not used #ifdef MX1 PEAR= 0x04; //r/w enab #endif #ifdef MX2 PEAR= 0x0c; //lstrbe and r/w enab #endif #ifdef ROM128 MXAR= 0x01; //a16 enab (128K rom) DPAGE= 0x07; //128k of ram=32 4k pages at 0x7000; flip in 1st 6 pages (24k) 0x2000-0x7fff #endif #ifdef ROM512 MXAR= 0x07; //a18 a17 a16 enab (512K rom) DPAGE= 0x07; //512k of ram=128 4k pages at 0x7000; flip in 1st 6 pages (24k) 0x2000-0x7fff #endif ATDCTL2=0xc0; //atd enab ATDCTL4=0x07; //sample rate ATDCTL5=0x70; //continuous scan, multichannel, 8 ch SC0CR2=0x0c; //rx & tx enab 0c=no int 2c=rx int 1st serial port SC0CR1=0x00; // SC0BDL=13; //38400=13 9600 baud=52 jnk=SC0SR1; //clear rdrf jnk=SC0DRL; //flush rcv buff SC1CR2=0x0c; //rx & tx enab 0x2c =rx int on 2nd serial port SC1CR1=0x00; // SC1BDL=52; //9600 baud=52 jnk=SC1SR1; //clear rdrf jnk=SC1DRL; //flush rcv buff DDRH= 0xff; //outs (lcd data) PORTH=0x00; //porth data lo // DDRT= 0xff; //outs // PORTT=0x00; //portt data lo DDRJ=0xf8; //5 out, 3 in (encoder and switch) PORTJ=0x18; //outs lo (cs1*, cd, rw, en, cs0*, i, i, i) PUPSJ=0x07; //pullups on lsbs (inputs) PULEJ=0x07; //enable pullups // KWIEJ=0x02; //bottom 2 bits RTICTL=0xc1; //0xc1,2,3,4,5=1,2,4,8,16ms 0xc1=1.024ms interrupt RTIFLG=0x80; //clear rtiflg TSCR=0x80; //timer enable TIOS=0x00; //all 8 ic enable TCTL3=0x02; //ic4=falling edge TCTL4=0xbe; //ic3=falling ic2=either ic1=either (encoder) ic0=falling (fuel flow) TMSK1=0x1f; //ic4,3,2,1,0 int enab TFLG1=0x1f; //clear ic flags TMSK2=0xb0; //tof int enab, t pull up enab TFLG2=0x80; //clear tof flag } //---------------- int kbhit(void){ //check for char in sci (polled version) return(SC0SR1 & 0x20); } #if 0 //---------------- int kbhit(void){ //check for char in 1st sci (int version) return(rx0indx != rx0ondx); } #endif #if 0 //---------------- int kbhit2(void){ //check for char in 2nd sci (int version) return(rx1indx != rx1ondx); } #endif //#if 0 //---------------- int kbhit2(void){ //check for char in 2nd sci (polled version) return(SC1SR1 & 0x20); } //#endif #if 0 //------------------ int getchar(void){ //get a char from 1st sci (int version) char c; while(!kbhit()){}; //wait c=rx0buf[rx0ondx++]; if(rx0ondx==500) rx0ondx=0; return(c); } #endif #if 0 //------------------ int getchar(void){ //get a char from 1st sci (polled version) (also a version in rtlib) char c; while(!kbhit()){}; //wait c=SC0DRL; return(c); } #endif #if 0 //------------------ char getchar2(void){ //get a char from 2nd sci (int version) char c; while(!kbhit2()){}; //wait c=rx1buf[rx1ondx++]; if(rx1ondx==500) rx1ondx=0; return(c); } #endif //#if 0 //------------------ char getchar2(void){ //get a char from 2nd sci (polled version) while(!kbhit2()){}; //wait return SC1DRL; } //#endif //------------------ void putchar2(char c){ //send c out rs232 2 while((SC1SR1 & 0x80)==0){}; //wait for tdre SC1DRL=c; //send char } //--------------------- #pragma nonpaged_function dumppc void dumppc(void){ //dump pc from saved user stack. no stack fram asm("ldd 9,SP"); //get old pc from stack rtn addr at sp+7, 2 more for call asm("std _tmp"); putwordhex(tmp); c=getchar(); //wait for keystroke _start(); //restart } //----interrupt handlers----------------- #pragma interrupt_handler DUMMY_ENTRY void DUMMY_ENTRY(void){ puts("unexpected interrupt!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler ffc0hdr void ffc0hdr(void){ //ffc0 handler puts("ffc0!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler rtihdr void rtihdr(void){ unsigned int tmp; tics++; //bump tics asm(" sts %tmp"); //grab stack pointer if(tmp < minstk) minstk=tmp; //remember minimum stack depth RTIFLG=0x80; //clear interrupt flag // putchar('r'); } #pragma interrupt_handler portjhdr void portjhdr(void){ //key wakeup on port j puts("portj!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler atdhdr void atdhdr(void){ //atd handler puts("atd!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler sci1hdr void sci1hdr(void){ //2nd sci int handler char stat,c; stat=SC1SR1; c=SC1DRL; rx1buf[rx1indx++]=c; if(rx1indx==500) rx1indx=0; // puts("sci1!"); // while(1){}; //hang up } #pragma interrupt_handler sci0hdr void sci0hdr(void){ //sci0 handler char stat,c; stat=SC0SR1; c=SC0DRL; rx0buf[rx0indx++]=c; if(rx0indx==500) rx0indx=0; // puts("sci0!"); // while(1){}; //hang up } #pragma interrupt_handler spihdr void spihdr(void){ //spi handler puts("spi!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler tofhdr void tofhdr(void){ //tof handler tofs++; //bump tofs TFLG2 =0x80; //clear interrupt flag // puts("tof!"); // while(1){}; //hang up // putchar('t'); } #pragma interrupt_handler ic7hdr void ic7hdr(void){ //ic7 handler puts("ic7!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler ic6hdr void ic6hdr(void){ //ic6 handler puts("ic6!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler ic5hdr void ic5hdr(void){ //ic5 handler puts("ic5!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler ic4hdr void ic4hdr(void){ //ic4 handler (left mag pulse) tic4=TC4; //read timer curcnt4=(tofs << 16)+tic4 ; //250ns timer tics ticsperbang4=curcnt4-startcnt4; //number of tics between mag bangs startcnt4=curcnt4; //remember endcnt as startcnt ic4tics++; TFLG1=0x10; //clear ic4 // puts("ic4!"); // while(1){}; //hang up } #pragma interrupt_handler ic3hdr void ic3hdr(void){ //ic3 handler (right mag pulse) tic3=TC3; //read latched timer count curcnt3=(tofs << 16)+tic3; //250ns timer tics ticsperbang3=curcnt3-startcnt3; //number of tics between mag bangs startcnt3=curcnt3; //remember endcnt as startcnt ic3tics++; TFLG1=0x08; //clear ic3 // puts("ic3!"); // while(1){}; //hang up // putchar('3'); } #pragma interrupt_handler ic2hdr void ic2hdr(void){ //ic2 handler (encoder edge) readencoder(); TFLG1=0x04; //clear ic2 // puts("ic2!"); // while(1){}; //hang up putchar('e'); } #pragma interrupt_handler ic1hdr void ic1hdr(void){ //ic1 handler (encoder edge) readencoder(); TFLG1=0x02; // puts("ic1!"); //clear ic1 // while(1){}; //hang up putchar('f'); } #pragma interrupt_handler ic0hdr void ic0hdr(void){ //ic0 handler from fuel flow counter //33333 counts/gal counts every few ms fftics++; TFLG1=0x01; //clear ic0 // puts("ic0!"); // while(1){}; //hang up // putchar('g'); } #pragma interrupt_handler irqhdr void irqhdr(void){ //unvectored irq handler puts("irq!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler xirqhdr void xirqhdr(void){ //xirq handler puts("xirq!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler swihdr void swihdr(void){ //swi handler puts("swi!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler illophdr void illophdr(void){ //illop handler puts("illop!"); dumppc(); // while(1){}; //hang up } #pragma interrupt_handler cophdr void cophdr(void){ //cop handler puts("cop!"); dumppc(); // while(1){}; //hang up } //---interrupt vectors--------------------------- #pragma abs_address:0xffc0 void (*interrupt_vectors[])(void)={ ffc0hdr, // ffc0 DUMMY_ENTRY, // ffc2 DUMMY_ENTRY, // ffc4 DUMMY_ENTRY, // ffc6 DUMMY_ENTRY, // ffc8 DUMMY_ENTRY, // ffca DUMMY_ENTRY, // ffcc DUMMY_ENTRY, //k wu H ffce portjhdr, //K wu J ffd0 atdhdr, //ATD ffd2 sci1hdr, //SCI 1 ffd4 sci0hdr, //SCI 0 ffd6 spihdr, //SPI ffd8 DUMMY_ENTRY, //PAIE ffda DUMMY_ENTRY, //PAO ffdc tofhdr, //TOF ffde ic7hdr, //TC7 ffe0 ic6hdr, //TC6 ffe2 ic5hdr, //TC5 ffe4 ic4hdr, //TC4 ffe6 ic3hdr, //TC3 ffe8 ic2hdr, //TC2 ffea ic1hdr, //TC1 ffec ic0hdr, //TC0 ffee rtihdr, //RTI fff0 irqhdr, //IRQ fff2 xirqhdr, //XIRQ fff4 swihdr, //SWI fff6 illophdr, //ILLOP fff8 cophdr, //cop fffa DUMMY_ENTRY, //CLM fffc _start //RESET fffe }; #pragma end_abs_address //------eof--------------- I've been fighting > > with this for days and can't find any helpful information on the > web. Basically, I need: > 1) to figure out how to enable and process SCI0 interrupts > 2) to figure out how to do the same for timer interrupts > 3) and finally, external interrupts. > > If there is sample code avialable, all the better. So far I've > played with my vectors.c file and the asm("cli") command. I haven't > had a twitch of success though. I'm sure there is some global mask > variable I have to fiddle with, but searching through the 14 PDFs > motorola provides offered no hope. BTW, I'm using the DP256 flavor. [Non-text portions of this message have been removed] |
|
Gary I posted some code yesterday related to interrupts and timers, you might find some help there. One of the most common mistakes is reading and writing the interrupt flag register for all the bits instead of just writing to a specific bit. Writing all the flags (masking and re-writing) will clear any interrupts pending. Try using NOICE (HC12 debugger) to breakpoint the code, you can download a trial version at www.noicedebugger.com <http://www.noicedebugger.com> Bob -----Original Message----- From: garydion [mailto:] Sent: Thursday, August 29, 2002 9:09 AM To: Subject: [68HC12] Desperately need help with interrupts Hi all, I was hoping that someone could point me to information they used to learn how to work with interrupts in ICC12. I've been fighting with this for days and can't find any helpful information on the web. Basically, I need: 1) to figure out how to enable and process SCI0 interrupts 2) to figure out how to do the same for timer interrupts 3) and finally, external interrupts. If there is sample code avialable, all the better. So far I've played with my vectors.c file and the asm("cli") command. I haven't had a twitch of success though. I'm sure there is some global mask variable I have to fiddle with, but searching through the 14 PDFs motorola provides offered no hope. BTW, I'm using the DP256 flavor. Thanks all! -Gary ps. help! hehehe Yahoo! Groups Sponsor ADVERTISEMENT <http://rd.yahoo.com/M=229441.2311215.3726473.2225242/D=egroupweb/S=17065542 05:HM/A=1189560/R=0/*www.bmgmusic.com/acq/ee/q6/enroll/mhn/10/> -------------------------------------------------------- To unsubscribe from this group, send an email to: To learn more about Motorola Microcontrollers, please visit http://www.motorola.com/mcu <http://www.motorola.com/mcu > . [Non-text portions of this message have been removed] |
|
Hey all, Frist off, thank you Bob and Bob (in no particular order) for responding to my plea. As it turns out, I was setting a value for my SCI0CR2 register before calling "setbaud", which I just reliazed turns right around and clears my interrupt bit. I have now reversed the operation and just -or- my interrupt bit onto the register. Now my interrupt handler is doing it's job. Thanks again! -Gary --- In 68HC12@y..., "garydion" <gdion@e...> wrote: > > Hi all, > > I was hoping that someone could point me to information they used > to learn how to work with interrupts in ICC12. I've been fighting > with this for days and can't find any helpful information on the > web. Basically, I need: > 1) to figure out how to enable and process SCI0 interrupts > 2) to figure out how to do the same for timer interrupts > 3) and finally, external interrupts. > > If there is sample code avialable, all the better. So far I've > played with my vectors.c file and the asm("cli") command. I haven't > had a twitch of success though. I'm sure there is some global mask > variable I have to fiddle with, but searching through the 14 PDFs > motorola provides offered no hope. BTW, I'm using the DP256 flavor. > > Thanks all! > -Gary > > ps. help! hehehe |
|
I wrote an article on this subject: http://www.seattlerobotics.org/encoder/sep98/68hc12intr.html Kevin ----- Original Message ----- From: "garydion" <> To: <> Sent: Thursday, August 29, 2002 9:09 AM Subject: [68HC12] Desperately need help with interrupts > > Hi all, > > I was hoping that someone could point me to information they used > to learn how to work with interrupts in ICC12. I've been fighting > with this for days and can't find any helpful information on the > web. Basically, I need: > 1) to figure out how to enable and process SCI0 interrupts > 2) to figure out how to do the same for timer interrupts > 3) and finally, external interrupts. > > If there is sample code avialable, all the better. So far I've > played with my vectors.c file and the asm("cli") command. I haven't > had a twitch of success though. I'm sure there is some global mask > variable I have to fiddle with, but searching through the 14 PDFs > motorola provides offered no hope. BTW, I'm using the DP256 flavor. > > Thanks all! > -Gary > > ps. help! hehehe > > -------------------------------------------------------- > To unsubscribe from this group, send an email to: > To learn more about Motorola Microcontrollers, please visit > http://www.motorola.com/mcu |