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: recieving 2 bytes of data through spi and transmit 1 byte of data through CAN

Part Number: TMS570LS3137
Other Parts Discussed in Thread: HALCOGEN

 i am a beginner , having some doubt.. my task is to recieve 100 bytes of data through spi and transmit the same through can.

by studying the TRM of TMS570LS3137, i understood at max 2 bytes of data can be recieved through spi function mibspiGetData(). and through can 1 byte of data can be transferred through canTransmit() function.

My questions are:

1. I studied CAN can transmit 0-8 bytes of data, but canTransmit() function is limiting it to 1 byte , why so ?

2. also i am facing problem in accessing 1 byte data (for can transmit ) from 2byte data stored in buffer after spi . Please help me with this

my code:


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

/* Include Files */

#include "sys_common.h"
#include "mibspi.h"
#include "can.h"

/* USER CODE BEGIN (1) */
int data;
int *pdata;
uint16 rxbuffer[];
uint8 RB[];
uint8 buff;


/* 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) */
/* USER CODE END */

int main(void)
{
/* USER CODE BEGIN (3) */
mibspiInit();
canInit();

int i,j;

for(i=0;i<10;i++)
{
for(j=0;j<5;j++)
{
rxbuffer[]= *(pdata);
pdata++;

mibspiGetData(mibspiREG1,0,rxbuffer);

}

/*stuck over here...*/

/* USER CODE END */
return 0 ;
}

  • 6648.MIBSPI_SLAVE_TMS570LS1224PGE.ZIPHello,

    This is how canTransmit function is declared:

    uint32 canTransmit(canBASE_t *node, uint32 messageBox, const uint8 * data)

    where data is pointer to a buffer.

    for example:

    uint8 tx_data[8] = {'H','E','R','C','U','L', 'E', 'S','\0'};  // buffer of 8 bytes

    canTransmit(canREG1, canMESSAGE_BOX1, tx_data); /* transmitting 8 bytes - H E R C U L E S*/

    Under HALCoGen folder you can find examples how to use CAN.

    About SPI:

    In MiBSPI mode you can set transfer groups for receiving/sending data.

    In HALCoGen you can set buffer size to transfer (up to 128 bytes) and char length (2..16 bits).

    Attached is project that receives data using TG (both HALCoGen and CCS).

    Best regards,

    Miroi

  • i have written this code as per requirement in question

    void main(void)
    {

    uint16 rxp1[50];
    int i,j;
    uint16 *p;
    uint16 val;


    for(i=0;i<10;i++)
    {
    p=rxp1;
    for(j=0;j<5;j++)
    {
    val=*p;
    mibspiGetData(mibspiREG1, 0,val);

    uint8 val_l=(val&0x00FF);
    canTransmit(canREG1, canMESSAGE_BOX1,val_l);

    val= val<<8;

    uint8 val_h=(val&0x00FF);
    canTransmit(canREG1, canMESSAGE_BOX1,val_h);
    p++;
    }
    p=(p+5);
    }

    }
    /* USER CODE END */

    but i am encountering these warnings in ccs
    could you please find out which part creating this error.

    cantransmit : argument of type "uint8" is incompatible with parameter of type "const uint8 *"
    mibspigetdata :D argument of type "uint16" is incompatible with parameter of type "uint16 *"
  • Hello,
    Please see how functions are declared.
    uint32 canTransmit(canBASE_t *node, uint32 messageBox, const uint8 * data) - data is pointer but val_l and val_h is uint8.
    and
    uint32 mibspiGetData(mibspiBASE_t *mibspi, uint32 group, uint16 * data) - data is pointer uint16 but val is uint16.

    SPI charlength could be set from 2 to 16 bits.
    Maximuim CAN payload is 8 bytes. This means that you can send maximum 8 bytes simultaneously. You don't need to send data two times.

    Best regards,
    Miro