Hi
Can someone help me with the following.
I am writing a firmware for a prototype level electric two wheeler coustom VCU(S32k146) . I am using S32DS with EAR SDK 0.8.6.
Brief Architecture

/*
* Copyright (c) 2015 - 2016 , Freescale Semiconductor, Inc.
* Copyright 2016-2017 NXP
* All rights reserved.
*
* THIS SOFTWARE IS PROVIDED BY NXP "AS IS" AND ANY EXPRESSED OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL NXP OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
* THE POSSIBILITY OF SUCH DAMAGE.
*/
/* Including needed modules to compile this module/procedure */
#include "Cpu.h"
#include "clockMan1.h"
#include "pin_mux.h"
#if CPU_INIT_CONFIG
#include "Init_Config.h"
#endif
volatile int exit_code = 0;
/* User includes (#include below this line is not maintained by Processor Expert) */
#include <stdint.h>
#include <stdbool.h>
/* This example is setup to work by default with EVB. To use it with other boards
please comment the following line
*/
#define GPIO_PORTA PTA
#define GPIO_PORTB PTB
#define GPIO_PORTC PTC
#define GPIO_PORTD PTD
#define GPIO_PORTE PTE
#define Right_Indicator 1U//PTD
#define Left_Indicator 0U//PTD
#define GLYPH1 14//PTC
#define GLYPH2 15//PTC
//#define GLYPH3 16//PTC
//#define GLYPH4 17//PTC
#define Cluster_Screen_Trig 7//PTE
#define Battery_Unlock 1//PTE
#define Boot_Unlock 11//PTE
#define Discharge_Contactor 16//PTD
#define Charge_Contactor 9//PTE
#define Motor_Ignition 11//PTA
#define Motor_Park 2//PTE
#define Light_Sound_Relay 0//PTC
#define Throttle_Relay 3//PTB
#define Display_Ignition_Relay 2//PTB
#define SL_Motor_Op1 5//PTB OLD CONFIG//PTC16 // INB
#define SL_Motor_Op2 8//PTE OLD CONFIG//PTC17 // INA
//CAN Tx Frame ID and MAILBOX Setup for CAN_PAL1
#define TX1VOLTAGE_MAILBOX_1 (1UL)
#define TX1VOLTAGE_ID1 (0x100)
#define TX1SOC_MAILBOX_2 (2UL)
#define TX1SOC_ID2 (0x101)
#define TX1STATUS_MAILBOX_3 (3UL)
#define TX1STATUS_ID3 (0x102)
#define TX1TEMP1_MAILBOX_4 (4UL)
#define TX1TEMP1_ID4 (0x105)
#define TX1TEMP2_MAILBOX_5 (5UL)
#define TX1TEMP2_ID5 (0x106)
//CAN Rx Frame ID and MAILBOX Setup for CAN_PAL1
#define RX1VOLTAGE_MAILBOX_1 (6UL)
#define RX1VOLTAGE_ID1 (0x100)
#define RX1SOC_MAILBOX_2 (7UL)
#define RX1SOC_ID2 (0x101)
#define RX1STATUS_MAILBOX_3 (8UL)
#define RX1STATUS_ID3 (0x102)
#define RX1TEMP1_MAILBOX_4 (9UL)
#define RX1TEMP1_ID4 (0x105)
#define RX1TEMP2_MAILBOX_5 (10UL)
#define RX1TEMP2_ID5 (0x106)
//CAN Tx Frame ID and MAILBOX Setup for CAN_PAL2
#define TX2VOLTAGE_MAILBOX_1 (21UL)
#define TX2VOLTAGE_ID1 (0x100)
#define TX2SOC_MAILBOX_2 (22UL)
#define TX2SOC_ID2 (0x101)
#define TX2STATUS_MAILBOX_3 (23UL)
#define TX2STATUS_ID3 (0x102)
#define TX2TEMP1_MAILBOX_4 (24UL)
#define TX2TEMP1_ID4 (0x105)
#define TX2TEMP2_MAILBOX_5 (25UL)
#define TX2TEMP2_ID5 (0x106)
#define TX2stefen_SOC_MAILBOX_6 (26UL)
#define TX2stefen_SOC_ID6 (0x310)
//Vehicle CAN
#define Vehicle_STAT_MAILBOX_7 (27UL)
#define Vehicle_SUBSYS_STAT_MAILBOX_8 (28UL)
#define Vehicle_STAT_ID1 (0x201)
#define Vehicle_SUBSYS_STAT_ID2 (0x202)
//Vehicle STAT Message Struct
can_message_t Vehicle_STAT = {
.cs = 0U,
.id = 0x201,
.data = {0}, // Initialize all bytes to 0
.length = 8U
};
//Vehicle SUBSYS Message Struct
can_message_t Vehicle_SUBSYS_STAT = {
.cs = 0U,
.id = 0x202,
.data = {0}, // Initialize all bytes to 0
.length = 8U
};
// RFID command frames
uint8_t Inventory_cmd[5] = {0x03,0x2F,0x01,0x2D};
uint8_t Blankarray[11];
uint32_t Timeout = 100; /* Timeout in ms for blocking operations */
uint8_t Motor_CAN_Receive =0;
uint8_t arrayindex = 0 ;
uint8_t arrayindex1 = 0;
uint8_t arrayindex2 = 0 ;
// SYSTEM STATES and SYSTEM VARIABLES Initiations
uint8_t SYSTEM_AUTH,SYSTEM_PARK,SYSTEM_ON,SYSTEM_READY,SYSTEM_MOVING = 0;
uint16_t stefen_SOC;
uint16_t micronix_voltage,stefen_voltage;
uint8_t Kill_Switch, Push_Button, Brake, Steering_Lock_STAT, Battery_Lock, Side_Stand, Charger_Connect,Battery_Dock_STAT,CHARGING,BATTERY_LOCKED,BOOT_LOCKED;
uint8_t Battery_High_Temp, Motor_High_Temp,Battery_Malfunction,Motor_Malfunction;
//System Status
status_t can_status;
void delay(volatile int cycles)
{
/* Delay function - do nothing for a number of cycles */
while(cycles--);
}
void BoardInit(void)
{
/* Initialize and configure clocks
* - Setup system clocks, dividers
* - Configure FlexCAN clock, GPIO, LPSPI
* - see clock manager component for more details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_FORCIBLE);
/* Initialize pins
* - Init FlexCAN, LPSPI and GPIO pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
}
void Screen_Trigger_ON (void)
{
//Battery Pack Unlock
if((PTD -> PDIR & (1<<2)) == 0 ) //Soft switch one pressed for Battery Unlock
{
PINS_DRV_WritePin(GPIO_PORTE,Battery_Unlock,1);
delay (100000);//adjust the delay based on the actuator duty cycle
PINS_DRV_WritePin(GPIO_PORTE,Battery_Unlock,0);
}
//Boot Unlock Operation
if((PTD -> PDIR & (1<<3)) == 0 ) //Soft switch two pressed for Boot Unlock
{
PINS_DRV_WritePin(GPIO_PORTE,Boot_Unlock,1);
delay (12500000);//adjust the delay based on the actuator duty cycle
PINS_DRV_WritePin(GPIO_PORTE,Boot_Unlock,0);
}
// //Charging_Contactor Operation
// if((PTD -> PDIR & (1<<4)) == 0 ) //Soft switch two state
// {
// PINS_DRV_WritePin(GPIO_PORTE,Charge_Contactor,1);//Charging Contactor Turned ON
// CHARGING = 1;//Flag raised for Charging
// }
// else if ((PTD -> PDIR & (1<<4)) != 0 )
// {
// PINS_DRV_WritePin(GPIO_PORTE,Charge_Contactor,0);//Charging Contactor Turned OFF
// CHARGING = 0;//Flag raised for Charging Disconnect
// }
}
void CHARGING_OPERATION (void)
{
if (SYSTEM_AUTH == 1 && (PTA->PDIR & (1<<6)) == 0) //PB2 High Detected - Charger Connector Plugged In
{
CHARGING =1;
PINS_DRV_WritePin(GPIO_PORTB,Throttle_Relay,0); //Throttle Disable
PINS_DRV_WritePin(GPIO_PORTE,Motor_Park,0); //SONACOM M.CON START SEQ
PINS_DRV_WritePin(GPIO_PORTC,Light_Sound_Relay,0); // Lighting OFF
PINS_DRV_WritePin(GPIO_PORTD,Discharge_Contactor,0); //Discharge Contactor Turned OFF
delay(10000000);
PINS_DRV_WritePin(GPIO_PORTE,Charge_Contactor,1);//Charging Contactor Turned ON
}
else
{
PINS_DRV_WritePin(GPIO_PORTE,Charge_Contactor,0);//Charging Contactor Turned ON
CHARGING = 0;
}
}
// If the battery is swappable this applies.
//void Discharge_CONTACTOR_ON (void)
//{
// if ((PTE -> PDIR & (1<<0)) == 0)//Battery Position Switch
// {
// PINS_DRV_WritePin(GPIO_PORTD,Discharge_Contactor,1); //Discharge Contactor ON
// BATTERY_LOCKED = 1;
// }
// else
// {
// BATTERY_LOCKED = 0;
// }
//}
void Steering_Unlock(void)
{
//if((PTE->PDIR & (1<<4)) == 0 && (PTE->PDIR & (1<<3)) != 1 ) // this condition checks the LOCK state piston position (it should satisify the lock state piston position)
//{
PINS_DRV_WritePin(GPIO_PORTB, SL_Motor_Op1,0);
PINS_DRV_WritePin(GPIO_PORTE, SL_Motor_Op2,1);
delay (750000); //map this delay to around the same time till it unlock
PINS_DRV_WritePin(GPIO_PORTB, SL_Motor_Op1,0);
PINS_DRV_WritePin(GPIO_PORTE, SL_Motor_Op2,0);
//}
}
void Steering_lock(void)
{
//if((PTE->PDIR & (1<<4)) == 0 && (PTE->PDIR & (1<<3)) != 1 ) // this condition checks the LOCK state piston position (it should satisify the lock state piston position)
//{
PINS_DRV_WritePin(GPIO_PORTB, SL_Motor_Op1,1);
PINS_DRV_WritePin(GPIO_PORTE, SL_Motor_Op2,0);
delay (750000); //map this delay to around the same time till it locks
PINS_DRV_WritePin(GPIO_PORTB, SL_Motor_Op1,0);
PINS_DRV_WritePin(GPIO_PORTE, SL_Motor_Op2,0);
//}
}
void Indicator_Light_Start_Stop (void)
{
// flag required to run this function once when called upon
// static bool functionExecuted = false;
// if(!functionExecuted)
//
PINS_DRV_WritePin(GPIO_PORTD,Right_Indicator,1);
PINS_DRV_WritePin(GPIO_PORTD, Left_Indicator,1);
delay (1000000);
PINS_DRV_WritePin(GPIO_PORTD,Right_Indicator,0);
PINS_DRV_WritePin(GPIO_PORTD,Left_Indicator, 0);
delay (1000000);
PINS_DRV_WritePin(GPIO_PORTD,Right_Indicator,1);
PINS_DRV_WritePin(GPIO_PORTD, Left_Indicator,1);
delay (1000000);
PINS_DRV_WritePin(GPIO_PORTD,Right_Indicator,0);
PINS_DRV_WritePin(GPIO_PORTD,Left_Indicator, 0);
//
// functionExecuted = true;
// }
}
void Vehicle_Switching_Operation(void)
{
if (Blankarray[6]==0x9D && Blankarray[7]==0x30 && Blankarray[8]==0x49 && Blankarray[9]==0x6B)
{
PINS_DRV_WritePin(GPIO_PORTB,Display_Ignition_Relay,1);//Sleep/wake Signal Cluster
delay(10000000);
PINS_DRV_WritePin(GPIO_PORTE,Cluster_Screen_Trig,1);
Steering_Unlock();
Indicator_Light_Start_Stop ();
SYSTEM_AUTH = 1;
SYSTEM_PARK = 1;
BATTERY_LOCKED = 1; //since VE4 is a fixed battery pack
// Reset array values to zero
Blankarray[6] = 0;
Blankarray[7] = 0;
Blankarray[8] = 0;
Blankarray[9] = 0;
}
Screen_Trigger_ON ();// this function allows to run the soft switches
CHARGING_OPERATION();// Charging operation
if (CHARGING == 0 && SYSTEM_PARK == 1 && (PTC->PDIR & (1<<8)) == 0)// RED KEY SWITCH ON
{
PINS_DRV_WritePin(GPIO_PORTE,Cluster_Screen_Trig,0);// Navigate to Home Page
PINS_DRV_WritePin(GPIO_PORTD,Discharge_Contactor,1);//since the battery is not removed it can directly be turned On
delay(100000);//delay required, so, power doesn't flow immediately after the contactor turned on
if (BATTERY_LOCKED ==1)
{
PINS_DRV_WritePin(GPIO_PORTC,Light_Sound_Relay,1);
SYSTEM_ON = 1;
SYSTEM_PARK = 0;
}
}
if (CHARGING == 0 && SYSTEM_ON==1 && (PTC->PDIR & (1<<9)) == 0) // Brake Pressed
{
if (SYSTEM_PARK == 0 && (PTA -> PDIR & (1<<7)) == 0) //Push Button 1 Pressed
{
PINS_DRV_WritePin(GPIO_PORTE,Motor_Park,1); //SONACOM M.CON START SEQ
SYSTEM_READY = 1;
}
}
if ( CHARGING == 0 && SYSTEM_ON==1 && SYSTEM_READY==1) // Throttle Enable
{
PINS_DRV_WritePin(GPIO_PORTB,Throttle_Relay,1);// enable this based on side stand
SYSTEM_MOVING = 1;
}
if (CHARGING == 0 && SYSTEM_ON == 1 && (PTC->PDIR & (1<<8)) !=0 ) // RED KEY SWITCH OFF
{
PINS_DRV_WritePin(GPIO_PORTC,Light_Sound_Relay,0);
PINS_DRV_WritePin(GPIO_PORTE,Motor_Park,0);
PINS_DRV_WritePin(GPIO_PORTB,Throttle_Relay,0);
PINS_DRV_WritePin(GPIO_PORTD,Discharge_Contactor,0);
PINS_DRV_WritePin(GPIO_PORTE,Cluster_Screen_Trig,1);
SYSTEM_ON = 0;
SYSTEM_READY = 0;
SYSTEM_MOVING = 0;
SYSTEM_PARK = 1;
}
if (CHARGING == 0 && SYSTEM_PARK == 1 && (PTA -> PDIR & (1<<7)) == 0) //Push Button 1 Pressed
{
PINS_DRV_WritePin(GPIO_PORTB,Display_Ignition_Relay,0);
Indicator_Light_Start_Stop ();
Steering_lock();
SYSTEM_PARK = 0;
SYSTEM_AUTH = 0;
}
}
void Monitoring_Vehicle_Input_Output(void)
{
// Kill Switch Monitoring
if ((PTC->PDIR & (1<<8)) == 0 ) //RED KEY SWITCH ON
{
Kill_Switch = 1;
Vehicle_STAT.data[0] |= (1<<0); //set bit 0
}
else
{
Kill_Switch = 0;
Vehicle_STAT.data[0] &= ~(1<<0); //clear bit 0
}
// Push Button Monitoring
if ((PTA->PDIR & (1<<7)) == 0 ) //Push Button ON
{
Push_Button = 1;
Vehicle_STAT.data[0] |= (1<<1); //set bit 1
}
else
{
Push_Button = 0;
Vehicle_STAT.data[0] &= ~(1<<1); //clear bit 1
}
// Brake Monitoring
if ((PTC->PDIR & (1<<9)) == 0 ) //Brake Pressed
{
Brake = 1;//Brake Pressed
Vehicle_STAT.data[0] |= (1<<2); //set bit 2
}
else
{
Brake = 0;
Vehicle_STAT.data[0] &= ~(1<<2); //Clear bit 2
}
// Side Stand
if ((PTE->PDIR & (1<<5)) == 0 ) //Side Stand Enable // Enable this as a condition to turn the throttle realy on and off
{
Side_Stand = 1;// cut of the throttle
Vehicle_STAT.data[1] |= (1<<4); //Set bit 4
Vehicle_STAT.data[1] &= ~(1<<5); //Clear bit 5
}
else if ((PTE->PDIR & (1<<5)) != 0 ) // Side Stand Disabled
{
Side_Stand = 0;//connect the throttle
Vehicle_STAT.data[1] &= ~ (1<<4); //Clear bit 4
Vehicle_STAT.data[1] &= ~ (1<<5); //Clear bit 5
}
else
{
Side_Stand = 2;// connecet the throttle so that the malfunction of side stand doesn't effectt the throttle functioning
Vehicle_STAT.data[1] &= ~ (1<<4); //Clear bit 4
Vehicle_STAT.data[1] |= (1<<5); //Set bit 5
}
//Steering Lock
if (((PTE->PDIR & (1<<4)) != 0) && ((PTE->PDIR & (1<<3)) == 0)) // Feedback1 0v and Feedback2 12V
{
Steering_Lock_STAT = 1; //Unlocked (Traveled In)
Vehicle_STAT.data[1] |= (1<<0); //Set bit 0
Vehicle_STAT.data[1] &= ~(1<<1); //Clear bit 1
}
else if (((PTE->PDIR & (1<<4)) == 0) && ((PTE->PDIR & (1<<3)) != 0)) // Feedback1 12v and Feedback2 0V
{
Steering_Lock_STAT = 0; //Locked (Traveled Out)
Vehicle_STAT.data[1] &= ~(1<<0); //Clear bit 0
Vehicle_STAT.data[1] &= ~(1<<1); //Clear bit 1
}
else
{
Steering_Lock_STAT = 2; // Lock Error (Stuck in between)
Vehicle_STAT.data[1] &= ~(1<<0); //Clear bit 0
Vehicle_STAT.data[1] |= (1<<1); //Set bit 1
}
// Charging Status - Byte 2 (Bit 0)
if(CHARGING == 1)
{
Vehicle_STAT.data[2] |= (1 << 0); //Set bit 0; 1-Charging
}
else
{
Vehicle_STAT.data[2] &= ~(1 << 0); //clear bit 0; 0-Not Charging
}
}
void Monitoring_Vehicle_CAN(void)
{
//Vehicle CAN data Monitoring of all nodes
CAN_Send (INST_CAN_PAL2, Vehicle_STAT_MAILBOX_7, &Vehicle_STAT);
CAN_Send (INST_CAN_PAL2, Vehicle_SUBSYS_STAT_MAILBOX_8, &Vehicle_SUBSYS_STAT);
}
int main(void)
{
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/
BoardInit();
//RFID LPUART Initialization
LPUART_DRV_Init(INST_LPUART_RFID, &lpuart_rfid_State, &lpuart_rfid_InitConfig0);
delay (10000);
// CAN Initialization+
CAN_Init(INST_CAN_PAL1,&can_pal1_Config0);
CAN_Init(INST_CAN_PAL2,&can_pal2_Config0);
//CAN Buffer Configuration for CAN PAL1 and CAN_PAL2
can_buff_config_t stdbuff = {
.enableFD = true,
.enableBRS = true,
.idType = CAN_MSG_ID_STD
};
//Configure Tx Buffer with Tx_Mailbox for CAN_PAL1
CAN_ConfigTxBuff(INST_CAN_PAL1, TX1VOLTAGE_MAILBOX_1, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL1, TX1SOC_MAILBOX_2, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL1, TX1STATUS_MAILBOX_3, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL1, TX1TEMP1_MAILBOX_4, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL1, TX1TEMP2_MAILBOX_5, &stdbuff);
//Configure Rx Buffer with Rx_mailbox for CAN_PAL1
CAN_ConfigRxBuff(INST_CAN_PAL1, RX1VOLTAGE_MAILBOX_1, &stdbuff, RX1VOLTAGE_ID1);
CAN_ConfigRxBuff(INST_CAN_PAL1, RX1SOC_MAILBOX_2, &stdbuff, RX1SOC_ID2);
CAN_ConfigRxBuff(INST_CAN_PAL1, RX1STATUS_MAILBOX_3, &stdbuff, RX1STATUS_ID3);
CAN_ConfigRxBuff(INST_CAN_PAL1, RX1TEMP1_MAILBOX_4, &stdbuff, RX1TEMP1_ID4);
CAN_ConfigRxBuff(INST_CAN_PAL1, RX1TEMP2_MAILBOX_5, &stdbuff, RX1TEMP2_ID5);
//Configure Tx Buffer with Tx_Mailbox for CAN_PAL2
CAN_ConfigTxBuff(INST_CAN_PAL2, TX2VOLTAGE_MAILBOX_1, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL2, TX2SOC_MAILBOX_2, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL2, TX2STATUS_MAILBOX_3, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL2, TX2TEMP1_MAILBOX_4, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL2, TX2TEMP2_MAILBOX_5, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL2, TX2stefen_SOC_MAILBOX_6, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL2, Vehicle_STAT_MAILBOX_7, &stdbuff);
CAN_ConfigTxBuff(INST_CAN_PAL2, Vehicle_SUBSYS_STAT_MAILBOX_8, &stdbuff);
// Define messages in TX1 send buffer
can_message_t TX1VOLTAGE = {
.cs = 0U,
.id = TX1VOLTAGE_ID1,
.data[0] = 0x5A,.data[1] = 00,.data[2] = 00,.data[3] = 00,.data[4] = 00,.data[5] = 00,.data[6] = 00,.data[7] = 00,
.length = 8U
};
can_message_t TX1SOC = {
.cs = 0U,
.id = TX1SOC_ID2,
.data[0] = 0x5A,.data[1] = 00,.data[2] = 00,.data[3] = 00,.data[4] = 00,.data[5] = 00,.data[6] = 00,.data[7] = 00,
.length = 8U
};
can_message_t TX1STATUS = {
.cs = 0U,
.id = TX1STATUS_ID3,
.data[0] = 0x5A,.data[1] = 00,.data[2] = 00,.data[3] = 00,.data[4] = 00,.data[5] = 00,.data[6] = 00,.data[7] = 00,
.length = 8U
};
can_message_t TX1TEMP1 = {
.cs = 0U,
.id = TX1TEMP1_ID4,
.data[0] = 0x5A,.data[1] = 00,.data[2] = 00,.data[3] = 00,.data[4] = 00,.data[5] = 00,.data[6] = 00,.data[7] = 00,
.length = 8U
};
can_message_t TX1TEMP2 = {
.cs = 0U,
.id = TX1TEMP2_ID5,
.data[0] = 0x5A,.data[1] = 00,.data[2] = 00,.data[3] = 00,.data[4] = 00,.data[5] = 00,.data[6] = 00,.data[7] = 00,
.length = 8U
};
//Setup and Initialization for Receiving the CAN messages
can_message_t RX1VOLTAGE;
can_message_t RX1SOC;
can_message_t RX1STATUS;
can_message_t RX1TEMP1;
can_message_t RX1TEMP2;
while (1)
{
// LPUART Send and Receive loop setup
LPUART_DRV_SendDataBlocking(INST_LPUART_RFID,Inventory_cmd,5, Timeout);
LPUART_DRV_ReceiveDataBlocking(INST_LPUART_RFID,Blankarray,20, Timeout);
// Vehicle Switching Operation flow.
Vehicle_Switching_Operation();
// Vehicle Input and Output Monitoring constant updates of the vehicle STAT
Monitoring_Vehicle_Input_Output();
// Vehicle CAN Monitoring and Notification Trigger, send the updated data
//Monitoring_Vehicle_CAN();
//Transmitt the TX1 frames
delay(10000);
if (CAN_Send(INST_CAN_PAL1, TX1VOLTAGE_MAILBOX_1, &TX1VOLTAGE) == STATUS_SUCCESS)
{
arrayindex++;
}
delay(10000);
if (CAN_Send(INST_CAN_PAL1, TX1SOC_MAILBOX_2, &TX1SOC) == STATUS_SUCCESS)
{
arrayindex++;
}
delay(10000);
if (CAN_Send(INST_CAN_PAL1, TX1STATUS_MAILBOX_3, &TX1STATUS) == STATUS_SUCCESS)
{
arrayindex++;
}
delay(10000);
if (CAN_Send(INST_CAN_PAL1, TX1TEMP1_MAILBOX_4, &TX1TEMP1) == STATUS_SUCCESS)
{
arrayindex++;
}
delay(10000);
if (CAN_Send(INST_CAN_PAL1, TX1TEMP2_MAILBOX_5, &TX1TEMP2) == STATUS_SUCCESS)
{
arrayindex++;
}
//Receiving the RX1 frames
if (CAN_Receive(INST_CAN_PAL1, RX1VOLTAGE_MAILBOX_1, &RX1VOLTAGE) == STATUS_SUCCESS)
{
micronix_voltage = ((uint16_t)RX1VOLTAGE.data[0]<<8) | (uint16_t)RX1VOLTAGE.data[1];//Big Endian mapping
//micronix_voltage = ((uint16_t)RX1VOLTAGE.data[1]<<8) | (uint16_t)RX1VOLTAGE.data[0];//Little Endian mapping
stefen_voltage = micronix_voltage/10;
arrayindex1++;
}
if (CAN_Receive(INST_CAN_PAL1, RX1SOC_MAILBOX_2, &RX1SOC) == STATUS_SUCCESS)
{
stefen_SOC = RX1SOC.data[5] *10;
arrayindex1++;
}
if (CAN_Receive(INST_CAN_PAL1, RX1STATUS_MAILBOX_3, &RX1STATUS) == STATUS_SUCCESS)
{
arrayindex1++;
}
if (CAN_Receive(INST_CAN_PAL1, RX1TEMP1_MAILBOX_4, &RX1TEMP1) == STATUS_SUCCESS)
{
arrayindex1++;
}
if (CAN_Receive(INST_CAN_PAL1, RX1TEMP2_MAILBOX_5, &RX1TEMP2) == STATUS_SUCCESS)
{
arrayindex1++;
}
// Set up for the TX2 Message with the shifted Payloads from RX1 Message
can_message_t TX2VOLTAGE = {
.cs = 0U,
.id = TX2VOLTAGE_ID1,
.data[0] = RX1VOLTAGE.data[0],
.data[1] = RX1VOLTAGE.data[1],
.data[2] = RX1VOLTAGE.data[2],
.data[3] = RX1VOLTAGE.data[3],
.data[4] = RX1VOLTAGE.data[4],
.data[5] = RX1VOLTAGE.data[5],
.data[6] = RX1VOLTAGE.data[6],
.data[7] = RX1VOLTAGE.data[7],
.length = 8U
};
can_message_t TX2SOC = {
.cs = 0U,
.id = TX2SOC_ID2,
.data[0] = RX1SOC.data[0],
.data[1] = RX1SOC.data[1],
.data[2] = RX1SOC.data[2],
.data[3] = RX1SOC.data[3],
.data[4] = RX1SOC.data[4],
.data[5] = RX1SOC.data[5],
.data[6] = RX1SOC.data[6],
.data[7] = RX1SOC.data[7],
.length = 8U
};
can_message_t TX2STATUS = {
.cs = 0U,
.id = TX2STATUS_ID3,
.data[0] = RX1STATUS.data[0],
.data[1] = RX1STATUS.data[1],
.data[2] = RX1STATUS.data[2],
.data[3] = RX1STATUS.data[3],
.data[4] = RX1STATUS.data[4],
.data[5] = RX1STATUS.data[5],
.data[6] = RX1STATUS.data[6],
.data[7] = RX1STATUS.data[7],
.length = 8U
};
can_message_t TX2TEMP1 = {
.cs = 0U,
.id = TX2TEMP1_ID4,
.data[0] = RX1TEMP1.data[0],
.data[1] = RX1TEMP1.data[1],
.data[2] = RX1TEMP1.data[2],
.data[3] = RX1TEMP1.data[3],
.data[4] = RX1TEMP1.data[4],
.data[5] = RX1TEMP1.data[5],
.data[6] = RX1TEMP1.data[6],
.data[7] = RX1TEMP1.data[7],
.length = 8U
};
can_message_t TX2TEMP2 = {
.cs = 0U,
.id = TX2TEMP2_ID5,
.data[0] = RX1TEMP2.data[0],
.data[1] = RX1TEMP2.data[1],
.data[2] = RX1TEMP2.data[2],
.data[3] = RX1TEMP2.data[3],
.data[4] = RX1TEMP2.data[4],
.data[5] = RX1TEMP2.data[5],
.data[6] = RX1TEMP2.data[6],
.data[7] = RX1TEMP2.data[7],
.length = 8U
};
can_message_t TX2stefen_SOC = {
.cs = 0U,
.id = TX2stefen_SOC_ID6,
.data[0] = TX2stefen_SOC.data[0],
.data[1] = TX2stefen_SOC.data[1],
.data[2] = TX2stefen_SOC.data[0],
.data[3] = TX2stefen_SOC.data[1],
.data[4] = 0,
.data[5] = 0,
.data[6] = TX2stefen_SOC.data[6],
.data[7] = TX2stefen_SOC.data[7],
.length = 8U
};
// mapping the Micronix SOC data to stefen SOC
TX2stefen_SOC.data[6] = (uint8_t)(stefen_SOC&0xFF); // TX2stefen_SOC.data[6] stores the least significant byte (LSB) of stefen_SOC.
//This is done using (stefen_SOC & 0xFF) to isolate the LSB.
TX2stefen_SOC.data[7] = (uint8_t)((stefen_SOC>>8)&0xFF);
// mapping the micronix voltage data to stefen voltage
TX2stefen_SOC.data[0] = (uint8_t)(stefen_voltage&0xFF);
TX2stefen_SOC.data[1] = (uint8_t)((stefen_voltage>>8)&0xFF);
// Switch Case Conditions for Tx the Std BMS Data over CAN PAL 2
switch (RX1VOLTAGE.id)
{
case 0x100: //CAN
delay (1000);
CAN_Send (INST_CAN_PAL2,TX2VOLTAGE_MAILBOX_1, &TX2VOLTAGE);
arrayindex2++;
//if (CAN_Send (INST_CAN_PAL2,TX2VOLTAGE_MAILBOX_1, &TX2VOLTAGE) == STATUS_SUCCESS)
//{
//LPUART1_transmit_string("\r\n 0x310 Transmitted \r\n");
//}
break;
default:
break;
}
switch (RX1SOC.id)
{
case 0x101: //CAN
delay (1000);
CAN_Send (INST_CAN_PAL2,TX2SOC_MAILBOX_2, &TX2SOC);
CAN_Send (INST_CAN_PAL2,TX2stefen_SOC_MAILBOX_6, &TX2stefen_SOC);
arrayindex2++;
break;
default:
break;
}
switch (RX1STATUS.id)
{
case 0x102: //CAN
delay (1000);
CAN_Send (INST_CAN_PAL2,TX2STATUS_MAILBOX_3, &TX2STATUS);
arrayindex2++;
break;
default:
break;
}
switch (RX1TEMP1.id)
{
case 0x105: //CAN
delay (1000);
CAN_Send (INST_CAN_PAL2,TX2TEMP1_MAILBOX_4, &TX2TEMP1);
arrayindex2++;
break;
default:
break;
}
switch (RX1TEMP2.id)
{
case 0x106: //CAN
delay (1000);
CAN_Send (INST_CAN_PAL2,TX2TEMP2_MAILBOX_5, &TX2TEMP2);
arrayindex2++;
break;
default:
break;
}
}
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
/* END main */
/*!
** @}
*/
/*
** ###################################################################
**
** This file was created by Processor Expert 10.1 [05.21]
** for the Freescale S32K series of microcontrollers.
**
** ###################################################################
*/
P.S: I have extracted the Issue summary by a Claude AI generative AI after step by step interaction with it during my debug process inorder to have quick summary. Please comment to this post if any additional info is required inroder to rectifyu the issue. But i have proof read this thoroughly
CAN Transmission Issue Brief Report
Problem Summary
Experiencing a CAN transmission anomaly on your S32K146 VCU where the software indicates successful CAN frame transmission (arrayindex2 increments, CAN_Send() returns success), but no CAN frames are visible on external CAN analyzer despite the hardware and basic transmission logic working correctly.
System Architecture
Based on your schematic:
- VCU (S32K146): Contains CAN PAL 1 (CAN 0 Transceiver) and CAN PAL 2 (CAN 1 Transceiver)
- BMS: Connected via CAN PAL 1
- Motor Controller: Directly connected to Display via shared CAN bus
- Display: Connected to shared CAN bus with Motor Controller
- CAN PAL 2: Connected to the same shared bus as Motor Controller and Display
- Important Note: VCU does NOT receive or acknowledge Motor Controller data - it only transmits on this shared bus
- CAN Analyzer: Connected to CAN PAL 2 bus during testing
Debugging Steps Performed
1. Hardware Verification
- Physical connections confirmed: CAN H, CAN L, and ground properly wired
- Power supply verified: Target voltage 3.30V detected by J-Link
- Termination tested: 120Ω resistors properly installed
- J-Link connectivity: Successfully resolved initial J-Link connection issues by switching from JTAG to SWD interface
2. Successful Test Scenarios
- Simple CAN test code (different code to test the CAN opeartion): Successfully transmitted and received 3 CAN IDs via CAN PAL 1→CAN PAL 2→Analyzer
- Motor Controller reception: Analyzer successfully receives Motor Controller frames (0x500-0x5FF range) on shared bus
- Basic hardware functionality: Proven working through test code
3. Switch Case Logic Verification
Your main application code processes received CAN frames from BMS (via CAN PAL 1) and retransmits via CAN PAL 2:
- Case 0x100 (RX1VOLTAGE): Transmits 1 frame (TX2VOLTAGE) via TX2VOLTAGE_MAILBOX_1
- Case 0x101 (RX1SOC): Transmits 2 frames (TX2SOC, TX2stefen_SOC) via TX2SOC_MAILBOX_2 and TX2stefen_SOC_MAILBOX_6
- Case 0x102 (RX1STATUS): Transmits 1 frame (TX2STATUS) via TX2STATUS_MAILBOX_3
- Case 0x105 (RX1TEMP1): Transmits 1 frame (TX2TEMP1) via TX2TEMP1_MAILBOX_4
- Case 0x106 (RX1TEMP2): Transmits 1 frame (TX2TEMP2) via TX2TEMP2_MAILBOX_5
- Expected total: 4 confirmed CAN frames per cycle (first 3 cases working)
4. Debug Log Analysis
Console logs show:
- Successful function execution: CAN_Send() calls complete without errors
- Arrayindex2 incrementation: Clear progression from 0x00→0x01→0x02→0x03 (first test), then 0x06→0x33+ (Motor Controller disconnected test), confirming switch case execution
- Mailbox processing: Sequential mailbox handling in range 11-17 working correctly
- No error conditions: No timeout, arbitration loss, or hardware fault indicators visible in debug session
5. Priority Analysis Verification
Message ID priorities confirmed:
- Your VCU transmitted frames: 0x100, 0x101, 0x102, 0x310 (higher priority - lower numerical values)
- Motor Controller frames: 0x500-0x5FF range (lower priority - higher numerical values)
- Arbitration should heavily favor your VCU frames due to significantly lower numerical IDs
6. Isolation Testing Results
Motor Controller disconnected test:
- Same symptom persists: arrayindex2 increments (0x06→0x33) but no analyzer detection
- Eliminates bus contention: Completely ruled out arbitration conflicts
- Confirms issue specificity: Problem isolated to main application vs. simple test code
- Display also disconnected: Only VCU and Analyzer on bus during this test
7. Analyzer Validation
CAN analyzer functionality confirmed:
- Successfully receives Motor Controller data (0x500-0x5FF) when connected
- Successfully receives test code transmissions in simple scenarios
- Proper bit rate and configuration: Demonstrated by successful Motor Controller frame capture
- Hardware connections verified: Same physical setup works for other frame types
Critical Findings
1. Software Logic Confirmed Working
The arrayindex2 increment pattern definitively proves:
- Switch case processing is correct
- CAN_Send() function calls complete successfully
- Mailbox assignments (11-17 range) are properly configured
- Transmission timing (1-second delays) is implemented correctly
2. Hardware Functionality Verified
- CAN PAL 2 transceiver is functional: Proven by successful test code
- Physical bus connections are correct: Motor Controller frames received successfully
- No electrical/termination issues: Demonstrated by working scenarios
3. Priority Not the Issue
With Motor Controller using 0x500-0x5FF range and VCU using 0x100-0x310 range, arbitration heavily favors VCU frames. This is confirmed by Motor Controller disconnected test showing same symptoms.
Current Issue Analysis
The evidence points to a CAN frame acknowledgment (ACK) problem specific to your main application. The S32K FlexCAN controller successfully executes transmission commands and increments software counters, but the frames are not being acknowledged properly, causing them to never complete the full CAN protocol cycle.
Key Insight: ACK Requirement
Every CAN frame requires acknowledgment from at least one receiving device. In your setup:
- Motor Controller frames: Get acknowledged by Display (their intended receiver)
- Your VCU frames: Have no configured receivers on the shared bus to provide ACK
- Test code worked: Because analyzer was properly configured to acknowledge those specific frames
I would appriciate some help here.
P.S: I have extracted the Issue summary by a Claude AI generative AI after step by step interaction with it during my debug process inorder to have quick summary. Please comment to this post if any additional info is required inroder to rectifyu the issue
@Julián_AragónM