This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LS3137: CAN masks in interrupt data adquisition

Part Number: TMS570LS3137
Other Parts Discussed in Thread: HALCOGEN

Im trying to use CAN2 for comunication, however the rx interrupt is not beeing triggered,
If i try to make the connection in loopback, there is no issue, but when i change the id or use
a different device for sending data, the interrupt is never triggered. 

 I have VIM 45 and 35 enabled and also CAN Driver for CAN 2 and 3 

(i have the same configuration in can2 and 3 to check if there might be another error)

/** @file sys_main.c 
*   @brief Application main file
*   @date 11-Dec-2018
*   @version 04.07.01
*
*   This file contains an empty main function,
*   which can be used for the application.
*/

/* 
* Copyright (C) 2009-2018 Texas Instruments Incorporated - www.ti.com 
* 
* 
*  Redistribution and use in source and binary forms, with or without 
*  modification, are permitted provided that the following conditions 
*  are met:
*
*    Redistributions of source code must retain the above copyright 
*    notice, this list of conditions and the following disclaimer.
*
*    Redistributions in binary form must reproduce the above copyright
*    notice, this list of conditions and the following disclaimer in the 
*    documentation and/or other materials provided with the   
*    distribution.
*
*    Neither the name of Texas Instruments Incorporated nor the names of
*    its contributors may be used to endorse or promote products derived
*    from this software without specific prior written permission.
*
*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
*  "AS IS" AND ANY EXPRESS 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 THE COPYRIGHT 
*  OWNER OR 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.
*
*/


/* USER CODE BEGIN (0) */
/* Includes */
#include "system.h"
#include "spi.h"
#include "het.h"
#include "gio.h"
#include "reg_pcr.h"
#include "sys_pcr.h"
#include "sys_pmm.h"
#include "reg_vim.h"
#include "sci.h"
#include "string.h"
#include "reg_can.h"
#include "can.h"
#include "sys_common.h"
#include "sys_core.h"
#include "sys_vim.h"
#include "reg_mibspi.h"
#include "reg_can.h"
#include "adc.h"
#include "i2c.h"
#include "esm.h"
/* USER CODE END */

/* Include Files */

#include "sys_common.h"

/* USER CODE BEGIN (1) */
/* USER CODE END */

/** @fn void main(void)
*   @brief Application main function
*   @note This function is empty by default.
*
*   This function is called after startup.
*   The user can use this function to implement the application.
*/

/* USER CODE BEGIN (2) */
/* Globals */

typedef struct qMessage3
{
    uint32_t    id;
    uint8_t     buffer[8];
    uint8_t     interface;
} xMessage3;

uint32 tx_done = 0;
uint32 rx_unread = 0;
xMessage3 rx_data;


void sysInit(void);
void canTest(void);
void dumpSomeData();

/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
    sysInit();
    canTest();
    while(1);
/* USER CODE END */

    return 0;
}


/* USER CODE BEGIN (4) */

void canTest()
{
    uint8_t tx_data[8] = {0x03, 0x0A, 0x03, 0x0A, 0x0B, 0x0C, 0x0B, 0x0A};
    uint8 *tx_ptr = &tx_data[0];
    uint32 newCanId = 0xA;
    uint32 ArbValue;

    sciSend(scilinREG, 34, (unsigned char *)"\r\n********************************");
    sciSend(scilinREG, 34, (unsigned char *)"\r\n**********  CAN test  **********");
    sciSend(scilinREG, 34, (unsigned char *)"\r\n********************************");
    sciSend(scilinREG, 2,  (unsigned char *)"\r\n");
    sciSend(scilinREG, 12, (unsigned char *)"\r\nDeveloper:");
    sciSend(scilinREG, 26, (unsigned char *)"\r\n           Marco Mecha\r\n");
    sciSend(scilinREG, 2,  (unsigned char *)"\r\n");

    ArbValue  = canREG2->IF2ARB;
    ArbValue &= 0xF0000000;
    ArbValue |= newCanId;

    canUpdateID(canREG2, canMESSAGE_BOX1, ArbValue);

    if(!canTransmit(canREG2, canMESSAGE_BOX1, tx_ptr)){
        sciSend(scilinREG, 26, "Error in data transmission");
    }

    while(!tx_done){};
    tx_done=0;

    sciSend(scilinREG, 13, "Transmitted: ");
    sciDisplayData(scilinREG, tx_ptr, 8);
    sciSend(scilinREG, 2, "\r\n");

    while(1){
        while(!rx_unread){};  //The code does not go beyond this 

        sciSend(scilinREG, 12, "Received:   ");
        sciDisplayData(scilinREG, (uint8_t *)&(rx_data.buffer), 8);
        sciSend(scilinREG, 2, "\r\n");
        sciSend(scilinREG, 4, "Id: ");
        sciDisplayData(scilinREG, (uint8_t *)&(rx_data.id), 4);
        sciSend(scilinREG, 2, "\r\n");

        rx_unread = 0;
    }
}


void sysInit()
{
    uint8_t generic = 0;

    sciInit();                                      //SCI initialization.
    canInit();                                      //CAN initialization.

    //Enable interrupts:
    _enable_interrupt_();                           //General interrupt flag.

    //Enable SCI interrupt:
    sciEnableNotification(scilinREG,SCI_RX_INT);    //Enable SCI Lin interrupt by Rx.
    sciEnableNotification(sciREG,SCI_RX_INT);       //Enable SCI interrupt by Rx.

    //Enable CAN interrupt:
    canEnableErrorNotification(canREG2);            //Enable canREG2 interrupt.
    canEnableErrorNotification(canREG3);            //Enable canREG3 interrupt.

    canEnableStatusChangeNotification(canREG2);
    canEnableStatusChangeNotification(canREG3);



    sciReceive(scilinREG,1, (unsigned char *)&generic);

    sciSend(scilinREG, 2,  (unsigned char *)"\r\n");
    sciSend(scilinREG, 37, (unsigned char *)"Initializing system. Please wait...\r\n");
    gioInit();                                      //GIO module initialization.
    gioSetDirection(hetPORT1, 1 << 15);             //Enable N2HET1[15] as output. This is the output signal to the external watch-dog.
    gioSetDirection(spiPORT3, 0x11);                //to set the SPI3NCS[0] to output direction. The SPI3NCS[0] is the bit0 of SPIPC1 register.
                                                    //to set the SPI3NCS[4] to output direction. The SPI3NCS[4] is the bit4 of SPIPC1 register.
    gioSetDirection(mibspiPORT5, 0 <<9);
    gioSetDirection(mibspiPORT1, 0 <<1);

    //By default we set the GIO pins for long test as follows:

    gioSetDirection(mibspiPORT1, (0 << 9));         //Set MibSPI1_CLK direction. This is the bit 9 in the SPIPC3 register.
    gioSetDirection(gioPORTA, (0 << 6));            //Set GIOA[6] direction. This is the bit 6 of GIODIRA register.
    gioSetDirection(mibspiPORT1, (1 << 11));        //Set MibSPI1_SOMI[0] direction. This is the bit 11 in the SPIPC3 register.
    gioSetDirection(mibspiPORT1, (1 << 10));        //Set MibSPI1_SIMO[0] direction. This is the bit 10 in the SPIPC3 register.
    gioSetBit(mibspiPORT1, 10, 0);                  //We set the GIOs as logic 0
    gioSetBit(mibspiPORT1, 11, 0);                  //We set the GIOs as logic 0


    gioSetBit(spiPORT3, 0, 1);                      //Disable External memories SPI communication
    gioSetBit(spiPORT3, 4, 1);                      //Disable External memories SPI communication

    sciSend(scilinREG, 27, (unsigned char *)"\t************************\r\n");
    sciSend(scilinREG, 27, (unsigned char *)"\tLabOSat-02 [OBC] OS V1.0\r\n");
    sciSend(scilinREG, 27, (unsigned char *)"\t************************\r\n");
    sciSend(scilinREG, 1, (unsigned char *)"\n");
    sciSend(scilinREG, 14, (unsigned char *)"Developers: \r\n");
    sciSend(scilinREG, 30, (unsigned char *)"\t Gagliardi Leandro Luciano \r\n");
    sciSend(scilinREG, 22, (unsigned char *)"\t Di Nardo Federico \r\n");
    sciSend(scilinREG, 1, (unsigned char *)"\n");
}

/*********************************
 * SCI interrupt service routine *
 *********************************/
void sciNotification(sciBASE_t *sci, unsigned flags)
{
    uint8_t *rxKey = NULL;
    if(sci == scilinREG)
    {
        sciReceive(scilinREG, 1, rxKey);
        sciSend(sci, sizeof(uint8_t), rxKey);
    }
}

/*********************************
 * CAN interrupt service routine *
 *********************************/

void canMessageNotification(canBASE_t *node, uint32 messageBox)
{
    if(node==canREG2)
    {
        switch(messageBox){
           case canMESSAGE_BOX1:
               tx_done=1; /* confirm transfer request */
               break;
           case canMESSAGE_BOX2:
               while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX2));
               canGetData(canREG2, canMESSAGE_BOX2, &(rx_data.buffer[0]));
               rx_data.id = canGetID(node, messageBox);
               rx_unread = 1;
               break;
        }
    }

    if(node==canREG3)
    {
        switch(messageBox){
            case canMESSAGE_BOX1:
                tx_done=1; /* confirm transfer request */
                break;
            case canMESSAGE_BOX2:
                while(!canIsRxMessageArrived(canREG3, canMESSAGE_BOX2));
                canGetData(canREG3, canMESSAGE_BOX2, &(rx_data.buffer[0]));
                rx_data.id = canGetID(node, messageBox);
                rx_unread = 1;
                break;
        }
    }
}

/* USER CODE END */

  • Hi Marco,

    I am working on your issue and will try to update my response ASAP.

    --
    Thanks & regards,
    Jagadish.

  • Hi Marco,

    I don't have a hardware setup with me now, can we please setup one live debugging session? So that you can share your screen and explain the issue, i will try to provide my suggestions to rectify the issue.

    If you are okay with it then please create one meeting request and share with me. I will be available from 10AM to 8PM IST (Indian Standard Time).

    --
    Thanks & regards,
    Jagadish.

  • Ok, 


    (Sin título)
    Viernes, 17 de mayo · 9:00 – 10:00am
    Zona horaria: America/Argentina/Buenos_Aires
    Información para unirse con Google Meet
    Enlace de la videollamada: meet.google.com/xti-nfpn-onh

  • Hi Marco,

    Sorry i don't understand timings.

    Please tell me the meeting time in Indian Standard Time. I will login in that time.

    --
    Thanks & regards,
    Jagadish.

  • Hi Marco,

    Do you get a chance to change the CAN ID for Arduino board to the extended ID?

    Any updates on this?

    --
    Thanks & Regards,
    Jagadish.

  • Yes, i replaced it but still couldn´t make it work.
    But then i make this change and this fixed everithing, now in receving without problem

    canREG2->IF1MCTL = 0x00001000U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;

    i need to read how con i hange this in HalCoGen, because otherwise the code is modiffied
  • Hi Marco,

    If i understand correctly:

    Previously: canREG2->IF1MCTL = 0x00001000U | (uint32)0x00000400U| (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;

    Modified: canREG2->IF1MCTL = 0x00001000U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;

    This is the change you made right?

    If this is the case, then you are disabling the receive interrupt:

    If you did that then "canMessageNotification" will not get called right for receiving data? Then how you are saying that it is working without any issues. Are you testing in polling mode?

    --
    Thanks & regards,
    Jagadish.

  • Previously
    canREG2
    ->IF2MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000200U | (uint32)0x00000000U | (uint32)8U;

    Modified
    canREG2->IF2MCTL = 0x00001000U | (uint32)0x00000400U | (uint32)0x00000000U | (uint32)0x00000000U | (uint32)8U;
    With this new code im changing this bit


     But the code is working as i expected originaly and trigering interrupts
  • Hi Marco,

    Maybe you are confused, because it is not 10th bit, and it is 9th bit.

    The main functionality of this bit is that we can enable the transmission of data frame automatically after we received a matching frame. As mentioned above at reception of a matching remote frame the TxRqst bit will get set and packet will get transmitted.

    And this RmtEn bit should be zero for configuration of receive data frames, please verify below information:

    As you can see for receive data frames configuration this bit should always zero.

    And this bit configuration is only allowed for transmit data frame configuration, please refer below information:

    This bit configuration is only allowed in the transmission data frame configuration, so if we set this bit for a transmitted frame then TxRqst enable bit of this frame will only get set after it receives a matching frame.

    So, keep this bit zero for to receive data frames.

    --
    Thanks & regards,
    Jagadish.