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.

RM48L952 CAN能发送数据,接收数据不能进入中断.

Expert 1222 points


1.用HALCoGen驱动代码生成工具,生成步骤如下:

(1)图一:

(2)图二   传输速率是 bit rate: 100;

(3)图三   CAN2 Message1 配置:CANTX, 无中断 ,  CAN2 Message2 配置: CANRX VIM 中断.

(4)图4 中断设置

以上配置后生成代码..

“主函数 sys_main.c ”代码如下:

/* Include Files */

#include "sys_common.h"
#include "system.h"
#include "can.h"
#include "sys_core.h"
#include "esm.h"
#include "sys_vim.h"


void wait(uint32_t time);
void delay(uint32_t time);


unsigned char can_data[8] = {1, 2, 3, 4, 5, 6, 7, 8};
unsigned char can_data_ptr[8] = {0};
unsigned char ret = 0;
void main(void)
{
canInit(); /*can bus init*/
vimInit();
_enable_interrupt_(); /* enable irq interrupt in Cortex R4 */


while(1) /* continious display */
{
 if(canTransmit(canREG2, canMESSAGE_BOX1, can_data) == 1) /* sender data from can1 */  能发送数据;
 {
    ret = 1;
 }
  delay(10000000);

// if(canIsRxMessageArrived(canREG2, canMESSAGE_BOX2)) /* receiver data for can2*/
// {
/* - When a message is ready, read it into can_data */
// while(!canGetData(canREG2, canMESSAGE_BOX2, can_data_ptr));
// }

};
}

void canMessageNotification(canBASE_t *node, uint32 messageBox)      //中断函数, 接收数据时.中断函数不能进入中断...
{
/* enter user code between the USER CODE BEGIN and USER CODE END. */
if(canIsRxMessageArrived(canREG2, canMESSAGE_BOX2)) /* receiver data for can2*/
{
/* - When a message is ready, read it into can_data */
while(!canGetData(canREG2, canMESSAGE_BOX2, can_data_ptr));
}
/* USER CODE BEGIN (15) */
/* USER CODE END */
}

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

void delay(uint32_t time)
{
int i;
for(i = 0; i < time; i++)
{
wait(10000000);
}
}

调试工具采用CANUSB..