Not able to read receiving CAN message in MultiCANBasic Demo code (TASKING TOOLSET IDE)

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
arkapravasain
Level 1
Level 1
5 replies posted 10 sign-ins 5 sign-ins

Dear Community

I am using AURIX Tricore Microcontroller TC234 with Tasking Toolset IDE.

I am generating CAN messages with some specified message IDS from another Node, which I want to receive in my TC234 ECU and check for a particular message ID eg. 0x630, and if such a message is received, I am calling a function MultiCanBasicDemo_run(), which I have attached below.

 

void MulticanBasicDemo_run(void)
{
    const uint32 dataLow  = 0x00000000;
    const uint32 dataHigh = 0x00000000;
    /* Transmit Data */
    {
        IfxMultican_Message msg;
        IfxMultican_Message_init(&msg, id, dataLow, dataHigh, IfxMultican_DataLengthCode_8);

        while (TRUE)
        {
        if(IfxMultican_Can_MsgObj_sendMessage(&g_MulticanBasic.drivers.canSrcMsgObj, &msg) == IfxMultican_Status_busOff)
           break;
        }


    }

}

 

 

Currently The message with ID 0x630 is being generated and that is visible in CAN BUS monitor as well. However the below code snippet for receiving the CAN message is not working. I have written this code in cpu0. Please check the below snippet.

 

uint32 id;
    const uint32 dataLow = 0x02000125;
    const uint32 dataHigh = 0x010acdfe;
    while (TRUE)
    {
IfxMultican_Can_MsgObj_readMessage(&g_MulticanBasic1.drivers.canSrcMsgObj, &rxMsg);
    IfxMultican_Message_init(&rxMsg, id, dataLow, dataHigh, IfxMultican_DataLengthCode_8);

    if(rxMsg.id == 0x630)
    {
    MulticanBasicDemo_run();
        }
    }

 

 

Can you help me with the correct code for receiving messages, check their ID and if that ID matches with 0x630, my MulticanBasicDemo_run() function would work. 

Thanking You

Regards

Arka

 

 

 

 

 

0 Likes
1 Solution
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Here is a demonstration of the tc234 MultiCAN functionality:

(1) Initial Setup

Start by using the provided project available at:

https://github.com/Infineon/AURIX_code_examples/tree/master/code_examples/Blinky_LED_1_KIT_TC234_TFT

(2) Loopback Mode Testing

Utilize the provided code package named "code 1.zip" to enable loopback mode.
Debug the tc234 tribaord v2.0 using the ARUX Development Studio (ADS).
Set breakpoints within the code to pause at the RX interrupt.
Observe the behavior by watching the LED status; specifically, ensure that two LEDs are illuminated.
(3) Non-Loopback Mode 

Next, disable the loopback mode using the "code2.zip" package.
Configure Node 0 for both transmission (TX) and reception (RX).
Use a CAN analyzer to monitor the incoming and outgoing CAN frames.
Set breakpoints within the RX interrupt to analyze the frame reception.
By following these steps, you can effectively test and analyze the tc234 MultiCAN capabilities.

 

dw_0-1692092179208.png

 

View solution in original post

0 Likes
9 Replies
FD_aurix
Level 5
Level 5
100 sign-ins 100 replies posted 5 solutions authored

No snipped code is present:-\

0 Likes

Really sorry for that, Kindly  check the updated question

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi arkapravasain,

Could you please explain a bit more for your request?

Thanks.

dw

0 Likes

Really Sorry for that, I have updated my question. Kindly check

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi arkapravasain,

https://github.com/Infineon/AURIX_code_examples/tree/master/code_examples/MULTICAN_1_KIT_TC275_LK

Please refer to above source code, and you could modify the below ISR to your need. 

void canIsrRxHandler(void)
{
    IfxMultican_Status readStatus;

    /* Read the received CAN message and store the status of the operation */
    readStatus = IfxMultican_Can_MsgObj_readMessage(&g_multican.canDstMsgObj, &g_multican.rxMsg);

    /* If no new data has been received, report an error */
    if( !( readStatus & IfxMultican_Status_newData ) )
    {
        while(1)
        {
        }
    }

    /* If new data has been received but with one message lost, report an error */
    if( readStatus == IfxMultican_Status_newDataButOneLost )
    {
        while(1)
        {
        }
    }

    /* Finally, check if the received data matches with the transmitted one */
    if( ( g_multican.rxMsg.data[0] == g_multican.txMsg.data[0] ) &&
        ( g_multican.rxMsg.data[1] == g_multican.txMsg.data[1] ) &&
        ( g_multican.rxMsg.id == g_multican.txMsg.id ) )
    {
        /* Turn on the LED2 to indicate correctness of the received message */
        IfxPort_setPinLow(g_led.led2.port, g_led.led2.pinIndex);
    }
}

 dw

0 Likes

Thanks for your reply, I am a bit confused though

I was not using this ISR function earlier while checking for the received messages. why is it necessary to use a ISR while receiving but not transmitting?

I am using Tasking toolset whose MulticanBasic_demo code does not use Interrupt and does not have ISR function. Kindly check this attachment MulticanBasic_demo.c code.

 

/**
 * \file MulticanBasicDemo.c
 * \brief Demo MulticanBasicDemo
 *
 * \version iLLD_Demos_1_0_1_10_0
 * \copyright Copyright (c) 2014 Infineon Technologies AG. All rights reserved.
 *
 *
 *                                 IMPORTANT NOTICE
 *
 *
 * Infineon Technologies AG (Infineon) is supplying this file for use
 * exclusively with Infineon's microcontroller products. This file can be freely
 * distributed within development tools that are supporting such microcontroller
 * products.
 *
 * THIS SOFTWARE IS PROVIDED "AS IS".  NO WARRANTIES, WHETHER EXPRESS, IMPLIED
 * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE.
 * INFINEON SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL,
 * OR CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER.
 */

/******************************************************************************/
/*----------------------------------Includes----------------------------------*/
/******************************************************************************/

#include <stdio.h>
#include "MulticanBasicDemo.h"

/******************************************************************************/
/*-----------------------------------Macros-----------------------------------*/
/******************************************************************************/

/******************************************************************************/
/*--------------------------------Enumerations--------------------------------*/
/******************************************************************************/

/******************************************************************************/
/*-----------------------------Data Structures--------------------------------*/
/******************************************************************************/

/******************************************************************************/
/*------------------------------Global variables------------------------------*/
/******************************************************************************/

App_MulticanBasic g_MulticanBasic; /**< \brief Demo information */

/******************************************************************************/
/*-------------------------Function Prototypes--------------------------------*/
/******************************************************************************/

/******************************************************************************/
/*------------------------Private Variables/Constants-------------------------*/
/******************************************************************************/

const unsigned id = 0x100;             /* message identifier */

/******************************************************************************/
/*-------------------------Function Implementations---------------------------*/
/******************************************************************************/

/** \addtogroup IfxLld_Demo_MulticanBasic_SrcDoc_Main_Interrupt
 * \{ */

/** \} */

/** \brief Demo init API
 *
 * This function is called from main during initialization phase
 */
void MulticanBasicDemo_init(void)
{
    /* create module config */
    IfxMultican_Can_Config canConfig;
    IfxMultican_Can_initModuleConfig(&canConfig, &MODULE_CAN);

    /* initialize module */
    IfxMultican_Can_initModule(&g_MulticanBasic.drivers.can, &canConfig);

    /* create CAN node config */
    IfxMultican_Can_NodeConfig canNodeConfig;
    IfxMultican_Can_Node_initConfig(&canNodeConfig, &g_MulticanBasic.drivers.can);

    canNodeConfig.baudrate = 1000000;     /* 1 MBaud
                                           *
                                           * Source Node */
    {
        canNodeConfig.nodeId    = (IfxMultican_NodeId)((int)IfxMultican_NodeId_0);
        canNodeConfig.rxPin     = &IfxMultican_RXD0B_P20_7_IN;
        canNodeConfig.rxPinMode = IfxPort_InputMode_pullUp;
        canNodeConfig.txPin     = &IfxMultican_TXD0_P20_8_OUT;
        canNodeConfig.txPinMode = IfxPort_OutputMode_pushPull;

        IfxMultican_Can_Node_init(&g_MulticanBasic.drivers.canSrcNode, &canNodeConfig);
    }

    /* Destination Node */
    {
        canNodeConfig.nodeId    = (IfxMultican_NodeId)((int)IfxMultican_NodeId_1);
        canNodeConfig.rxPin     = &IfxMultican_RXD1B_P14_1_IN;
        canNodeConfig.rxPinMode = IfxPort_InputMode_pullUp;
        canNodeConfig.txPin     = &IfxMultican_TXD1_P14_0_OUT;
        canNodeConfig.txPinMode = IfxPort_OutputMode_pushPull;

        IfxMultican_Can_Node_init(&g_MulticanBasic.drivers.canDstNode, &canNodeConfig);
    }

    /* Destination Message object */
    {
        /* create message object config */
        IfxMultican_Can_MsgObjConfig canMsgObjConfig;
        IfxMultican_Can_MsgObj_initConfig(&canMsgObjConfig, &g_MulticanBasic.drivers.canDstNode);

        canMsgObjConfig.msgObjId              = 0;
        canMsgObjConfig.messageId             = id;
        canMsgObjConfig.acceptanceMask        = 0x7FFFFFFFUL;
        canMsgObjConfig.frame                 = IfxMultican_Frame_receive;
        canMsgObjConfig.control.messageLen    = IfxMultican_DataLengthCode_8;
        canMsgObjConfig.control.extendedFrame = FALSE;
        canMsgObjConfig.control.matchingId    = TRUE;

        /* initialize message object */
        IfxMultican_Can_MsgObj_init(&g_MulticanBasic.drivers.canDstMsgObj, &canMsgObjConfig);
    }

    /* Source Message object  */
    {
        /* create message object config */
        IfxMultican_Can_MsgObjConfig canMsgObjConfig;
        IfxMultican_Can_MsgObj_initConfig(&canMsgObjConfig, &g_MulticanBasic.drivers.canSrcNode);

        canMsgObjConfig.msgObjId              = 1;
        canMsgObjConfig.messageId             = id;
        canMsgObjConfig.acceptanceMask        = 0x7FFFFFFFUL;
        canMsgObjConfig.frame                 = IfxMultican_Frame_transmit;
        canMsgObjConfig.control.messageLen    = IfxMultican_DataLengthCode_8;
        canMsgObjConfig.control.extendedFrame = FALSE;
        canMsgObjConfig.control.matchingId    = TRUE;

        /* initialize message object */
        IfxMultican_Can_MsgObj_init(&g_MulticanBasic.drivers.canSrcMsgObj, &canMsgObjConfig);
    }

    printf("Multican is Initialized\n");
}


/** \brief Demo run API
 *
 * This function is called from main, background loop
 */
void MulticanBasicDemo_run(void)
{
    const uint32 dataLow  = 0x12340000;
    const uint32 dataHigh = 0x9abc0000;

    uint32       errors   = 0;

    /* Transmit Data */
    {
        IfxMultican_Message msg;
        IfxMultican_Message_init(&msg, id, dataLow, dataHigh, IfxMultican_DataLengthCode_8);

        while (IfxMultican_Can_MsgObj_sendMessage(&g_MulticanBasic.drivers.canSrcMsgObj, &msg) == IfxMultican_Status_notSentBusy)
        {}
    }

    /* Receiving Data */
    {
        /* wait until MCAN received the frame */
        while (!IfxMultican_Can_MsgObj_isRxPending(&g_MulticanBasic.drivers.canDstMsgObj))
        {}

        IfxMultican_Message msg1;
        IfxMultican_Message_init(&msg1, 0xdead, 0xdeadbeef, 0xdeadbeef, IfxMultican_DataLengthCode_8); /* start with invalid values */

        IfxMultican_Status  readStatus = IfxMultican_Can_MsgObj_readMessage(&g_MulticanBasic.drivers.canDstMsgObj, &msg1);

        /* if no new data is been received report an error */
        if (!(readStatus & IfxMultican_Status_newData))
        {
            printf("ERROR: IfxMultican_Can_MsgObj_readMessage returned 0x%04x\n", readStatus);
        }

        /* if a new data is been received but one lost, report the status */
        if (readStatus == IfxMultican_Status_newDataButOneLost)
        {
            printf(" IfxMultican_Can_MsgObj_readMessage returned 0x%04x\n", readStatus);
        }

        /* check the received data */
        if (msg1.data[0] != dataLow)
        {
            ++errors;
        }

        if (msg1.data[1] != dataHigh)
        {
            ++errors;
        }

        if (errors)
        {
            printf("ERROR: Found (%d errors)\n", errors);
        }
        else
        {
            printf("OK: Checks passed\n");
        }
    }

    printf("Multican Basic data transactions are finished");
}

 

 

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Hi arkapravasain,

Using ISR is not a MUST but a good start point.

For your posted code, have you successfully received data with the Tasking demo?

 

dw

0 Likes

No, I haven't, I just  modified the code that I posted above, The same CAN readmessage function, Just removed all those if conditions for checking errors. I am not able to receive any data. I will try with ISR, which was in Aurix Example, will update you here in case of any progress.

0 Likes
Di_W
Moderator
Moderator
Moderator
500 solutions authored 1000 replies posted 250 solutions authored

Here is a demonstration of the tc234 MultiCAN functionality:

(1) Initial Setup

Start by using the provided project available at:

https://github.com/Infineon/AURIX_code_examples/tree/master/code_examples/Blinky_LED_1_KIT_TC234_TFT

(2) Loopback Mode Testing

Utilize the provided code package named "code 1.zip" to enable loopback mode.
Debug the tc234 tribaord v2.0 using the ARUX Development Studio (ADS).
Set breakpoints within the code to pause at the RX interrupt.
Observe the behavior by watching the LED status; specifically, ensure that two LEDs are illuminated.
(3) Non-Loopback Mode 

Next, disable the loopback mode using the "code2.zip" package.
Configure Node 0 for both transmission (TX) and reception (RX).
Use a CAN analyzer to monitor the incoming and outgoing CAN frames.
Set breakpoints within the RX interrupt to analyze the frame reception.
By following these steps, you can effectively test and analyze the tc234 MultiCAN capabilities.

 

dw_0-1692092179208.png

 

0 Likes