S32K148EVB CAN1 cannot transmit or receive any message from TJA1050

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

S32K148EVB CAN1 cannot transmit or receive any message from TJA1050

924 Views
kc23
Contributor I

Dear all,

I am using the example code can_pal in S32K148 folder from the downloaded S32_SDK_S32K1xx_RTM_4.0.3.

My requirement is to get CAN1 through (PTC6 & PTC7) to work with TJA1050 CAN bus module. My connection is as shown below.

 

Scenario 2.png

Tested with the original code using CAN0, I can receive message on the console S32K144EVB. For CAN1, I have changed the instance index, define the number of flexcan, configured the pins but it is not working. I observe PTC6 and PTC7 with oscilloscope and no waveform. Below is my code and what I have changed:

I have added a source code file and a header file:

1) peripherals_can_pal2.c and peripherals_can_pal2.h

/*can_instance_t can_pal1_instance = {
.instType = CAN_INST_TYPE_FLEXCAN,
.instIdx = 0UL
};*/

can_instance_t can_pal2_instance = {
.instType = CAN_INST_TYPE_FLEXCAN,
.instIdx = 1UL
};

const can_user_config_t can_pal2_Config0 = {
.maxBuffNum = 2UL,
.mode = CAN_NORMAL_MODE,
.peClksrc=CAN_CLK_SOURCE_OSC,
.enableFD = true,
.payloadSize = CAN_PAYLOAD_SIZE_16,
.nominalBitrate = {
.propSeg = 7UL,
.phaseSeg1 = 4UL,
.phaseSeg2 = 1UL,
.preDivider = 0UL,
.rJumpwidth = 1UL
},
.dataBitrate = {
.propSeg = 3UL,
.phaseSeg1 = 1UL,
.phaseSeg2 = 1UL,
.preDivider = 0UL,
.rJumpwidth = 1UL
},
.extension = NULL
};

 

I have modified the code in 3 different files:

1) can_pal_cfg.h

I have defined for both definition because I needed to use both CAN0 and CAN1.

#define CAN_OVER_FLEXCAN 2

#define NO_OF_FLEXCAN_INSTS_FOR_CAN 2

2) pin_mux.c

I have included the below code in the array to configure CAN1 (PTC6 & PTC7).

{
.base = PORTC,
.pinPortIdx = 6U,
.pullConfig = PORT_INTERNAL_PULL_NOT_ENABLED,
.driveSelect = PORT_LOW_DRIVE_STRENGTH,
.passiveFilter = false,
.mux = PORT_MUX_ALT3,
.pinLock = false,
.intConfig = PORT_DMA_INT_DISABLED,
.clearIntFlag = false,
.gpioBase = NULL,
.digitalFilter = false,
},
{
.base = PORTC,
.pinPortIdx = 7U,
.pullConfig = PORT_INTERNAL_PULL_NOT_ENABLED,
.driveSelect = PORT_LOW_DRIVE_STRENGTH,
.passiveFilter = false,
.mux = PORT_MUX_ALT3,
.pinLock = false,
.intConfig = PORT_DMA_INT_DISABLED,
.clearIntFlag = false,
.gpioBase = NULL,
.digitalFilter = false,
},

3) main.c
int main(void)
{
/* Do the initializations required for this application */
BoardInit();
GPIOInit();

CAN_Init(&can_pal2_instance, &can_pal2_Config0);

while(1)
{
/******************************************************************************
* CAN Transmit
******************************************************************************/

/* Set information about the data to be sent
* - Standard message ID
* - Bit rate switch enabled to use a different bitrate for the data segment
* - Flexible data rate enabled
* - Use zeros for FD padding
*/
can_buff_config_t buffCfg = {
.enableFD = true,
.enableBRS = true,
.fdPadding = 0U,
.idType = CAN_MSG_ID_STD,
.isRemote = false
};

/* Configure TX buffer with index TX_MAILBOX*/
CAN_ConfigTxBuff(&can_pal2_instance, TX_MAILBOX_0, &buffCfg);

/* Prepare message to be sent */
can_message_t message = {
.cs = 0U,
.id = TX_MSG_ID_0, // 0x5BC
//.data = {0x23, 0xDE, 0x84, 0xD7, 0xA0, 0xF6, 0x41, 0xF3},
//.length = 8U
.data = {0xAA},
.length = 1U
};

/* Send the information via CAN */
/* 0x5BC */
CAN_Send(&can_pal2_instance, TX_MAILBOX_0, &message);

for (int i = 0; i<10000000; i++){}
}

for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
}

Kindly feedback to me, thank you in advance.

Regards,

KC.

0 Kudos
5 Replies

890 Views
kc23
Contributor I

Hi Petr,

Thank you for the fast response.
What is this PE code and how do you generate it?
I tried to use pin PTA12 & PTA13 by including it inside the array in pin_mux.c but I am still not getting anything on S32K144.
Did I configure it the right way?

Regards,
KC.

0 Kudos

889 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

I overlooked you have RTM403 so is using S32DS3.4 probably. In this case ConfigTools are used instead of Processor Expert.
So do changes in Peripherals and Pins Config tools and click on Update Code

PetrS_1-1674744257616.png

BR, Petr

 

0 Kudos

869 Views
kc23
Contributor I

Hi Petr,

I am using S32DS3.5 to be precised.
I did try the method you mentioned. I have changed the pin configurations and peripherals using ConfigTools and update the code ONLY for the pins and peripherals.

Screenshot 2023-01-27 115451.png

Screenshot 2023-01-27 115508.png

Screenshot 2023-01-27 122708.png
I have made changes in the main file so that it will configure and receive based on CAN1 but still unable to get any data on S32K144EVB.

Regards,
KC.

0 Kudos

856 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

try to disconnect transceiver from MCU and connect CAN1 pins together, then send a message. You should see message transmitted still on this connection due to missing ACK. This way you can test if CAN1 and its pins are properly configured. Also you can inspect ESR1, ECR registers for errors detected. There should be TX error counter at 0x80 and ACK error detected.
If above is correct then remove external loopback wire, connect transceiver and do the same, check ESR1, ECR registers again.

BR, Petr

0 Kudos

895 Views
PetrS
NXP TechSupport
NXP TechSupport

Hi,

instead of modifying generated code, do a changes within can_pal and pin_mux components then generate PE code.
Also PTC6/PTC7 pins are connected to K20 that serves as OpenSDA and virtual serial port. Try to rather use different pins, I think PTA12/PTA13 should be available, if SAI interface is not used.

BR, Petr

0 Kudos