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.

CCS/TMS320F28335: Program for continuous massage transmission/receive on CAN bus

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Hello,

I want to change the control suite eCAN example of f28335 to transmit message continuously over a CAN bus . I have modified the program as mentioned below. But I am not seeing any changes on the CAN pins(i.e. eCANA 31 and 30).

Basically I want a program which will send massage over CAN and receive some massages for the same.

One more query if we are not using any CAN trans-reciver as of now with controller, Is it possible to see the signal change from CAN pins of the controller by Oscilloscope.(In transmitting mode)

Regards,

Vishal

Script as follows:


#include "DSP28x_Project.h" // Device Headerfile and Examples Include File


Uint32 PassCount=0;


void main(void)
{


// eCAN control registers require read/write access using 32-bits. Thus we
// will create a set of shadow registers for this example. These shadow
// registers will be used to make sure the access is 32-bits and not 16.
struct ECAN_REGS ECanaShadow;

// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
InitSysCtrl();

// Step 2. Initialize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio(); // Skipped for this example

// For this example, configure CAN pins using GPIO regs here
// This function is found in DSP2833x_ECan.c
InitECanGpio();

// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
DINT;

// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:
IER = 0x0000;
IFR = 0x0000;

// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example. This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
InitPieVectTable();

// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example

// Step 5. User specific code, enable interrupts:


InitECana(); // Initialize eCAN-A module

// Mailboxes can be written to 16-bits or 32-bits at a time
// Write to the MSGID field of TRANSMIT mailboxes MBOX0 - 15
ECanaMboxes.MBOX0.MSGID.all = 0x9555AAA0;

// Write to the MSGID field of RECEIVE mailboxes MBOX16 - 31


// Configure Mailboxes 0-15 as Tx, 16-31 as Rx
// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
ECanaRegs.CANMD.all = 0xFFFF0000;

// Enable all Mailboxes */
// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
ECanaRegs.CANME.all = 0xFFFFFFFF;

// Specify that 8 bits will be sent/received
ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;

// Write to the mailbox RAM field of MBOX0 - 15
ECanaMboxes.MBOX0.MDL.all = 0x9555AAA0;
ECanaMboxes.MBOX0.MDH.all = 0x89ABCDEF;

// Since this write is to the entire register (instead of a bit
// field) a shadow register is not required.
EALLOW;
ECanaRegs.CANMIM.all = 0xFFFFFFFF;

// Configure the eCAN for self test mode
// Enable the enhanced features of the eCAN.
EALLOW;
ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
ECanaShadow.CANMC.bit.STM = 0; // Configure CAN for self-test mode
ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
EDIS;

// Begin transmitting
for(;;)
{
PassCount++;
ECanaRegs.CANTRS.all = 0x00000001; // Set TRS for all transmit mailboxes
while(ECanaRegs.CANTA.all != 0x00000001 ) {} // Wait for all TAn bits to be set..

ECanaRegs.CANTA.all = 0x00000001; // Clear all TAn


//Read from Receive mailboxes and begin checking for data */

}
}

  • You need a transceiver connected to the CANTX pin even to see the waveform. If you don't have the 2nd node connected, the frame will be re-transmitted forever. You can see this in the scope.

  • Why at least one more node is needed:

     

    When a node transmits a frame on the CAN bus, it expects an ACKnowledgement from at least one other node on the network. The receiving node that provides the ACK does not need to be the intended recipient of the frame, although it could very well be. When the transmitting node does not receive an ACK, it results in ACKnowledge error and it keeps re-transmitting the frame forever. In this situation, the TA bit for the transmitting mailbox does not get set at all and code will be looping there forever. No interrupts will be generated either. If it is not feasible to connect another node, run this code in self-test mode. For proper operation, the CAN_H pins of all CAN nodes must be connected together and likewise the CAN_L pins. The bus also should be terminated correctly on either ends (only).

     

    Why transceiver is needed:

     

    You cannot directly connect CANTX of node-A to CANRX of node-B and vice versa and expect successful CAN communication. In this case, CAN is unlike other serial interfaces like SCI or SPI or McBSP. For example, SCI can be made to work with a RS232 transceiver or through a direct connection. However, CAN bus needs a CAN transceiver. Why a transceiver is needed? In addition to converting the single-ended CAN signal for differential transmission, the transceiver also loops back the CANTX to the CANRX pin of a node. This is because a CAN node needs to be able to monitor its own transmission. Why? This has to do with the ACK requirement mandated by the CAN protocol. When a node transmits a frame on the CAN bus, it expects an ACKnowledgement from at least one other node on the network. The receiving node that provides the ACK does not have to be the intended recipient of the frame, although it could very well be. When the transmitting node does not receive an ACK, it results in ACKnowledge error and it keeps re-transmitting the frame forever. In this situation, the TA bit for the transmitting mailbox does not get set at all and code will be looping there forever. No interrupts will be generated either. For the ACK phase, the transmitter puts out a 1 and expects to read back a 0.

     

    If you are new to CAN, I strongly urge you to download SLOA101A from the TI website and read it cover-to-cover.

  • Another excellent app.note for Physical Layer understanding is SLYT529 Debugging_CAN-PHY-SLYT529.pdf