我使用的开发板是 Hercules TMS570L4x LaunchPad;芯片型号是TMS570LS0432
1 完全按照HCG的帮助文件example_canCommunication.c例程配置相应寄存器;
(1)勾选Enable CAN1 driver、勾选Enable CAN1 driver、勾选EnableDCC driver;
(2)CAN1、CAN2都选择500Kbi波特率,勾选Enable Identifier Extension;
(3)Active CAN1 Message1 configuration,选择Tx功能;
(4)Active CAN2 Message1 cnofiguration,选择Rx功能;
2 由于Hercules TMS570L4x LaunchPad的CAN通信接口没有电平转化,
现分别给CAN1 和 CAN2 的pin脚外加了VP230模块(CAN1一个、CAN2一个),
即 CAN1 Tx、CAN1Rx接VP230模块1的 Tx、Rx;
CAN2 Tx、CAN2Rx接VP230模块2的 Tx、Rx;
VP230模块1的H、L与VP230模块2的H、L相连;
3 调试程序,程序一直停留在这里,下不去;
while(!canIsRxMessageArrived(canREG2, canMESSAGE_BOX1));
uint32 canIsRxMessageArrived(canBASE_t *node, uint32 messageBox)
{
uint32 flag;
uint32 regIndex = (messageBox - 1U) >> 5U;
uint32 bitIndex = 1U << ((messageBox - 1U) & 0x1FU);
/* USER CODE BEGIN (16) */
/* USER CODE END */
/** - Read Tx request register */
flag = node->NWDATx[regIndex] & bitIndex;///////////////////////flag 总是为0
/* USER CODE BEGIN (17) */
/* USER CODE END */
return flag;
}
我想咨询的问题是:
1 配驱动时一定要配置---------》勾选EnableDCC driver;为什么?
2 我的外接的模块的电路有问题么?
代码想要实现CAN1 Message1 发送数据,CAN2 Message2 接收回数据
main.c的代码
#include "sys_common.h" /* USER CODE BEGIN (1) */ #include "system.h" #include "can.h" #include "esm.h" #define D_SIZE 9 uint8 tx_data[D_SIZE] = {'H','E','R','C','U','L','E','S','\0'}; uint8 rx_data[D_SIZE] = {0}; uint32 error = 0; uint32 checkPackets(uint8 *src_packet,uint8 *dst_packet,uint32 psize); /* 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) */ 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 */ return 0; } /* 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); }