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 */





