SCI interrupts on CSM12C32 module

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

SCI interrupts on CSM12C32 module

1,732 Views
ersinozkan
Contributor I

hello,

 

I am trying to read data from sci by handling  RDRF interrupt. i had some trouble with it and then i found sample source codes from Internet. also i tried the sample project which is in code-warrior examples.

 

1) Codewarrior provides an example project for mc9s12c32.  it uses vector table in isr_vectors.c

 

typedef void (*near tIsrFunc)(void);
const tIsrFunc _vect[] @0xFF80 = {
.....

}

 

i tried same way in my project but i couldn't handle any sci interrupts.

 

2) i checked code-warrior help. it gives two way to use interrupts.

define

VECTOR ADDRESS 0x8A INCcount

or

VECTOR 69 INCcount

in prm file then use

 

interrupt void INCcount() ..

or

#pragma TRAP_PROC

void INCCount()  ..

 

 or directly use

interrupt 69 void INCcount(void) ...

 

when i try defining vectors in prm file, something strange is happening. when i send a byte to mcu i get back '0xE0  0xF2  0x3E'  messages in endless loop.

 

3) i have found a source code from my school. they are using it on the same module i have.

i checked the code and they are handling IRQ interrupt not SCI. IRQ is vector 6 and SCI is vector 20. i didn't have time to ask about this. i read all data-sheets again and again but no answer.

 

also there is  a weird thing about their code. they use vector table for interrupt definitions. what that code do is transmitting the received byte back by appending it to a message "you send a byte ...".

for the first byte i send, mcu handles interrupt but always sends back  'a', smiley face and '>'.

sometimes after i send a new byte, it sends back previous byte.

 

also i edited that code a bit. i am turning led1 on and off each almost each second. until i send a byte to mcu led blinks very well. but after the first byte i send blinking stops and never starts again.

 

and i am changing the state of led2 in interrupt function. it must be turn off after nth interrupt and turn on n+1th interrupt. but what happens is in turns off and  on (very fast blinking) in one interrupt.

 

 

i hope I'm missing a simple point.

 

waiting for all ideas and working source codes if possible.

 

have a nice day

Labels (1)
0 Kudos
Reply
4 Replies

663 Views
Lundin
Senior Contributor IV

I would strongly recommend using this code for vector table declarations:

 

https://community.freescale.com/message/59586#59586

0 Kudos
Reply

663 Views
Covenant
Contributor I

I have exactly the same error, i have been searching and trying codes from internet, but the error is the same. what is wrong?

 

Regards

0 Kudos
Reply

663 Views
ersinozkan
Contributor I

here is one of my source code

 

 

#include <hidef.h>      /* common defines and macros */
#include <mc9s12c32.h>     /* derivative information */
#pragma LINK_INFO DERIVATIVE "mc9s12c32"

byte interrupt_counter = 0;
int x,y;
byte dummy;
   
#pragma TRAP_PROC
void SCI_ISR(void) {
    if( (SCISR1 & 0b00000111) ){
        dummy = SCIDRL;
        return;   
    }
   
    if( (SCISR1 & 0b00101000) ){
        dummy = SCIDRL;
        interrupt_counter++;
        while (!(SCISR1 & 0x80));  // wait for output buffer empty
        SCIDRL = interrupt_counter + '0' ;
    } 
   
    if((interrupt_counter % 2) == 0)
        PORTA = 0x01;         
    else
        PORTA = 0x00;
   
    x=0;
    y=0;
}                               

/*
interrupt 6 void SCI_ISR(void) {
    byte dummy;
    if( (SCISR1 & 0b00000111) ){
        dummy = SCIDRL;
        return;   
    }
   
    if( (SCISR1 & 0b00101000) ){
        dummy = SCIDRL;
        interrupt_counter++;
        while (!(SCISR1 & 0x80));  // wait for output buffer empty
        SCIDRL = interrupt_counter + '0' ;
    } 
   
    if((interrupt_counter % 2) == 0)
        PORTA = 0x01;         
    else
        PORTA = 0x00;
}                               
*/

#pragma CODE_SEG DEFAULT        
void main(void) {
  /* put your own code here */

  EnableInterrupts;

  DDRA = 0x01;
 
  SCIBDH = 0x00;
  SCIBDL = (unsigned char)((16000000UL /* OSC freq */ / 2) / 9600 /* baud rate */ / 16 /*factor*/);
  SCICR1 = 0x00;
  SCICR2 = 0x2C;

  for(;;) {
      for(x=0;x<100;x++){
          for(y=0;y<10000;y++){
          }
      }
     
      while (!(SCISR1 & 0x80));  /* wait for output buffer empty */
      SCIDRL = 'x';
     
  } /* wait forever */
  /* please make sure that you never leave this function */
}

 i also have

 

VECTOR 6 SCI_ISR

 

line in prm file. 6 is for IRQ. it has to be 20 for SCI interrupts but it doesnt work.

 

 

as you see, i send 'x' chars in main loop. but after interrupt subroutine, it stops.

anything i am missing ?

 

 

also, adding full project in zip format.

 

 

 

0 Kudos
Reply

663 Views
ersinozkan
Contributor I

i checked the manual for HCS12 serial monitor program and pasting some info from it to here:

 

For the serial port function of the monitor to work, the SCI0 serial interface is
used. The monitor must have exclusive use of this interface. User application
code should not implement communications on this serial channel.
This monitor accommodates RS-232 serial communications through SCI0 at
115.2 kbaud. For systems requiring the use of SCI0, use a BDM development
system that allows more sophisticated debugging. Alternatively, this monitor
program may be modified by the user to check the state of the switches used
to enter the monitor and adjust vector relocation accordingly. This modification
would enable the user to use the monitor SCI port, although debugging of SCI0
routines would be very difficult or impossible using the monitor.

 

Is my problem related to this? if so, what can i do now?

0 Kudos
Reply