AnsweredAssumed Answered

CAN receive not working in KEA-128

Question asked by vignesh balaji on Nov 6, 2015
Latest reply on Nov 9, 2015 by Kerry Zhou

Hi,

I am working on CAN in KEA-128.I wrote a small code to receive data in CAN.please tell me what i am missing in this and what should i add in this to get my receive as working.Please give solutions based on my code

 

 

 

#include "derivative.h" /* include peripheral declarations */

#include "CLK.h"

 

void MSCAN_init();

UINT8 i=0;

UINT16 rx_buffer[8];

 

 

int main(void)

{

  Clk_Init();           //20Mhz frequency

  MSCAN_init();

 

  MSCAN_CANRIER = 0x80; //receive interrupt enabled

  MSCAN_RSIDR0 = 0x01;  // identifier register

  MSCAN_RSIDR1 = 0x01;  // standard id,data frame, standard identifier format

 

  MSCAN_RDLR = 0x10;    // data length 1 byte

 

  for(;;) {  

 

  }

 

  return 0;

}

 

void MSCAN_init()

{

SIM_PINSEL1 &= ~SIM_PINSEL1_MSCANPS_MASK;           /* Selected PTC7 and PTC6 ******/       

SIM_SCGC |= SIM_SCGC_MSCAN_MASK ;                                  /* Clock enabled to CAN0 *******/

MSCAN_CANCTL1 |= MSCAN_CANCTL1_CANE_MASK;           /* Enable CAN mode ************/

MSCAN_CANCTL0 |= MSCAN_CANCTL0_INITRQ_MASK;         /* Enable INIT mode ************/

MSCAN_CANCTL1 |= MSCAN_CANCTL1_INITAK_MASK;         /* Enable INIT mode ************/

while ((MSCAN_CANCTL1&0x01)!=1);                    /* wait for initialization mode */

MSCAN_CANCTL0 |= MSCAN_CANCTL0_TIME_MASK;           /* time stamping */

MSCAN_CANCTL1 |= MSCAN_CANCTL1_CLKSRC_MASK;      /* Enable CLK source ***********/ //not for time stamping(internal clock

MSCAN_CANBTR0 = 0x01;                                /* prescaler set to 2 **********/  

MSCAN_CANBTR1=0x3E;                                  /* SEG SEG1 SEG2 ***************/ //(generates 500 Kbps)

 

 

/******************* receive initialization **********************************/

MSCAN_CANIDAC = 0x40; /* 8 bit acceptaance filter */

 

 

MSCAN_CANCTL0 &= ~MSCAN_CANCTL0_INITRQ_MASK;         /* Disable INIT mode ***********/

MSCAN_CANCTL1 &= ~MSCAN_CANCTL1_INITAK_MASK;         /* Disable INIT mode ***********/

while ((MSCAN_CANCTL1&0x00) != 0); /**** wait for normal board *******/

}

 

 

void MSCAN_Rx_IRQHandler(void){

  if((MSCAN_CANRFLG & 0x80)== 1)      // indicating message received

  {

 

      UINT8 rx= (MSCAN_CANIDAC & 0xE0);

      rx_buffer[i] = rx;

  i++;

  MSCAN_CANRFLG = 0x01;     /* Clear RXF */

 

 

  }

}

Outcomes