CAN receive not working in KEA-128

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

CAN receive not working in KEA-128

652 Views
vignesh_vb_7
Contributor IV

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 */

  }

}

1 Reply

370 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi vignesh balaji,

    I find you create anther post with the same question in this link:CAN Tx in KEA-128

  I already answer you in that link, if you still have question, please update your problem in that link, I will continue to reply you!

  You can disable your Identifier Mask Register to receive all the ID, and you should make sure your PEAK-CAN baud is the same baud with your KEA chip, my project CAN baud is 100Kbps, and don't mask the receive ID, you can test my project on your side. Besides, you should make sure your CAN RX pin is correct.


Have a great day,
Jingjing

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