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.

TMS320F280049C: CAN bus implementation for F280049C controller

Part Number: TMS320F280049C
Other Parts Discussed in Thread: DRV8301, TMDSADAP180TO100, C2000WARE

Hi,

I am unable to communicate with CAN and I need some help.

Setup: I am using the DRV8301 kit with the F280049C control card and TMDSADAP180TO100. I have a USB to CAN adapter. I am using the example 3 from driver lib for external transmit.

I have edited the code so that only CANA is configured and CANB is not. 

I get an error on the USB to CAN device software and on the CCS - there is an error of 0x5 which I understand that it means the following:

The bus remained a bit level of 0 for longer than is allowed.

What could be the possible reasons for this? Can you help me with debugging?

(the USB to CAN device is configured for 500kbit/s, tseg1 = 9, tseg2 = 6, sjw=4)

This is the code:

//#############################################################################
//
// FILE: can_ex3_external_transmit.c
//
// TITLE: CAN External Transmit Example
//
//! \addtogroup driver_example_list
//! <h1> CAN-A to CAN-B External Transmit </h1>
//!
//! This example initializes CAN module A and CAN module B for external
//! communication. CAN-A module is setup to transmit incrementing data for "n"
//! number of times to the CAN-B module, where "n" is the value of TXCOUNT.
//! CAN-B module is setup to trigger an interrupt service routine (ISR) when
//! data is received. An error flag will be set if the transmitted data doesn't
//! match the received data.
//!
//! \note Both CAN modules on the device need to be
//! connected to each other via CAN transceivers.
//!
//! \b Hardware \b Required \n
//! - A C2000 board with two CAN transceivers
//!
//! \b External \b Connections \n
//! - ControlCARD CANA is on GPIO31 (CANTXA) and GPIO30 (CANRXA)
//! - ControlCARD CANB is on GPIO8 (CANTXB) and GPIO10 (CANRXB)
//!
//! \b Watch \b Variables \n
//! - TXCOUNT - Adjust to set the number of messages to be transmitted
//! - txMsgCount - A counter for the number of messages sent
//! - rxMsgCount - A counter for the number of messages received
//! - txMsgData - An array with the data being sent
//! - rxMsgData - An array with the data that was received
//! - errorFlag - A flag that indicates an error has occurred
//!
//
//#############################################################################
// $TI Release: F28004x Support Library v1.05.00.00 $
// $Release Date: Thu Oct 18 15:43:57 CDT 2018 $
// $Copyright:
// Copyright (C) 2018 Texas Instruments Incorporated - http://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.
// $
//#############################################################################

//
// Included Files
//
#include "driverlib.h"
#include "device.h"

//
// Defines
//
#define TXCOUNT 1000000
#define MSG_DATA_LENGTH 4
#define TX_MSG_OBJ_ID 1
#define RX_MSG_OBJ_ID 1

//
// Globals
//
volatile unsigned long i;
volatile uint32_t txMsgCount = 0;
volatile uint32_t rxMsgCount = 0;
volatile uint32_t errorFlag = 0;
uint16_t txMsgData[4];
uint16_t rxMsgData[4];
uint16_t get_ts1;
uint16_t get_ts2;
float get_sjw;
//
// Function Prototypes
//
__interrupt void canbISR(void);

//
// Main
//
void main(void)
{
//
// Initialize device clock and peripherals
//
Device_init();

//
// Initialize GPIO and configure GPIO pins for CANTX/CANRX
// on module A and B
//
Device_initGPIO();
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXA);
GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXA);
//GPIO_setPinConfig(DEVICE_GPIO_CFG_CANRXB);
//GPIO_setPinConfig(DEVICE_GPIO_CFG_CANTXB);

//
// Initialize the CAN controllers
//
CAN_initModule(CANA_BASE);
//CAN_initModule(CANB_BASE);

//
// Set up the CAN bus bit rate to 500kHz for each module
// Refer to the Driver Library User Guide for information on how to set
// tighter timing control. Additionally, consult the device data sheet
// for more information about the CAN module clocking.
//
CAN_setBitRate(CANA_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);
//CAN_setBitRate(CANB_BASE, DEVICE_SYSCLK_FREQ, 500000, 16);

//
// Enable interrupts on the CAN B peripheral.

//CAN_enableInterrupt(CANB_BASE, CAN_INT_IE0 | CAN_INT_ERROR |
// CAN_INT_STATUS);

//
// Initialize PIE and clear PIE registers. Disables CPU interrupts.
//
Interrupt_initModule();

//
// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
//
Interrupt_initVectorTable();

//
// Enable Global Interrupt (INTM) and realtime interrupt (DBGM)
//
EINT;
ERTM;

//
// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
// This registers the interrupt handler in PIE vector table.
//
//Interrupt_register(INT_CANB0, &canbISR);

//
// Enable the CAN-B interrupt signal
//
//Interrupt_enable(INT_CANB0);
//CAN_enableGlobalInterrupt(CANB_BASE, CAN_GLOBAL_INT_CANINT0);

//
// Initialize the transmit message object used for sending CAN messages.
// Message Object Parameters:
// CAN Module: A
// Message Object ID Number: 1
// Message Identifier: 0x95555555
// Message Frame: Extended
// Message Type: Transmit
// Message ID Mask: 0x0
// Message Object Flags: None
// Message Data Length: 4 Bytes
//
CAN_setupMessageObject(CANA_BASE, TX_MSG_OBJ_ID, 0x95555555,
CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_TX, 0,
CAN_MSG_OBJ_NO_FLAGS, MSG_DATA_LENGTH);

//
// Initialize the receive message object used for receiving CAN messages.
// Message Object Parameters:
// CAN Module: B
// Message Object ID Number: 1
// Message Identifier: 0x95555555
// Message Frame: Extended
// Message Type: Receive
// Message ID Mask: 0x0
// Message Object Flags: Receive Interrupt
// Message Data Length: 4 Bytes
//
//CAN_setupMessageObject(CANB_BASE, RX_MSG_OBJ_ID, 0x95555555,
// CAN_MSG_FRAME_EXT, CAN_MSG_OBJ_TYPE_RX, 0,
// CAN_MSG_OBJ_RX_INT_ENABLE, MSG_DATA_LENGTH);

//
// Initialize the transmit message object data buffer to be sent
//
txMsgData[0] = 0x12;
txMsgData[1] = 0x34;
txMsgData[2] = 0x56;
txMsgData[3] = 0x78;

//
// Start CAN module A and B operations
//
CAN_startModule(CANA_BASE);
//CAN_startModule(CANB_BASE);

//
// Transmit messages from CAN-A to CAN-B
//
for(i = 0; i < TXCOUNT; i++)
{
//
// Check the error flag to see if errors occurred
//
if(errorFlag)
{
asm(" ESTOP0");
}

//
// Verify that the number of transmitted messages equal the number of
// messages received before sending a new message
//
//if(txMsgCount == rxMsgCount)
//{
CAN_sendMessage(CANA_BASE, TX_MSG_OBJ_ID, MSG_DATA_LENGTH,txMsgData);
txMsgCount++;
//}
//else
//{
// errorFlag = 1;
//}

//
// Delay before continuing
//
DEVICE_DELAY_US(2500);

//
// Increment the value in the transmitted message data.
//
txMsgData[0] += 0x01;
txMsgData[1] += 0x01;
txMsgData[2] += 0x01;
txMsgData[3] += 0x01;

//
// Reset data if exceeds a byte
//
if(txMsgData[0] > 0xFF)
{
txMsgData[0] = 0;
}
if(txMsgData[1] > 0xFF)
{
txMsgData[1] = 0;
}
if(txMsgData[2] > 0xFF)
{
txMsgData[2] = 0;
}
if(txMsgData[3] > 0xFF)
{
txMsgData[3] = 0;
}
}

//
// Stop application
//
asm(" ESTOP0");
}