AnsweredAssumed Answered

MPC5604B INTC_InstallINTCInterruptHandler

Question asked by Martin Kehrer on Mar 3, 2016
Latest reply on Mar 4, 2016 by Martin Kovar

Controller crashs always by a PIT0 and/or PIT1 interrupt.

 

#include "MPC5604B.h" #include "IntcInterrupts.h"  void initModesAndClock(void) {   ME.MER.R = 0x0000001D;       CGM.FMPLL_CR.R = 0x02400100;        ME.RUN[0].R = 0x001F0074;         ME.RUNPC[0].R = 0x00000010;       ME.PCTL[16].R = 0x0000;   ME.PCTL[68].R = 0x0000;       ME.PCTL[92].R = 0x0000;           ME.MCTL.R = 0x40005AF0;         ME.MCTL.R = 0x4000A50F;           while (ME.IS.B.I_MTC != 1) {}      ME.IS.R = 0x00000001;           } void initPeriClkGen(void) {   CGM.SC_DC[0].R = 0x80;   CGM.SC_DC[1].R = 0x80;     CGM.SC_DC[2].R = 0x80;   } void disableWatchdog(void) {   SWT.SR.R = 0x0000c520;       SWT.SR.R = 0x0000d928;    SWT.CR.R = 0x8000010A;     }    void Pit0Interrupt(void) {       PIT.CH[0].TFLG.R = 0x00000001;    } void Pit1Interrupt(void) {      PIT.CH[1].TFLG.R = 0x00000001;   } void main() {      /* Init */        initModesAndClock();        initPeriClkGen();         disableWatchdog();                  INTC_InstallINTCInterruptHandler(Pit0Interrupt,59,2); //Channel 0         INTC_InstallINTCInterruptHandler(Pit1Interrupt,60,2); //Channel 1          PIT.PITMCR.R = 0x00000000;        PIT.CH[1].LDVAL.R=64000000;         PIT.CH[0].LDVAL.R=128000000;        PIT.CH[1].TFLG.R = 0x00000001;        PIT.CH[0].TFLG.R = 0x00000001;        PIT.CH[1].TCTRL.R = 0x00000003;        PIT.CH[0].TCTRL.R = 0x00000003;        INTC.CPR.B.PRI = 0;        for(;;)        {         } }

 

Update, but still not working:

#include "MPC5604B.h"   #include "IntcInterrupts.h"      void initModesAndClock(void) {     ME.MER.R = 0x0000001D;    /** EXTERNAL CLOCK */   /** Use external clock from crystal oscillator */   /** Use this crystal oscillator in fast mode */   CGM.FXOSC_CTL.B.OSCBYP = 0u;   /** Disable slow mode for external clock */   CGM.SXOSC_CTL.R = 0u;    /** EXTERNAL CLOCK CONTROL */   /** Disable FMPLL clock monitor */   CGM.CMU_CSR.B.CME_A = 0u;   /** Disable frequency measure */   CGM.CMU_CSR.B.SFM = 0u;   /** The external clock shall be greater than FIRC(16MHz)/divisor_value[1, 2, 4, 8]   * Like external clock is between 4 and 16 MHz so divisor_value = 8.   * This condition is always right   */   CGM.CMU_CSR.B.RCDIV = 3u;    /** PLL COMPUTATION */   /** Disable PLL modulation */   CGM.FMPLL_MR.B.FM_EN = 0u;   CGM.FMPLL_CR.R = 0x02400100;          ME.RUN[0].R = 0x001F0074;           ME.RUNPC[0].R = 0x00000010;         ME.PCTL[16].R = 0x0000;     ME.PCTL[68].R = 0x0000;         ME.PCTL[92].R = 0x0000;               ME.MCTL.R = 0x40005AF0;           ME.MCTL.R = 0x4000A50F;             /** wait transition completed */   while (ME.GS.B.S_MTRANS != 0u) {}   /** check clock = 64MHz is stable */   while (ME.GS.B.S_FXOSC != 1u) {}   /** check that current mode = RUN0 */   while (ME.GS.B.S_CURRENTMODE != 4u) {}            }   void initPeriClkGen(void) {     CGM.SC_DC[0].R = 0x80;     CGM.SC_DC[1].R = 0x80;       CGM.SC_DC[2].R = 0x80;     }   void disableWatchdog(void) {     SWT.SR.R = 0x0000c520;         SWT.SR.R = 0x0000d928;      SWT.CR.R = 0x8000010A;       }      void Pit0Interrupt(void) {    //if( (SIU.PGPDO[0].R & 0x00080000)>0) SIU.PGPDO[0].R &= ~(0x00080000);    //else SIU.PGPDO[0].R |= 0x00080000;   SIU.GPDO[12].B.PDO ^= 1;    if (PIT.CH[0].TFLG.R == 1) PIT.CH[0].TFLG.R = 1; }   void Pit1Interrupt(void) {     //if( (SIU.PGPDO[0].R & 0x00000002)>0) SIU.PGPDO[0].R &= ~(0x00000002);    //else SIU.PGPDO[0].R |= 0x00000002;   SIU.GPDO[30].B.PDO ^= 1;    if (PIT.CH[1].TFLG.R == 1) PIT.CH[1].TFLG.R = 1; }   void main()   {          /* Init */          initModesAndClock();          initPeriClkGen();           disableWatchdog();                     SIU.PCR[12].R = 0x0200;        SIU.PCR[30].R = 0x0200;        SIU.GPDO[12].B.PDO = 0;         SIU.GPDO[30].B.PDO = 0;                INTC_InstallINTCInterruptHandler(Pit0Interrupt,59,2); //Channel 0          INTC_InstallINTCInterruptHandler(Pit1Interrupt,60,2); //Channel 1             PIT.PITMCR.R = 0x00000000;          PIT.CH[1].LDVAL.R=64000000;           PIT.CH[0].LDVAL.R=128000000;          PIT.CH[1].TFLG.R = 0x00000001;          PIT.CH[0].TFLG.R = 0x00000001;          PIT.CH[1].TCTRL.R = 0x00000003;          PIT.CH[0].TCTRL.R = 0x00000003;          INTC.CPR.R = 0u;        for(;;)          {         //Test without Interrupts ok       //if(PIT.CH[0].TFLG.R>0) Pit0Interrupt();       //if(PIT.CH[1].TFLG.R>0) Pit1Interrupt();        }   }  

Outcomes