regarding CAN in KEA128

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

regarding CAN in KEA128

1,656 Views
jashanm
Contributor III

hi all,

       i am working on TRK KEA128, how do i select the baud rate ?? (My CAN bus works at 500 Mbps) Can someone also give the over view on how the data is structured in KEA128 to receive and transmit 5 bytes of data  ?? i am actually stuck with selecting the proper registers for RX and TX ( confusion with MSCAN_CANTFLG_TXE ) ??

Regards,

Jashan M

Labels (1)
6 Replies

985 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Jashan,

Are you sure that you use the MSCAN bus with 500MBPS? I suppose that KEA128 can not reach up to 500MBPS. Pls refer to section 32.1.3 Features in KEA128RM, "Programmable bit rate up to 1 Mbps". In other words, the maximum baudrate of mscan is 1Mbps.

Regarding the question how to compute the baudrate, pls refer to section 32.4.5.2 Clock system. There is a concept of Time quanta clock, which is the CAN driving clock/prescaler. For example, if the BUS clock frequency is 24MHz, the prescaler is 2 by setting the BRP bits as 000001 in MSCAN_CANBTR0 register, the MSCAN the time quanta is 1/(24MHz/2)=0.08333uS. Pls refer to Figure 32-81. Segments within the bit time, the CAN bit cycle time=time quanta*(SYNC_SEG+PROP_SEG + PHASE_SEG1+PHASE_SEG2).

hope it can help you.

BR

XiangJun Rong

0 Kudos

985 Views
jashanm
Contributor III

hi XiangJun,

                  Am sorry, it should be 500 kbps. Thanks for the reply, what if i want to have 500 kbps from 20 MHz  Bus clock ?? to calculate the time quanta i need prescaler which is not described how to calculate in the document. So basically i need to know how you got prescaler as 2 from 24 MHz for 500 Kbps ??

Regards,

Jashan M

0 Kudos

985 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Jashan,

For example, if the Bus clcok is 24MHz, the prescaler is 2, the MSCAN the time quanta 0.08333uS. If the required baudrate is 500KBPS, the sum of (SYNC_SEG+PROP_SEG + PHASE_SEG1+PHASE_SEG2) should be 12MHz/0.5MHz=24.

You can use the following parameters:

SYNC_SEG=1

PROP_SEG + PHASE_SEG1=15

PHASE_SEG2=8

This is register setting for 500Kbps based on 24MHz bus clock from FLL and 12M Time quanta clock frequency.

MSCAN_CANBTR0=0x01; //prescaler is 2, Synchronization Jump Width=1 Tq

MSCAN_CANBTR1=0x7E;

If you use external 8MHz clock, you can use the external clock to drive the MSCAN directly, but you need reconfigure the above two register.

BTW, if you use PE or SDK, after you input required baudrate, the PE/SDK can set up the register automatically.

Hope it can help you.

0 Kudos

985 Views
jashanm
Contributor III

hi Xiangjun,

                  i have made the following change in which my bus clock is running at 20 MHz,

1. Bus_Clk = 20 MHz

2. CAN_bus_speed = 500 Kbps

3. prescler = 2

4. SYNC_SEG =1

    PROP_SEG + PHASE_SEG1 = 15

    PHASE_SEG2 = 4

5. MSCAN_CANBTR0=0x01;        

    MSCAN_CANBTR1=0x3E;

this configuration is fine for 20 MHz bus clock ???

Regards,

Jashan M

0 Kudos

985 Views
jashanm
Contributor III

hi Xiangjun,

                   After the above configuration, i have to send a CAN message of ID = 0x123 with Data length (DLC) of 5 bytes. I have done a function to the same which goes to initialization mode and sets the configuration which is as given below.

void MSCAN0_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 CAN0 mode ************/
MSCAN_CANCTL0 |= MSCAN_CANCTL0_INITRQ_MASK;         /* Enable INIT mode ************/
MSCAN_CANCTL1 |= MSCAN_CANCTL1_INITAK_MASK;         /* Enable INIT mode ************/
MSCAN_CANCTL1 |= MSCAN_CANCTL1_CLKSRC_MASK;      /* Enable CLK source ***********/
MSCAN_CANBTR0 = 0x01;                                                              /* prescaler set to 2 **********/   
MSCAN_CANBTR1=0x3E;                                                                /* SEG SEG1 SEG2 ***************/
MSCAN_CANCTL0 &= MSCAN_CANCTL0_INITRQ_MASK;        /* Disable INIT mode ***********/
MSCAN_CANCTL1 &= MSCAN_CANCTL1_INITAK_MASK;        /* Disable INIT mode ***********/

}

is this configuration fine to get my CAN0 to Tx and Rx CAN messages ??

0 Kudos

985 Views
xiangjun_rong
NXP TechSupport
NXP TechSupport

Hi, Jashan

This is the official driver and test code of MSCAN based KEA128 from website, pls check it. Hope it can help you.

KEA |Kinetis KEA Automotive MCUs|Freescale

BR

XiangJun Rong