About 9S12 CAN bus wake function

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

About 9S12 CAN bus wake function

Jump to solution
1,662 Views
jinchengxie
Contributor I

When using chip is the MC9S12XE256, I met a problem.

As datasheet said:"The MSCAN can recover from stop or wait via the wake-up interrupt. This interrupt can only occur if the MSCAN was in sleep mode (SLPRQ = 1 and SLPAK = 1) before entering power down mode, the wakeup option is enabled (WUPE = 1), and the wake-up interrupt is enabled (WUPIE = 1)."   (P656 16.4.7.7)

But I configuration register,The code can not jump to VectorNumber_Vcan1wkup.in other words,System after entering the stop or wait mode,and To send data through the CAN analyzer, CAN't wake up.what's the problem?How to can bus into sleep or power down mode when no activity,and Can bus has activities when wake up again?Please provide code as much as possible.Thanks!

The key code as shown below. The code as shown in attachment.

 

Regards,

xjc

 

 

#include"mc9s12xet256.h"

#include  "mmi.h"

#include "dal_gpio.h"

#define SYNR_NUM             9                                    

#define REFDV_NUM            1                                     

#define  TEST_PIN            GPIOE, GPIO_Pin_4

#define  IO_GSM_POWER_EN       GPIOA, GPIO_Pin_5

#define  IO_GSM_POWER_KEY      GPIOA, GPIO_Pin_4

 

 

static void mmi_ppl_init(void)

{

    CLKSEL_PLLSEL = 0;

    PLLCTL_PLLON = 1;                                                                                                               

// f(vco) = 2 * f(osc) * (SYNR + 1) / (REFDV + 1) */

    SYNR = 0xC0 | SYNR_NUM;                                                  

    REFDV = 0x80 | REFDV_NUM;                                                

    POSTDIV = 0x00;

    _asm(nop);                                                               

    while (!CRGFLG_LOCK) {                                                   

        ;

    }

    CLKSEL_PLLSEL = 1;                                                       

}

 

 

static void mmi_CPU_Gotostop(void)

{

    __asm ANDCC #0x7F;

    CLKSEL_PLLSEL = 0;

    __asm STOP;

}

static void mmi_CPU_Gotowait(void)

{

    __asm WAI;

}

 

 

 

 

void main(void)

{

     mmi_ppl_init();

  

     CAN1TIER = 0x00;                                                        

     CAN1RIER = 0x01;                                                     

     CAN1RFLG_RXF = 1;                                                        

     CAN1CTL0_CSWAI = 0;                                                     

     CAN1CTL0_WUPE = 1;                                                       

     CAN1RIER_WUPIE=1;

     CAN1RFLG_WUPIF =1;

   

     EnableInterrupts;

   

     CreateOutputPort(TEST_PIN); 

     WriteOutputPort(TEST_PIN, true);

 

 

      _asm nop;

      _asm nop;

      _asm nop;

      _asm nop;

      _asm nop;

    

     CAN1CTL0_SLPRQ=1;

  // CAN1CTL1_SLPAK=0;

     while( !CAN1CTL1_SLPAK);

   

   //   mmi_CPU_Gotowait();

    mmi_CPU_Gotostop(); 

         

     while(1)

     {

         CAN1CTL0_SLPRQ=0;

      // CAN1CTL1_SLPAK=0;      

         WriteOutputPort(TEST_PIN, false);     

     }        

  

}

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

#pragma CODE_SEG __NEAR_SEG NON_BANKED

static void interrupt  VectorNumber_Vcan1wkup  CAN1_Wkup_interrupt(void)

{

    CAN1RFLG_WUPIF =1;

}

#pragma CODE_SEG DEFAULT_ROM

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

 

 

#pragma CODE_SEG __NEAR_SEG NON_BANKED

static void interrupt VectorNumber_Vcan1rx CAN1_Rx_interrupt(void)

{

    CAN1RFLG = 0x01;                                                      

}

#pragma CODE_SEG DEFAULT_ROM

Original Attachment has been moved to: main[1].c.zip

Labels (1)
0 Kudos
Reply
1 Solution
1,291 Views
RadekS
NXP Employee
NXP Employee

Hi Jin,

It seems that problem is that you didn’t initialize CAN module properly as first.

You have to enter into initialization mode and configure CANCTL0, CANCTL1, CANBTR0, CANTR1 and potentially also CAN acceptance filter registers.

Please look at attached example code with CAN communication and CAN Sleep/MCU Stop mode + CAN wake-up.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

View solution in original post

0 Kudos
Reply
2 Replies
1,292 Views
RadekS
NXP Employee
NXP Employee

Hi Jin,

It seems that problem is that you didn’t initialize CAN module properly as first.

You have to enter into initialization mode and configure CANCTL0, CANCTL1, CANBTR0, CANTR1 and potentially also CAN acceptance filter registers.

Please look at attached example code with CAN communication and CAN Sleep/MCU Stop mode + CAN wake-up.

I hope it helps you.

Have a great day,
Radek

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos
Reply
1,291 Views
jinchengxie
Contributor I

Who can help me?

0 Kudos
Reply