SAM4E-EK开发板代码解读04——CAN

查看数: 24179 | 评论数: 1 | 收藏 0
开灯 | 提示:支持键盘翻页<-左 右->
    组图打开中,请稍候......
发布时间: 2020-5-13 13:48

正文摘要:

本帖最后由 Mcuzone_TKN 于 2020-5-15 09:13 编辑 关键词:Microchip Atmel  SAM4E SAM4E-EK  SAM4E16E 芯片CAN 控制器局域网络 概述:实现板载两路之间的收发 开发板有两路CAN,每个C ...

回复

Mcuzone_TKN 发表于 2020-5-13 13:56:47
  1. static void test_1(void)
  2. {
  3.         can_reset_all_mailbox(CAN0);
  4.         can_reset_all_mailbox(CAN1);

  5.         puts("\n\rTest1: CAN0 Mailbox 0 transmitting to CAN1 Mailbox 0" STRING_EOL);

  6.          //初始化CAN1邮箱0到接收邮箱
  7.         reset_mailbox_conf(&can1_mailbox);
  8.         can1_mailbox.ul_mb_idx = TEST1_CAN_COMM_MB_IDX;
  9.         can1_mailbox.uc_obj_type = CAN_MB_RX_MODE;
  10.         can1_mailbox.ul_id_msk = CAN_MAM_MIDvA_Msk | CAN_MAM_MIDvB_Msk;
  11.         can1_mailbox.ul_id = CAN_MID_MIDvA(TEST1_CAN_TRANSFER_ID);
  12.         can_mailbox_init(CAN1, &can1_mailbox);

  13.        
  14.         //初始化CAN0邮箱0来传输邮箱
  15.         reset_mailbox_conf(&can0_mailbox);
  16.         can0_mailbox.ul_mb_idx = TEST1_CAN_COMM_MB_IDX;
  17.         can0_mailbox.uc_obj_type = CAN_MB_TX_MODE;
  18.         can0_mailbox.uc_tx_prio = TEST1_CAN0_TX_PRIO;
  19.         can0_mailbox.uc_id_ver = 0;
  20.         can0_mailbox.ul_id_msk = 0;
  21.         can_mailbox_init(CAN0, &can0_mailbox);

  22.        
  23.         //写发送信息到邮箱
  24.         can0_mailbox.ul_id = CAN_MID_MIDvA(TEST1_CAN_TRANSFER_ID);
  25.         can0_mailbox.ul_datal = CAN_MSG_TOGGLE_LED_0;
  26.         can0_mailbox.ul_datah = CAN_MSG_DUMMY_DATA;
  27.         can0_mailbox.uc_length = MAX_CAN_FRAME_DATA_LEN;
  28.         can_mailbox_write(CAN0, &can0_mailbox);

  29.        
  30.         //使能CAN1邮箱0中断
  31.         can_enable_interrupt(CAN1, CAN_IER_MB0);

  32.        
  33.         //把邮箱里的信息发出去
  34.         can_global_send_transfer_cmd(CAN0, CAN_TCR_MB0);

  35.         while (!g_ul_recv_status) {
  36.         }

  37.         if ((can1_mailbox.ul_datal == CAN_MSG_TOGGLE_LED_0) &&
  38.                 (can1_mailbox.uc_length == MAX_CAN_FRAME_DATA_LEN)) {
  39.                 puts("Test1 passed" STRING_EOL);
  40.                 decode_can_msg(&can1_mailbox);
  41.         } else {
  42.                 puts("Test1 ERROR" STRING_EOL);
  43.         }
  44. }
复制代码
快速回复 返回顶部 返回列表