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.

HalCoGen的CAN example问题

Other Parts Discussed in Thread: HALCOGEN

使用TMS570Ls12x LaunchPad,根据HalCoGen(V04.06.00)->Help->Help Topics->Examples->example_canCommunication生成代码:

#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
*
*/

/* 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) */
/** @fn checkPackets(uint8 *src_packet,uint8 *dst_packet,uint32 psize)
* @brief check two buffers and report error
*
*/
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);
}

canTransmit()返回状态是1成功,为什么在CAN1 Tx、Rx引脚上用示波器测量没有一直是高电平?