AnsweredAssumed Answered

serial communication interrupt for MC9S08DN16 controller

Question asked by vikas subramani on Jul 2, 2014



/*******************************************************************************************************************************/

/* Problem that i am facing is that the interrupt function is getting executed twice instead of just once */

/* and the other problem is that on the screen it indicates that the interrupt function has some syntax error i have included the photo shots */

/* I have also included the screen shots of the result please go through */

/* last updated 7/2/2014 */

/* MC9S08DN16 */

/* The below program is a sample code with the following configuration */

/* SCI enable */

/* 19200 baud rate, 8 data bits, 1stop bit, No parity bit and i am using a 9.8304 MHz external oscillator */

/* Idle wake up */

/* Idle character bit count starts after stop bit */

/* receiver wake up to standby mode */

/* transmitter enable */

/* RS_485 direction set to receive */

/* Interrupt on receiver full */

/* Any problem in the code go through MCU_init(void) function */

/********************************************************************************************************************************/

 

#include <hidef.h>

#include "derivative.h"

void pin_initialization(void);

void UART_initialization(void);

void mode_initialization(void);

void MCU_init(void);

char ReceivedByte, temp;

int flag;

void delay(int i);

 

 

 

 

void main(void)

{

       EnableInterrupts;

       flag = 1;

       pin_initialization();

       mode_initialization();

       UART_initialization();

       MCU_init();

       while(1);

}

 

 

void pin_initialization(void)

{

       PTEDD_PTEDD2 = 1;

       PTEPE_PTEPE2 = 0;

       PTESE_PTESE2 = 0;

       PTED_PTED2 = 0;   // MAX 8032 IC '0' for Reception and '1' for transmission

 

}

 

void UART_initialization(void)

{

/* baud rate generator calculations */

/* Using 9.8304 MHz oscillator hence SBR12:SRB0 = ((bus clk)/(16*baud rate)) ===> ((9830400/2)/(16*19200)) = 16 = ox10 */

 

 

SCI1BDH = 0x00;

SCI1BDL = 0x10;

 

/* configuring register SCI1C1 bit by bit */

 

SCI1C1_PT = 0;

SCI1C1_PE = 0;

SCI1C1_ILT = 1;

SCI1C1_WAKE = 0;

SCI1C1_M = 0 ;

SCI1C1_RSRC = 0;

SCI1C1_SCISWAI = 0;

SCI1C1_LOOPS = 0;

 

/* configuring register SCI1C2 bit by bit */

 

SCI1C2_SBK = 0;                  

SCI1C2_RWU =  0;               

SCI1C2_RE = 1;                  

SCI1C2_TE = 1;                    

SCI1C2_ILIE = 1;                 

SCI1C2_RIE = 1;                  

SCI1C2_TCIE =  0;                

SCI1C2_TIE = 0;

 

/* configuring register SCI1C3  bit by bit */

 

SCI1C3_PEIE = 0;                

SCI1C3_FEIE = 0;              

SCI1C3_NEIE = 0;               

SCI1C3_ORIE = 0;               

SCI1C3_TXINV = 0;                             

SCI1C3_T8 = 0;                   

SCI1C3_R8 = 0;

 

}

 

 

 

/* Changing mode to PBE Mode */

 

void mode_initialization(void)

{

       /* Transition from FEI mode to FBE mode */

      

       MCGC2 = 0x36;

       while (MCGSC_OSCINIT == 0);

       asm SEI;  // Disables all interrupt

       MCGC1 = 0xB8;

       while(MCGSC_IREFST == 1);

       while(!(MCGSC_CLKST == 2));

      

       /* Transition from FBE mode into BLPE mode */

      

       MCGC2 = 0x3E;

       asm CLI;  // Enabled interrupt   

       MCGC1 = 0x98;

       MCGC3 = 0x44;

       while (MCGSC_PLLST == 0);

      

       /* BLPE mode transitions into PBE mode: */

      

       MCGC2_LP = 0;

       while(MCGSC_LOCK == 0);

      

}

 

void delay (int i)

{

       int j,k;

       for(j=0;j<i;j++)

              for(k=0;k<j;k++);

}

 

/* I have used different function name for interrupts as shown below but nothing works

 

__interrupt void Vsci1rx_isr(void)

void interrupt 17 Vsci1rx_isr (void)    

__interrupt 17 Vsci1rx_isr (void)

 

*/

 

void interrupt 17 Vsci1rx_isr (void)

{

       flag++;         // Global variable

       temp = SCI1S1;  // ACK the flags

       ReceivedByte = SCI1D;  // rading the data from the buffer

       SCI1S2_RXEDGIF = 1;    // Clearring the RXEDGIF pin (no effect even if i commented it )

       delay(50);

}

 

 

/* I also used the below commented code it also has same result

 

void interrupt 17 Vsci1rx_isr (void)

{

       temp = SCI1S1;

       ReceivedByte = SCI1D;

       delay(200);

       delay(200);

       ReceivedByte += 1;

       PTED_PTED2 = 1;

       delay(100);

       while (SCI1S1_TDRE == 0);

       SCI1D = ReceivedByte;

       delay(200);

       delay(200);

       delay(200);

       PTED_PTED2 = 0;

 

} */

 

 

void MCU_init(void)

{

        SOPT1_COPT = 0;

        SRS = 0xFF; // Clears watch dog timer

        SPMSC1 = 0x1C;                                     

        /* SPMSC2: LVWF=0,LVWACK=0,LVDV=0,LVWV=0,PPDF=0,PPDACK=0,PDC=0,PPDC=0 */

        SPMSC2 = 0x00;                                     

        /* ICGC1: RANGE=1,REFS=0,CLKS1=0,CLKS0=0,OSCSTEN=1 */

        /* Common initialisation of the CPU registers */

         /* PTASE: PTASE7=0,PTASE6=0,PTASE5=0,PTASE4=0,PTASE3=0,PTASE2=0,PTASE1=0,PTASE0=0 */

         PTASE = 0x00;                                     

         /* PTBSE: PTBSE7=0,PTBSE6=0,PTBSE5=0,PTBSE4=0,PTBSE3=0,PTBSE2=0,PTBSE1=0,PTBSE0=0 */

         PTBSE = 0x00;                                     

         /* PTCSE: PTCSE7=0,PTCSE6=0,PTCSE5=0,PTCSE4=0,PTCSE3=0,PTCSE2=0,PTCSE1=0,PTCSE0=0 */

         PTCSE = 0x00;                                     

         /* PTDSE: PTDSE7=0,PTDSE6=0,PTDSE5=0,PTDSE4=0,PTDSE3=0,PTDSE2=0,PTDSE1=0,PTDSE0=0 */

         PTDSE = 0x00;                                     

         /* PTESE: PTESE7=0,PTESE6=0,PTESE5=0,PTESE4=0,PTESE3=0,PTESE2=0,PTESE1=0,PTESE0=0 */

         PTESE = 0x00;                                     

         /* PTFSE: PTFSE7=0,PTFSE6=0,PTFSE5=0,PTFSE4=0,PTFSE3=0,PTFSE2=0,PTFSE1=0,PTFSE0=0 */

         PTFSE = 0x00;                                     

         /* PTGSE: PTGSE7=0,PTGSE6=0,PTGSE5=0,PTGSE4=0,PTGSE3=0,PTGSE2=0,PTGSE1=0,PTGSE0=0 */

         PTGSE = 0x00;                                     

         /* ### Init_COP init code */

       //   SRS = 0xFF;                          /* Clear WatchDog counter */

 

}




// Please Help me as i am stuck in UART for the past 3 weeks and because of which i am not able to move forward

Attachments

Outcomes