CAN Tx in KEA-128

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

CAN Tx in KEA-128

Jump to solution
1,376 Views
vignesh_vb_7
Contributor IV

Hi,

    I am working on CAN in KEA-128.I wrote a scratch code for CAN transmit.Please tell me what mistake i have done in it as it is not working.Please tell changes in my code and i don't want drivers for it.I want a simple sample code like mine here.Thanks in advance

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

#include "ATHER_GPIO.h"

#include "typedefs.h"

#include "CLK.h"

UINT8 tx_select, backup_txbuffer;

void MSCAN_init();

int main(void)

{

Clk_Init();           //20Mhz frequency

MSCAN_init();

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

/**** selection of transmit buffer ****/

if (MSCAN_CANTFLG != 1); /* Is Transmit Buffer full?? */

/************* select one among 3 buffers *************/

tx_select = MSCAN_CANTFLG; /* read transmit flag */

MSCAN_CANTBSEL = tx_select; /* write the value back to Can select register */

backup_txbuffer = MSCAN_CANTBSEL;

/************ Fill the parts of CAN frame(Frame ID, local priority, datalength, data) ************/

MSCAN_TSIDR0 = 0x01;   /* frame id */ // standard frame has 2 registers involved

MSCAN_TEIDR0 = 0X01;

MSCAN_TDLR = 1;         /* Data frame length */

MSCAN_TEDSR0 = 0X20;        /*putting data into the data buffer*/

MSCAN_TBPR = backup_txbuffer;              /* local priority */

MSCAN_CANTFLG = backup_txbuffer;  /*start transmission */ // setting the ttransmit flasg to release the buffer

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

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)

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

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

}

1 Solution
793 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi vignesh balaji,

      What the KEA platform you are using? Did you use the TRK-KEA128?

      Please refer to my CW10.6 KEA128 CAN project, my project can receive both extend ID or standard ID, I already test in on our TRK-KEA128, and it works ok on my side.

      I use the CAN analyzer to send the standard Frame, ID:0x00000123, DLC is 8, the Data is : 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x77

You can use your PEAK-CAN send the same data to the KEA128, If your PEAK-CAN send the correct data, you will find the InpData is: 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x77 in the CW debug expressions after you stop the debug. The MSCAN baud is 100kbps, so you should use your PEAK-CAN send the data with 100kbps, otherwise MCU won't receive it.

      This is the test result picture:

cantest.jpg

Wish it helps you!

If you still have question, please contact with me!


Have a great day,
Jingjing

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

View solution in original post

3 Replies
794 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi vignesh balaji,

      What the KEA platform you are using? Did you use the TRK-KEA128?

      Please refer to my CW10.6 KEA128 CAN project, my project can receive both extend ID or standard ID, I already test in on our TRK-KEA128, and it works ok on my side.

      I use the CAN analyzer to send the standard Frame, ID:0x00000123, DLC is 8, the Data is : 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x77

You can use your PEAK-CAN send the same data to the KEA128, If your PEAK-CAN send the correct data, you will find the InpData is: 0x11,0x22,0x33,0x44,0x55,0x66,0x77,0x77 in the CW debug expressions after you stop the debug. The MSCAN baud is 100kbps, so you should use your PEAK-CAN send the data with 100kbps, otherwise MCU won't receive it.

      This is the test result picture:

cantest.jpg

Wish it helps you!

If you still have question, please contact with me!


Have a great day,
Jingjing

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

793 Views
dogukangovce
Contributor I

Hi Kerry, I am new at kea128 and can communications. I have 2 kea128 and I want to communicate them with canbus, you gave the code which is for reading can messages, could you configure it for sending messages. 

https://community.nxp.com/message/846659#comment-850071  in here the code is so long, I guess I don't need everything on there and it is realy hard to understand. 

Thanks for your interest.

0 Kudos
793 Views
kerryzhou
NXP TechSupport
NXP TechSupport

Hi dogukan,

   That post is using the official CAN driver, you can use that, and it is not difficult to understand if you read it carefully.

   When meet the code which you can't understand, you can post the question, we will help you to answer it.


Have a great day,
Kerry

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