How to config CAN with using FLEXCAN_5 on S32K312 S32K312NHT0MPBSR

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

How to config CAN with using FLEXCAN_5 on S32K312 S32K312NHT0MPBSR

ソリューションへジャンプ
693件の閲覧回数
DanielYJHsieh
Contributor II

Dear NXP-expert

current environment description:
Package: S32 Design Studio Platform package; Version: 3.4.3; Build id: 202112151555
Package: FreeRTOS for S32K3 2.0.0; Version: 2.0.0; Build id: 202204280242
Package: S32K3xx development package; Version: 3.4.3; Build id: 202112162057
Package: S32K3 RTD AUTOSAR 4.4 Version 2.0.0; Version: 2.0.0; Build id: 202203311410

I would like to enable S32K312NHT0MPBSR's CAN bus by example FlexCAN_Ip_Example_S32K312.

I had config it to FLEXCAN_5 and init it

I can not saw any wave when i send a CAN message

Are there any wrong config at following initial and send command?

 

#define Rx_MSG_ID 0x08u
#define Tx_MSG_ID 0x16u

#define RX_MB_IDX 1U
#define TX_MB_IDX 0U

FlexCAN_Ip_Init(INST_FLEXCAN_5, &FlexCAN_State5, &FlexCAN_Config5);
FlexCAN_Ip_SetRxMaskType(INST_FLEXCAN_5,FLEXCAN_RX_MASK_INDIVIDUAL);
FlexCAN_Ip_SetRxIndividualMask(INST_FLEXCAN_5,RX_MB_IDX,0);
FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_5, RX_MB_IDX, &rx_info, Rx_MSG_ID);
FlexCAN_Ip_SetStartMode(INST_FLEXCAN_5);

FlexCAN_Ip_Send(INST_FLEXCAN_5, TX_MB_IDX, &rx_info, Tx_MSG_ID, (uint8 *)&dummyData);
and 

DanielYJHsieh_0-1756212541328.png

 

BR

Daniel

 

0 件の賞賛
返信
1 解決策
509件の閲覧回数
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @DanielYJHsieh,

S32K312EVB uses a different transceiver than TJA1044. In your case, CAN_STB must be LOW for normal mode. From TJA1044's data sheet:

Snag_e64f9d2.png

I can receiver 0x55 and 0xFACE ID CAN BUS.
How to config for more IDs
These lines configure the received IDs:

rx_info.msg_id_type = FLEXCAN_MSG_ID_EXT;
FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_0, RX_MB_IDX, &rx_info, 0xFACE);  //MB = 1 : ID : 0xFACE : Extended ID
rx_info.msg_id_type = FLEXCAN_MSG_ID_STD;
FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_0, RX_MB_IDX_0, &rx_info, 0x55); // MB = 0 : ID = 0x55 : STANDARD ID

You can add more IDs to be received or set the acceptance mask to 0x0 to receive all IDs.

There is a community post explaining how to use the mask settings: S32K1xx-FlexCAN Mask Setting Demo - NXP Community. It is based on the S32K1 devices, but the same principles apply.

Does it mean the can bus is fine to use?
Yes.
 
However, the device seen stop after few seconds.
Is it system issue not CAN issue?
What do you mean by stop? Does the CAN bus stop receiving messages? Is there a BUSOFF error? Or does the application go to a hard fault?

元の投稿で解決策を見る

0 件の賞賛
返信
9 返答(返信)
578件の閲覧回数
DanielYJHsieh
Contributor II

Dear Julián

I had porting the S32K312_CAN_TX_RX_using_MB_Interrupt_working.zip of Example S32K312 CAN Transmit & Receive Using MB Interrupt DS3.5 RTD300 - NXP Community to my platform.

I use INST_FLEXCAN_5 other LED, 
Which part need to be change too?
How about following function?
/*Initial ISR*/

Should i change to 
IntCtrl_Ip_EnableIrq(FlexCAN5_0_IRQn);
IntCtrl_Ip_EnableIrq(FlexCAN5_1_IRQn);


How to testing it.

What should the Prop Seg/Seg 1/Seg 2/Pre Divider/Resync jump width of FlexCAN_Config0 be?

What does the PCAN VIIEW config should be?

Thank you very much

0 件の賞賛
返信
565件の閲覧回数
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @DanielYJHsieh

Yes, if you are using FlexCAN5, simply change the configuration for instance 5.

You can use this spreadsheet calculator for CAN bit timing segments: MPC5xxx/S32Kxx/LPCxxxx: CAN / CAN FD bit timing calculation - NXP Community.

For testing purposes, match the same configuration in PCAN View and in MCU, for example:

S32K3 with 500Kbps & SP 87.5%:

Snag_9739302.png

PEAK View w/same config:

Snag_973e51a.png

Bus status should be OK:

Snag_97471d9.png

Best regards,
Julián

0 件の賞賛
返信
545件の閲覧回数
DanielYJHsieh
Contributor II

Dear Julián

Sofar, i can send out the CAN Tx Message and Tx Message

I need to mark //Siul2_Dio_Ip_WritePin(PTC_L_HALF, 6u, 1U);   //CAN5_STB

Why example set high STB pin?

I can receiver 0x55 and 0xFACE ID CAN BUS.
How to config for more IDs

Does it mean the can bus is fine to use?
 
However, the device seen stop after few seconds.
Is it system issue not CAN issue?
Thank you very much
 
0 件の賞賛
返信
510件の閲覧回数
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @DanielYJHsieh,

S32K312EVB uses a different transceiver than TJA1044. In your case, CAN_STB must be LOW for normal mode. From TJA1044's data sheet:

Snag_e64f9d2.png

I can receiver 0x55 and 0xFACE ID CAN BUS.
How to config for more IDs
These lines configure the received IDs:

rx_info.msg_id_type = FLEXCAN_MSG_ID_EXT;
FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_0, RX_MB_IDX, &rx_info, 0xFACE);  //MB = 1 : ID : 0xFACE : Extended ID
rx_info.msg_id_type = FLEXCAN_MSG_ID_STD;
FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_0, RX_MB_IDX_0, &rx_info, 0x55); // MB = 0 : ID = 0x55 : STANDARD ID

You can add more IDs to be received or set the acceptance mask to 0x0 to receive all IDs.

There is a community post explaining how to use the mask settings: S32K1xx-FlexCAN Mask Setting Demo - NXP Community. It is based on the S32K1 devices, but the same principles apply.

Does it mean the can bus is fine to use?
Yes.
 
However, the device seen stop after few seconds.
Is it system issue not CAN issue?
What do you mean by stop? Does the CAN bus stop receiving messages? Is there a BUSOFF error? Or does the application go to a hard fault?
0 件の賞賛
返信
282件の閲覧回数
DanielYJHsieh
Contributor II

Dear @Julián_AragónM 

I had double check the scope.

The rate is 500K as picture.

Any thing i need to check more?

PC Tool PCAN-view's waveform

DanielYJHsieh_0-1757293695120.png

 

Device side's waveform

DanielYJHsieh_1-1757293729585.png

 

The H-L math waveform

DanielYJHsieh_2-1757293764682.png

 

 

0 件の賞賛
返信
259件の閲覧回数
DanielYJHsieh
Contributor II

Dear @Julián_AragónM 

I had slove my issue.

please ignore my previous question

Thank you very much

 
324件の閲覧回数
DanielYJHsieh
Contributor II

Dear @Julián_AragónM 

Could you please help to check following config is correct or not?
Me device's CAN become NG, however i did not change the config

The scope have waveform ,but the PCAN-view can not receiver message.

I suspect the device did not send the correct

DanielYJHsieh_0-1757262909780.pngDanielYJHsieh_1-1757262925792.png

DanielYJHsieh_4-1757262978994.png

 

 

DanielYJHsieh_2-1757262936893.pngDanielYJHsieh_3-1757262962624.png

DanielYJHsieh_5-1757263022645.png

 

 

 

0 件の賞賛
返信
594件の閲覧回数
DanielYJHsieh
Contributor II

Dear Julián

My SW version is 

Package: S32 Design Studio Platform package; Version: 3.4.3; Build id: 202112151555
Package: FreeRTOS for S32K3 2.0.0; Version: 2.0.0; Build id: 202204280242
Package: S32K3xx development package; Version: 3.4.3; Build id: 202112162057
Package: S32K3 RTD AUTOSAR 4.4 Version 2.0.0; Version: 2.0.0; Build id: 202203311410


I use my own board, design as following

DanielYJHsieh_0-1756351260209.png

 

DanielYJHsieh_1-1756351287456.png

 

i do following config to use CAN5.

Please help to review the steps

MCU: S32K312
CAN Module: FlexCAN5
Clock: FLEXCAN5_CLK = 24MHz
Pins: PTC26 (RX), PTC27 (TX)
Bit Rate: 500 kbps

// CAN Timing Configuration (from FlexCAN_Ip_Sa_BOARD_InitPeripherals_PBcfg.c)
{
    /* Prop Seg */     (5U),    // Propagation Segment
    /* Phase Seg 1 */  (8U),    // Phase Segment 1
    /* Phase Seg 2*/   (2U),    // Phase Segment 2  
    /* Pre Divider */  (3U),    // Prescaler
    /* Resync jump width */ (2U) // SJW
}
INST_FLEXCAN_5 = 5        // FlexCAN5 實例
RX_MB_IDX = 8             // 接收 Message Buffer 索引
TX_MB_IDX = 9             // 傳送 Message Buffer 索引
Rx_MSG_ID = 0x08          // 接收訊息 ID
Tx_MSG_ID = 0x16          // 傳送訊息 ID

void CAN0_init() {
    // 1. Initialize FlexCAN module
    FlexCAN_Ip_Init(INST_FLEXCAN_5, &FlexCAN_State0, &FlexCAN_Config0);
   
    // 2. Configure RX mask
    FlexCAN_Ip_SetRxMaskType(INST_FLEXCAN_5, FLEXCAN_RX_MASK_INDIVIDUAL);
    FlexCAN_Ip_SetRxIndividualMask(INST_FLEXCAN_5, RX_MB_IDX, 0);
   
    // 3. Configure RX message buffer
    FlexCAN_Ip_ConfigRxMb(INST_FLEXCAN_5, RX_MB_IDX, &rx_info, Rx_MSG_ID);
   
    // 4. Start CAN controller
    FlexCAN_Ip_SetStartMode(INST_FLEXCAN_5);
   
    // 5. Start reception
    FlexCAN_Ip_Receive(INST_FLEXCAN_5, RX_MB_IDX, &rxMsgBuff, FALSE);
}
void CAN0_tx_command() {
    // Check message buffer status
    Flexcan_Ip_StatusType mb_status = FlexCAN_Ip_GetTransferStatus(INST_FLEXCAN_5, TX_MB_IDX);
   
    // Handle BUSY state
    if(mb_status == FLEXCAN_STATUS_BUSY) {
        FlexCAN_Ip_AbortTransfer(INST_FLEXCAN_5, TX_MB_IDX);
        FlexCAN_Ip_ClearErrorStatus(INST_FLEXCAN_5, 0xFFFFFFFF);
    }
   
    // Send message
    Flexcan_Ip_StatusType status = FlexCAN_Ip_Send(INST_FLEXCAN_5, TX_MB_IDX, &tx_info, Tx_MSG_ID, dummyData);
    // status == FLEXCAN_STATUS_SUCCESS
0 件の賞賛
返信
610件の閲覧回数
Julián_AragónM
NXP TechSupport
NXP TechSupport

Hi @DanielYJHsieh,

Your basic configuration seems ok. Are you using an S32K312-EVB? Or is this a custom design? Please confirm if the pinout and CAN bus design is correct. You can base the design from the EVB (using a TJA1153 transceiver):

Julin_AragnM_0-1756330158934.png

Also, I assume you are also configuring and initializing the clocks and pins correctly. You can use these community posts as reference:

 Best regards,
Julián

0 件の賞賛
返信