AnsweredAssumed Answered

An interruption with KL25Z

Question asked by Max LEF on Jun 15, 2016
Latest reply on Jun 17, 2016 by Max LEF

Hi everyone !

 

I try to do an example of an interrupt without PE. I use a KL25Z.

The program has to do a timer which count to 5seconds, then the interruption turn on the blue LED and the timer restart. The second time, the blue led turn off, and the timer restart and again and again ...

I got some difficult to do this program as a beginner.

 

Could you help me to do it, this is what i did for the moment.

 

#include "MKL25Z4.h"

 

static int i = 0;

void delay(void);

void TPM_Init(void);

void GPIOBlue_Init(void);

uint16_t getTPMCounter(void);

void ResetTPM(void);

 

int main(void)

{

    uint16_t delayTimerTick;

 

    /* Write your code here */

    /* This for loop should be replaced. By default this loop allows a single stepping. */

 

    TPM_Init();

    ResetTPM();

    delay();

    delayTimerTick=getTPMCounter();

    __asm("nop"); //set a break point here

 

    for (;;) {

        i++;

    }

 

    /* Never leave main */

 

    return 0;

 

}

 

void GPIOBlue_Init(void)

{

    SIM_SCGC5 = 0b01011110000000;    // Active l'horloge pour driver les ports A,B et D

    PORTD_PCR1 = 0b00100000000;

    GPIOD_PDDR = 0b10;

    GPIOD_PDOR = 0b10;

}

 

 

 

void TPM_Init(void)

{

    SIM_SCGC6|=0x03000000; //enable FTM0 and FTM0 module clock

    SIM_SCGC5|=0x3E00;

    SIM_SOPT2|=0x1000000; //select TPMSRC clock source as MCGIRCLK clock

    TPM0_CONF=0x00; //set up BDM in 11

    TPM0_MOD=0xFFFF;

    TPM0_C0SC=0x14; //FTM output signal toggle when the FTM counter matches with //C0V registrer

    TPM0_C0V=500;

    TPM0_SC=0x08; // system clock driving, dividing by 1

}

 

void ResetTPM(void)

{

    TPM0_CNT=0x00;

}

 

uint16_t getTPMCounter(void)

{

     uint16_t temp;

     temp=TPM0_CNT;

     return temp;

}

 

void delay(void)

{

    uint16_t delayCounter;

    for(delayCounter=0; delayCounter<1000; delayCounter++)

    {

        __asm("nop");

        __asm("nop");

    }

}

 

//void PORTD_IRQHandler(void)

    //{

        //DelayFunction();

        //GPIOD_PDOR = 0b10;                /*Turn Off Blue Led*/

        //GPIOD_PDOR = 0b00;                /*Turn On Blue Led*/

        //DelayFunction();

        //GPIOD_PDOR = 0b10;                /*Turn Off Blue Led*/

        //DelayFunction();

 

        //PORTD_ISFR = PORT_ISFR_ISF(0x40);        /* Clear interrupt status flag */

    //}

 

    //void DelayFunction(void)

    //{

        //int cnt;

        //for(cnt=0; cnt<1000000; cnt++)

        //{

 

        //}

    //}

Outcomes