Hii,
Here I am trying to transmit some dummy data from S32K148 to USBCAN_FD Tool using standard CAN, but I am not able to receive any data at the tool and when I am debugging the code I am getting CAN clock not sync, so can you tell me where did i made the mistake and also here I am using TJA1042B CAN transducer. and I have configured it to active mode by setting the pin low.
And also I will share my code and Pics of the config what I did.













/*
* (c) Copyright 2020 NXP
*
* NXP Confidential. This software is owned or controlled by NXP and may only be used strictly
* in accordance with the applicable license terms. By expressly accepting
* such terms or by downloading, installing, activating and/or otherwise using
* the software, you are agreeing that you have read, and that you agree to
* comply with and are bound by, such license terms. If you do not agree to
* be bound by the applicable license terms, then you may not retain,
* install, activate or otherwise use the software.
*
* This file contains sample code only. It is not part of the production code deliverables.
*/
#ifdef __cplusplus
extern "C" {
#endif
/*==================================================================================================
* INCLUDE FILES
* 1) system and project includes
* 2) needed interfaces from external units
* 3) internal and external interfaces from this unit
==================================================================================================*/
#include "Mcu.h"
#include "Platform.h"
#include "Can_43_FLEXCAN.h"
#include "SchM_Can_43_FLEXCAN.h"
#include "check_example.h"
#include "stdio.h"
#include "Dio.h"
/*==================================================================================================
* LOCAL TYPEDEFS (STRUCTURES, UNIONS, ENUMS)
==================================================================================================*/
/*==================================================================================================
* LOCAL MACROS
==================================================================================================*/
/*==================================================================================================
* LOCAL CONSTANTS
==================================================================================================*/
/*==================================================================================================
* LOCAL VARIABLES
==================================================================================================*/
/*==================================================================================================
* GLOBAL CONSTANTS
==================================================================================================*/
uint8 Can_au8Sdu8bytes[8U] = {0x01U, 0x02U, 0x03U, 0x04U, 0x05U, 0x06U, 0x07U, 0x08};
/*==================================================================================================
* GLOBAL VARIABLES
==================================================================================================*/
uint8 CanIf_u8TxConfirmCnt = 0U;
boolean CanIf_bTxFlag = FALSE;
uint8 CanIf_u8RxIndicationCnt = 0U;
boolean CanIf_bRxFlag = FALSE;
Std_ReturnType status ;
uint8 dummyData1[8] = {0x11,0x11,0x11,0x11,0x11,0x11,0x11,0x11};
Can_PduType txPdu1;
uint8 rxData[8] = {0}; // Buffer for received data
Can_PduType rxPdu1; // Received PDU object
/*==================================================================================================
* LOCAL FUNCTION PROTOTYPES
==================================================================================================*/
void CAN_Transmit(uint8* data, uint8 length);
void CAN_Receive(void);
void CAN_WaitForClockSync(void);
/*==================================================================================================
* LOCAL FUNCTIONS
==================================================================================================*/
/**
* @brief Wait for CAN controller to synchronize with CAN bus clock.
* This should be called after CAN controller is set to STARTED mode.
* The function will timeout if clock synchronization is not achieved.
*/
/*==================================================================================================
* GLOBAL FUNCTIONS
==================================================================================================*/
void CanIf_ControllerBusOff(uint8 ControllerId)
{
(void)ControllerId;
}
void CanIf_ControllerModeIndication(uint8 ControllerId, Can_ControllerStateType ControllerMode )
{
(void)ControllerId;
(void)ControllerMode;
}
void CanIf_TxConfirmation(PduIdType CanTxPduId)
{
CanIf_u8TxConfirmCnt++;
CanIf_bTxFlag = TRUE;
(void)CanTxPduId;
}
void CanIf_RxIndication(const Can_HwType* Mailbox, const PduInfoType* PduInfoPtr )
{
CanIf_u8RxIndicationCnt++;
CanIf_bRxFlag = TRUE;
// Copy received data to local buffer for CAN_Receive()
if ((PduInfoPtr != NULL_PTR) && (PduInfoPtr->SduLength <= 8)) {
for (uint8 i = 0; i < PduInfoPtr->SduLength; i++)
{
rxData[i] = PduInfoPtr->SduDataPtr[i];
}
rxPdu1.id = Mailbox->CanId;
rxPdu1.length = PduInfoPtr->SduLength;
rxPdu1.sdu = rxData;
}
(void)Mailbox;
(void)PduInfoPtr;
}
void Can_DummyDelay(uint32 loops)
{
VAR( volatile uint32, CAN_VAR) data = 0xAA55AA55;
VAR( volatile uint32, CAN_VAR) contor1 = 0;
VAR( volatile uint32, CAN_VAR) contor2 = loops;
do
{
for (contor1 = 0; contor1 < 0x2FF; contor1++)
{
data ^= (1 << contor1) | (0xAAAAAA | contor2);
}
contor2--;
} while( contor2 > 0);
}
Can_PduType Can_CreatePduInfo(Can_IdType id, PduIdType swPduHandle, uint8 length, uint8* sdu)
{
Can_PduType PduInfo;
PduInfo.id = id;
PduInfo.swPduHandle = swPduHandle;
PduInfo.length = length;
PduInfo.sdu = sdu;
return PduInfo;
}
uint32_t counter1=0;
uint32_t counter2=0;
uint32_t counter3=0;
uint8_t step=0;
// Function for CAN transmit
void CAN_Transmit(uint8* data, uint8 length)
{
Can_PduType txPdu;
txPdu.id = 0x111; // Example CAN ID
txPdu.length = length;
txPdu.swPduHandle = 0;
txPdu.sdu = data;
status = Can_43_FLEXCAN_Write(CanHardwareObject_TX, &txPdu);
if(status==E_OK)
{
printf("CAN_Transmit: Transfer successful\n");
}
else
{
printf("CAN_Transmit: Transfer not successful!!\n");
}
}
int main(void)
{
CanIf_bTxFlag = FALSE;
CanIf_bRxFlag = FALSE;
#if (MCU_PRECOMPILE_SUPPORT == STD_ON)
Mcu_Init(NULL_PTR);
#elif (MCU_PRECOMPILE_SUPPORT == STD_OFF)
Mcu_Init(&Mcu_Config_VS_0);
#endif /* (MCU_PRECOMPILE_SUPPORT == STD_ON) */
/* Initialize the clock tree and apply PLL as system clock */
Mcu_InitClock(McuClockSettingConfig_0);
#if (MCU_NO_PLL == STD_OFF)
while ( MCU_PLL_LOCKED != Mcu_GetPllStatus() )
{
/* Busy wait until the System PLL is locked */
}
Mcu_DistributePllClock();
#endif
Mcu_SetMode(McuModeSettingConf_0);
/* Initialize Platform driver */
Platform_Init(NULL_PTR);
Can_43_FLEXCAN_Init(NULL_PTR);
Dio_WriteChannel(DioConf_DioChannel_DioChannel_CANSTDBY,STD_LOW);
Can_43_FLEXCAN_SetControllerMode(CanController_0, CAN_CS_STARTED);
/* ------- */
txPdu1.id = 0x111;
txPdu1.length = 8;
txPdu1.swPduHandle = 0;
txPdu1.sdu = dummyData1;
while(1)
{
// Example: transmit and attempt to receive
CAN_Transmit(dummyData1, 8);
Can_DummyDelay(0xFFFFF);
}
return (0U);
}
#ifdef __cplusplus
}
#endif
/** @} */