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: continous CAN Transmission

Part Number: TMS320F28335
Other Parts Discussed in Thread: SN65HVD230, CONTROLSUITE

Tool/software: Code Composer Studio

Hello all,

I am using the CAN module of F28335 experimenter kit. Basically I am using ADC to get the sensor data and transmitting this data over CAN. I trying to perform this in a continuous forever loop. I am using SN65HVD230 CAN transceivers. I also displaying  the sensor data onto Labview using serial communication. Hence, my code consists of serial, ADC, and CAN.

But the problem here is I am not able to continuously transmit the sensor data over CAN. The data is transmitted only once. After that any changes in sensor output does not reflect onto CAN transmission. Although I am able to see the continuous real time data onto Labview.

I am hereby attaching a part of my code for continuous transmission. Please suggest the required changes to be done.

for(;;)
{
for (i=0; i<AVG; i++)
{
while (AdcRegs.ADCST.bit.INT_SEQ1== 0) {} // Wait for interrupt
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[i] =((AdcRegs.ADCRESULT0>>4));
val = SampleTable[i];
f = val * 7.32600732e-4;
g = f * 33.898305084;

float n = g;
ftoa(n, res, 4);

float m = val;
ftoa(m, res1, 4);

float o = 24.528;
ftoa(o, res2, 4);

msg = res;
scia_msg(msg);
//while(SciaRegs.SCIFFRX.bit.RXFFST !=1) { } // wait for XRDY =1 for empty state

// Get character
// ReceivedChar[50] = SciaRegs.SCIRXBUF.all;

ECanaMboxes.MBOX25.MDL.all = g;
ECanaMboxes.MBOX25.MDH.all = f;


ECanaShadow.CANTRS.all = 0;
ECanaShadow.CANTRS.bit.TRS25 = 1; // Set TRS for mailbox under test
ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all;

do
{
ECanaShadow.CANTA.all = ECanaRegs.CANTA.all;
} while(ECanaShadow.CANTA.bit.TA25 == 0 ); // Wait for TA5 bit to be set..


ECanaShadow.CANTA.all = 0;
ECanaShadow.CANTA.bit.TA25 = 1; // Clear TA5
ECanaRegs.CANTA.all = ECanaShadow.CANTA.all;

// loopcount ++;

}
}
}

PS. ftoa is the float to string conversion  function which is required for serial communication.

  • Hi Gautham,

    Here's a snippet of code (from within a loop) I use in a F28035 project that reads two RTD temperatures from an IC over the SPI bus and continuously (once per second) reports these temperatures over CAN.

    // Write to the mailbox RAM field of MBOX0
    // THIS IS WHERE WE WOULD WRITE THE TEMPERATURE DATA!
    ECanaMboxes.MBOX0.MDL.all = tempBoth;
    ECanaMboxes.MBOX0.MDH.all = 0;
    
    
    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
    



    Here's the CANA initialization code that I use.

    // Setup the GPIOs CAN-A functionality
    InitECanGpio();
    
    // Initialize all the Device Peripherals:
    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 = 0x9700BEEF;
    
    // Configure Mailbox 0 as Tx
    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    ECanaRegs.CANMD.all = 0x00000000;
    
    // Enable Mailbox 0 */
    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    ECanaRegs.CANME.all = 0x00000001;
    
    // Specify that 8 bytes will be sent
    ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;
    
    // Since this write is to the entire register (instead of a bit
    // field) a shadow register is not required.
    EALLOW;
    ECanaRegs.CANMIM.all = 0x00000001;
    EDIS;
    



    Enjoy,
    Tom

  • Continuous transmit is fairly straightforward. Please take a look at the example in SPRA876 or any Controlsuite example.
  • Thank you Tom!!
    Could you please elaborate on how SPI is different from SCI.. Because I am using SCI in my work
  • Gautham,
    Please start a new post if your question is not connected to your original post. This makes future searches easier.