Help for SCI interrupt MC9S12

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Help for SCI interrupt MC9S12

7,814 次查看
gautier
Contributor II
Hello
 
I use codewarrior (with C language), a evaluationboard with a MC9S12DP512 and a P&E bdm mulitlink
 
I 've make a program to blinking a LED, it's OK
I've runnig this program with the PLL (48MHz), it's OK
I''ve put in the main the code to send a caracter to the SCI port, it's OK
BUT
I want to use the SCI port with interrupt, typically, I want to blinking the LED but if a 'A' caractere arrive on the SCI port I want to stop the blinking.
 
I don't arrive to use the interrupt.
 
Can someone help me to use the interrupt??
 
for the SCI.c
#include "datatypes.h"
//#include "hcs12dp256.h"
#include <mc9s12dp512.h>     /* derivative information */
#include "s12_sci.h"
//-- Code ---------------------------------------------------------------------
void initSCI0(UINT16 bauddiv) {
/*
 before install the PLL with a 16 MHz quartz
 SCI0BD  = bauddiv & 0x00A3; // baudrate divider has 13 bits
*/
 // I have running the PLL at 48MHz so the baud rate is different
 SCI0BD  = bauddiv & 0x1fff; // baudrate divider has 13 bits
 SCI0CR1 = 0;    // mode = 8N1
 SCI0CR2 = BM_TE+BM_RE;  // Transmitter + Receiver enable
 }
//-----------------------------------------------------------------------------
UINT8 getSCI0(void) {
 while((SCI0SR1 & BM_RDRF) == 0) ;
 return SCI0DRL;
 }
//-----------------------------------------------------------------------------
void putSCI0(UINT8 c) {
 while((SCI0SR1 & BM_TDRE) == 0) ;
 SCI0DRL = c;
 }
 
 
*****************************************************************************
*****************************************************************************
 for the main:
 
#include <hidef.h>      /* common defines and macros */
#include <mc9s12dp512.h>     /* derivative information */
#include "s12_crg.h"
#include "s12_sci.h"

#pragma LINK_INFO DERIVATIVE "mc9s12dp512"
UINT8 entree_SCI;
// some simple delay routines
//
void delay1(void) {
 volatile unsigned n = 36000u;
 do {
  n--;
  } while(n);
 }
void delay2(void) {
 volatile unsigned n, m;
 m = 3;
 do {
  n = 0;
  do {
   n--;
   } while(n);
  m--;
  } while(m);
 }
//-----------------------------------------------------------------------------
// program entry is here:
//
void main(void) {
 unsigned char k,m;
 EnableInterrupts;
 initPLL();
 // initSCI0(1);
 SCI0BD  = 0x0027;// baudrate divider has 13 bits
  SCI0CR1 = 0;    // mode = 8N1
 SCI0CR2 = BM_TE+BM_RE;  // Transmitter + Receiver enable
 
 PORTB = 0xff;
 DDRB = 0xff;
   PTP = 0;
   DDRP = 0x03;
 m = 0;
 while(1) {
  k = 0x80;
  do {
   PORTB &= ~k; // LED on
   delay1();
   PORTB |= k;  // LED off
   k >>= 1;
   } while(k);
  if(++m==4) m = 0;
  PTP = m;
  k = 0x01;
  do {
   PORTB &= ~k; // LED on
   delay1();
   PORTB |= k;  // LED off
   k <<= 1;
   } while(k);
  delay2();
 // entree_SCI= getSCI0();
  putSCI0('a');
  
  }
 }

 
 
Thanks for your Help!!!!
I'm realy desapointed
 
Escuse me for spelling mistake, I'm french.
 
标签 (1)
0 项奖励
回复
4 回复数

1,395 次查看
armitron
Contributor I
Hi,

I am also trying to use SCI (for MC9S12C32) for my program to receive data from an RFID Reader. I tried looking at the way you declare/initialize the data registers and status, but when I run the program, an illegal_bp error occurs.

i.e.

#include
#include


void main(void){

for(;:smileywink:{

SCICR1 = 0x03;
SCICR2 = 0xB4;
SCIBDL = 0x34;
SCIBDH = 0x00;


//codes

}
}

I am wondering if those SCI registers should be place there or before the main or outside the for loop and after the main.

Much help would be appreciated!

- New to CW
0 项奖励
回复

1,395 次查看
gautier
Contributor II

OK thanks a lot for your answers.

But I have discover a other option: it's to use the HCS12 software stationery (AN2485/D) of freescale.

There are a exemple of this application for serial communication  It's working wonderfull.

I think I can be able to use it for my application.

If someone want to use the serial port I think it can be interresant.

By

0 项奖励
回复

1,395 次查看
imajeff
Contributor III
I don't see that you have began to write your program to use interrupts. Have you read basically how to use interrupts?

Helpful tidbits (answers are documented):
  • When does an interrupt get called
  • Vectors table
  • How to define a function as interrupt
  • Sharing variable between interrupt and non-interrupt routines

Ok good use of color in your post, but I hope you'll learn another HTML tag: PRE
It is a great HTML tag
because it lets you cut & paste pre-formatted code.
<pre> pasted code </pre> example:
/* Wait 'ms' milliseconds (not accurate (:- (:-), hand adjusted
   and based on human time accuracy (understand, SCz feeling).  */
void
delay_ms (unsigned ms)
{
  unsigned short tcnt;

  while (ms > 0)
    {
      unsigned i;
     
      for (i = 100; --i != 0;)
        tcnt = get_timer_counter ();

      ms--;
    }
}
0 项奖励
回复

1,395 次查看
desponia_
Contributor I
Dear warrior
 
i m implementing your wishes by using following codes. you can use the same way
 
when you send information by using SCI it is useful not to use interrupt. when you take information from SCI interface it is better to use interrupt.
 
this is initalization function; fbus=12 Mhz by using PLL
 
SCI0BDH = 0x00;
SCI0BDL = baud;    //  for 9600 baud rate, these are baud rates must be send.   
                               //  for 24 Mhz   156,0x9C
                                //  for 12 Mhz 78, 0x4E
                               //  for 8  Mhz   52, 0x34
                              //  for 4  Mhz   26, 0x1A
SCI0CR1 = 0x40;   // LOOPS,WOMS,RSRC,M,WAKE,ILT,PE,PT
                              // sci disable in wait,parity disable,odd parity
SCI0CR2 = 0x2C;   // TIE,TCIE,RIE,ILIE,TE,RE,RWU,SBK
                             // rxfull or int enable, ,transmitter enable,receiver enable
 
and this my sci receive interrupt subroutine; 
 
void _sci0ISR( void )
{
  UBYTE scicr2,scisr1;
  
  LCD[1][10]='R';
  PTP_PTP7=~PTP_PTP7;
 
  scisr1 = SCI0SR1;      // save status register actual status
  scicr2 = SCI0CR2;     // save control register actual status
  //--- if transmission data reg. empty interrupt is enabled and corresponding interrupt flag is set
  if ((scicr2 & SCI0CR2_SCTIE_MASK) && (scisr1 & SCI0SR1_TDRE_MASK))
  { 
    SCI0DRL = sci0_data_out;
  }
  //--- if transmission complete interrupt is enabled and corresponding interrupt flag is set
  if ((scicr2 & SCI0CR2_TCIE_MASK)  && (scisr1 & SCI0SR1_TC_MASK))  
  { 
    SCI0DRL = sci0_data_out;                // send data and clear interrupt flag
  }
  //--- if receiver interrupt is enabled and corresponding interrupt flag is set
  if((scicr2 & SCI0CR2_RIE_MASK)    && ((scisr1 & (SCI0SR1_OR_MASK | SCI0SR1_RDRF_MASK))))
  {
    if(scisr1 & SCI0SR1_OR_MASK)            // if overrun error do nothing/something
    {
       SCI0DRL;                            // clear interrupt flag
       // do something
    }
    else
    {
       sci0_data_in = SCI0DRL;             // read received character + clear interrupt flag
       //PORTB = sci0_data_in;               // show received data on port B
       SCIRX[scireadcounter]= sci0_data_in;
       LCD[1][13]= sci0_data_in;           
       //SCI0DRL= sci0_data_in;              // echo received data
       scireadcounter++;
     
    
       
    }
  } 
}//*********** sci0 kesme altprogrami sonu************************************/  
i hope these would be helpful for you
 
best regards.
0 项奖励
回复