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的CAN通信

Other Parts Discussed in Thread: HALCOGEN, TMS570LS3137

我想通过CAN来控制板子上的LED的闪烁。在HALCoGen中的“Driver Enable ”中我勾选了“Enable GIO Driver,Enable CAN1 driver,Enable CAN2 driver , Enable DCC driver”四个。我写的程序如下,但是LED没有反映,想问下是什么问题??

/* USER CODE BEGIN (0) */

 #include "can.h"

#include"het.h"

 #include "esm.h"

 /* USER CODE END */

/* Include Files */

#include "sys_common.h"

 #include "system.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) */

 #define  D_SIZE 10

uint8_t  tx_data[D_SIZE]  = {1,0,1,0,1,0,1,0,1,0};

 uint8_t  rx_data[D_SIZE] = {0};

 uint32_t error = 0;

 uint32_t checkPackets(uint8_t *src_packet,uint8_t *dst_packet,uint32_t psize);

 void wait(uint32_t time);

uint8_t i;

 /* USER CODE END */

void main(void)

 { /* USER CODE BEGIN (3) */

 /* initialize can 1 and 2   */    

   canInit(); /* can1 -> can2 */

      /* transmit on can1 */     

  canTransmit(canREG1, canMESSAGE_BOX1, tx_data);

      /*... wait until message receive on can2 */      

 while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));      

 canGetData(canREG2, canMESSAGE_BOX1, rx_data);  /* receive on can2  */

      /* check received data patterns */     

  error = checkPackets(&tx_data[D_SIZE],&rx_data[D_SIZE],D_SIZE);

      i=D_SIZE;

     gioSetDirection(hetPORT1, 0xffffffff);

            for(i=0;i<10;i++)

       {               gioSetBit(hetPORT1, 0,(uint32_t)rx_data[i]);

              wait(5000);

       }     

  /* ... run forever */    

   while(1);

/* USER CODE END */

 }

/* USER CODE BEGIN (4) */

uint32_t checkPackets(uint8_t *src_packet,uint8_t *dst_packet,uint32_t psize)

 {    uint32_t err=0;    uint32_t cnt=psize;

   while(cnt--)  

     {      if((*src_packet++) != (*dst_packet++))    

            {         err++;           /*  data error  */  

            }

       }  

  return (err);

}

 /* USER CODE END */

 void wait(uint32_t time)

 {     time--;

 }

  • weibin,

       你是想通过同一块板子上面的两个CAN接口来收发数据,通过判断收到的数据是否和接收的一样,在翻转GPIO状态是吧。

    你CAN1和CAN2的messagebox设置是什么样的呢,两者的ID是一样的吗?发送和接收需要匹配。

    可以的话,截个配置的图片,我帮你看看。

    谢谢

  • weibin,

       你是想通过同一块板子上面的两个CAN接口来收发数据,通过判断收到的数据是否和接收的一样,在翻转GPIO状态是吧。

    你CAN1和CAN2的messagebox设置是什么样的呢,两者的ID是一样的吗?发送和接收需要匹配。

    可以的话,截个配置的图片,我帮你看看。

    谢谢

  • 呵呵,谢谢。俩个ID都一样的。不过,我调好了。是我那延迟的时间太短了,所以没有现象。

  • weibin,

      Ok, 调试过了就好了。后续如果有问题,再交流吧。

    谢谢

  • Ken,你好!

    想再问下如何在CCS5中测出指令的执行时间?

    如下延时函数,若time=10000000,要测其花费的时间是多少?是不是还可以通过计算,直接算出??

    void wait(uint32_t time)
    {
    while( time--);
    }

  • weibin,

      简单点算的话,t= time/Fsystem; 你先看下你的系统主频跑的是多少Mhz。TMS570LS3137的话,默认PGE封装的是160MHZ,BGA封装是180Mhz.

    这样可以算出个大概的值。

       另外在CCS里面应该有相应的测试指令运行时间的控件。你可以google一下。

    谢谢