[DSP编程] can如何获取数据存放数组

[复制链接]
 楼主| 彩月 发表于 2019-8-19 11:55 | 显示全部楼层 |阅读模式
现在遇到的问题是不明白怎么样把can获取出来的数据存到数组里。也不明白can中读数据的>>while(ECanbRegs.CANRMP.all & (1<< MBXnbr) == 0 ){}   // Wait for mailbox receive panding flag to be set..
   ECanbRegs.CANRMP.all |= 1<< MBXnbr; // Clear receive panding flag<<这两句的作用。代码如下,求大神讲解,谢谢!
  1. #include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
  2. #include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

  3. Uint32  MessageReceivedCount;
  4. Uint32  PassCount = 0;
  5. Uint32  TestMbox1 = 0;
  6. Uint32  TestMbox2 = 0;
  7. Uint32  TestMbox3 = 0;
  8. Uint32 buffer[80][2];

  9. void mailboxb_read(int16);
  10. void date_check(int32,int32);

  11. void main(void)
  12. {

  13.         //long tt;
  14.         struct ECAN_REGS  ECanbShadow;
  15. // Step 1. Initialize System Control:
  16. // PLL, WatchDog, enable Peripheral Clocks
  17. // This example function is found in the DSP2833x_SysCtrl.c file.
  18.    InitSysCtrl();

  19. // Step 2. Initalize GPIO:
  20. // This example function is found in the DSP2833x_Gpio.c file and
  21. // illustrates how to set the GPIO to it's default state.
  22. // InitGpio();  // Skipped for this example
  23.    InitXintf16Gpio();        //zq

  24.    // Just initalize eCAN pins for this example
  25.    // This function is in DSP2833x_ECan.c
  26.    InitECanGpio();

  27. // Step 3. Clear all interrupts and initialize PIE vector table:
  28. // Disable CPU interrupts
  29.    DINT;

  30. // Initialize the PIE control registers to their default state.
  31. // The default state is all PIE interrupts disabled and flags
  32. // are cleared.
  33. // This function is found in the DSP2833x_PieCtrl.c file.
  34.    InitPieCtrl();

  35. // Disable CPU interrupts and clear all CPU interrupt flags:
  36.    IER = 0x0000;
  37.    IFR = 0x0000;

  38. // Initialize the PIE vector table with pointers to the shell Interrupt
  39. // Service Routines (ISR).
  40. // This will populate the entire table, even if the interrupt
  41. // is not used in this example.  This is useful for debug purposes.
  42. // The shell ISR routines are found in DSP2833x_DefaultIsr.c.
  43. // This function is found in DSP2833x_PieVect.c.
  44.    InitPieVectTable();

  45.    // In this case just initalize eCAN-A and eCAN-B
  46.    // This function is in DSP2833x_ECan.c
  47.    InitECan();

  48. // Interrupts that are used in this example are re-mapped to
  49. // ISR functions found within this file.
  50.    EALLOW;  // This is needed to write to EALLOW protected registers
  51.    PieVectTable.TINT0 = &ISRTimer0;
  52.    //PieVectTable.ECAN0INTB = &ISRCANB;
  53.    //PieVectTable.XINT13 = &cpu_timer1_isr;
  54.    //PieVectTable.TINT2 = &cpu_timer2_isr;
  55.    EDIS;    // This is needed to disable write to EALLOW protected registers

  56. // Step 4. Initialize the Device Peripheral. This function can be
  57. //         found in DSP2833x_CpuTimers.c
  58.    InitCpuTimers();   // For this example, only initialize the Cpu Timers

  59. // Configure CPU-Timer 0, 1, and 2 to interrupt every second:
  60. // 150MHz CPU Freq, 1 second Period (in uSeconds)

  61.    ConfigCpuTimer(&CpuTimer0, 150, 5);
  62.    //ConfigCpuTimer(&CpuTimer1, 150, 1000000);
  63.    //ConfigCpuTimer(&CpuTimer2, 150, 1000000);
  64.         StartCpuTimer0();

  65. // Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
  66. // which is connected to CPU-Timer 1, and CPU int 14, which is connected
  67. // to CPU-Timer 2:
  68.     IER |= M_INT1;
  69.     //IER |= M_INT9;
  70.    //IER |= M_INT13;
  71.    //IER |= M_INT14;

  72. // Enable TINT0 in the PIE: Group 1 interrupt 7
  73.     PieCtrlRegs.PIEIER1.bit.INTx7 = 1;
  74.     //PieCtrlRegs.PIEIER9.bit.INTx5 = 1;

  75. // Enable global Interrupts and higher priority real-time debug events:
  76.     EINT;   // Enable Global interrupt INTM
  77.     ERTM;   // Enable Global realtime interrupt DBGM
  78. /* Write to the MSGID field  */
  79.            EALLOW;

  80.         /* Configure eCANB Mailbox_20 as a Receive mailbox */
  81.            ECanbMboxes.MBOX20.MSGID.all = 0x95555555; // Extended Identifier, same as the Transmitor
  82.         /* Configure Mailbox under test as a Receive mailbox */
  83.            ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
  84.            ECanbShadow.CANMD.bit.MD20 = 1;
  85.            ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;
  86.         /* Enable Mailbox under test */
  87.            ECanbShadow.CANME.all = ECanbRegs.CANME.all;
  88.            ECanbShadow.CANME.bit.ME20 = 1;
  89.            ECanbRegs.CANME.all = ECanbShadow.CANME.all;
  90.            ECanbMboxes.MBOX20.MSGCTRL.bit.DLC = 8;
  91.         /* Write to DLC field in Master Control reg */
  92.         //   ECanbMboxes.MBOX25.MSGCTRL.bit.DLC = 8;

  93.            EDIS;

  94.     while(1)
  95.     {
  96.                         mailboxb_read(20);                                 // read the received data
  97.                         date_check(TestMbox1,TestMbox2);// Checks the received data
  98.     }

  99. }

  100. // This function reads out the contents of the indicated
  101. // by the Mailbox number (MBXnbr).
  102. void mailboxb_read(int16 MBXnbr)
  103. {

  104.    volatile struct MBOX *Mailbox;
  105.    Mailbox = &ECanbMboxes.MBOX0 + MBXnbr;
  106.    while(ECanbRegs.CANRMP.all & (1<< MBXnbr) == 0 ){}   // Wait for mailbox receive panding flag to be set..
  107.    ECanbRegs.CANRMP.all |= 1<< MBXnbr; // Clear receive panding flag
  108.    TestMbox1 = Mailbox->MDL.all; // = 0x9555AAAn (n is the MBX number)
  109.    TestMbox2 = Mailbox->MDH.all; // = 0x89ABCDEF (a constant)
  110.    TestMbox3 = Mailbox->MSGID.all;// = 0x9555AAAn (n is the MBX number)
  111.    MessageReceivedCount++;


  112. }

  113. void date_check(int32 T1, int32 T2)
  114. {
  115.         if((T1 == 48) && ( T2 == 0))
  116.         {
  117.                 i=0;
  118.         }

  119.         if((T1 != 102) && ( T2 != 6))
  120.         {
  121.                 buffer[i][0]=T1;
  122.                 buffer[i][1]=T2;
  123.                 i++;
  124.         }
  125. }
airwill 发表于 2019-8-19 23:21 | 显示全部楼层
如果你是初学者, 你可以参考例程代码先把要实现的功能做出来, 不要太纠结这些细节.
如果想搞明白为何这样写, 得查编程参考手册里寄存器的说明和编程规则
蒋博1026 发表于 2019-8-23 09:51 | 显示全部楼层
这个如果能把芯片的数据手册都看明白了,应该就解决了
蒋博1026 发表于 2019-8-23 09:52 | 显示全部楼层
如何操作寄存器,如何写入,各个位都代表什么含义
蒋博1026 发表于 2019-8-23 09:53 | 显示全部楼层
ECanbRegs.CANRMP.all |= 1<< MBXnbr; // Clear receive panding flag<<这句话应该就是对寄存器进行操作吧,位操作,往里边写数
蒋博1026 发表于 2019-8-23 09:59 | 显示全部楼层
ECanbRegs.这个就应该表示的是与ecan相关的寄存器吧,单词的缩写,我是这么认为的
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

5

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部

5

主题

5

帖子

0

粉丝
快速回复 在线客服 返回列表 返回顶部