ARM技术论坛
直播中

祖力卡尔

7年用户 6经验值
擅长:CRF/无线 接口/总线/驱动
私信 关注
[问答]

TMS570LS04x在can1和can2通信测试例程中的一些问题

本人想测试一下板上can1和can2通信,于是用了手册里的can通信例程,代码如下,但是我用usbcan只能收到can1发的消息,并没有接受到can2收到的消息,于是我做了一些调整如下:

通过中断调试,can1发了一次,can2收了一次,但是测试例程是can1发8个消息的,并且在调试过程中,我发现程序,一直卡在这个地方(跳不出循环):
while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));


刚入坑,希望各位能解答一下我的疑惑,谢谢。
最后我提下我想实现的效果,希望大家能提供一些意见,我想要can1发can2收,并且can2收到的信息通过串口打印出来。

回帖(1)

祖力卡尔

2021-10-15 19:48:21
源码:

#include "sys_common.h"
#include "system.h"

/* USER CODE BEGIN (1) */
#include "can.h"
#include "esm.h"
#include "sys_core.h"

#define D_COUNT  8

uint32 cnt=0, error =0, tx_done =0;
uint8 tx_data[D_COUNT][8] = {0};
uint8 rx_data[D_COUNT][8] = {0};
uint8 *tx_ptr = &tx_data[0][0];
uint8 *rx_ptr = &rx_data[0][0];
uint8 *dptr=0;

void dumpSomeData();
/* USER CODE END */


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


void main(void)
{
/* USER CODE BEGIN (3) */

    /* enable irq interrupt in Cortex R4 */
    _enable_interrupt_();

    dumpSomeData();

    canInit();

    canEnableErrorNotification(canREG1);
    canEnableErrorNotification(canREG2);

    for(cnt=0;cnt     {
      canTransmit(canREG1, canMESSAGE_BOX1, tx_ptr); /* transmitting 8 different chunks 1 by 1 */
      //canMessageNotification(canREG1,canMESSAGE_BOX1);
      //canMessageNotification(canREG2,canMESSAGE_BOX1);//原例程只是定义了这个函数,但是没有调用,这里是我自己写上去的
      while(tx_done == 0){};                 /* ... wait until transmit request is through        */
      tx_done=0;
      tx_ptr +=8;    /* next chunk ...*/
    }

    tx_ptr = &tx_data[0][0];
    rx_ptr = &rx_data[0][0];

    for(cnt=0;cnt<63;cnt++)
     {
          if(*tx_ptr++ != *rx_ptr++)
          {
               error++; /* data error */
          }
     }

    while(1){}; /* wait forever after tx-rx complete. */

/* USER CODE END */
}

/* USER CODE BEGIN (4) */
/* writing some data to ram  */
void dumpSomeData()//dump(内存信息)转储
{
     uint32 tmp = 0x11;

     cnt = (D_COUNT*8)-1;
     dptr = &tx_data[0][0];
     *dptr = tmp;

     while(cnt--)
     {
        tmp = *dptr++;
        *dptr = tmp + 0x11;
     }
}


/* can interrupt notification  */
/* Note-You need to remove canMessageNotification from notification.c to avoid redefinition */

void canMessageNotification(canBASE_t *node, uint32 messageBox)
{
     /* node 1 - transfer request */
     if(node==canREG1)
     {
       tx_done=1; /* confirm transfer request */
     }

     /* node 2 - receive complete */
     if(node==canREG2)
     {
      while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));
      canGetData(canREG2, canMESSAGE_BOX1, rx_ptr); /* copy to RAM */
      rx_ptr +=8;
     }

    /* Note: since only message box 1 is used on both nodes we dont check it here.*/
}
/* USER CODE END */
举报

更多回帖

发帖
×
20
完善资料,
赚取积分