TMS570LS1224中CAN通信问题

2019-07-15 07:17发布

1.我设置了CAN1和CAN2之间进行通信,CAN1中接了收发器CAN_H和CAN_L,为什么用示波器测不出我所发送的数据呢?
以下是我按例子做的代码:
#include "sys_common.h"
#include "system.h"
/* USER CODE BEGIN (1) */
#include "can.h"
/* Include ESM header file - types, definitions and function declarations for system driver */
#include "esm.h"
#define  D_SIZE 9
uint8  tx_data[D_SIZE]  = {'H','E','R','C','U','L','E','S',''};
uint8  rx_data[D_SIZE] = {0};
uint32 error = 0;
uint32 checkPackets(uint8 *src_packet,uint8 *dst_packet,uint32 psize);
/* USER CODE END */
/* USER CODE BEGIN (2) */
/* 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[0],&rx_data[0],D_SIZE);
/* ... run forever */
    while(1);
/* USER CODE END */
}
/* USER CODE BEGIN (4) */
uint32 checkPackets(uint8 *src_packet,uint8 *dst_packet,uint32 psize)
{
   uint32 err=0;
   uint32 cnt=psize;
while(cnt--)
   {
     if((*src_packet++) != (*dst_packet++))
     {
        err++;           /*  data error  */
     }
   }
   return (err);
}
2.附件是我的HAL设置


0条回答

一周热门 更多>