DSP 28335 ECAN模块

2019-07-15 19:51发布

谁有发送接收程序呀!  谢谢。。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
1条回答
244531776
1楼-- · 2019-07-15 21:34
  1. // TI File $Revision: /main/2 $
  2. // Checkin $Date: July 30, 2009   18:44:23 $
  3. //###########################################################################
  4. //
  5. // FILE:    Example_2833xECanBack2Back.c
  6. //
  7. // TITLE:   DSP2833x eCAN Back-to-back transmission and reception in
  8. //          SELF-TEST mode
  9. //
  10. // ASSUMPTIONS:
  11. //
  12. //    This program requires the DSP2833x header files.
  13. //
  14. //    This progrm uses the peripheral's self test mode.
  15. //    Other then boot mode configuration, no other hardware configuration
  16. //    is required.
  17. //
  18. //    As supplied, this project is configured for "boot to SARAM"
  19. //    operation.  The 2833x Boot Mode table is shown below.
  20. //    For information on configuring the boot mode of an eZdsp,
  21. //    please refer to the documentation included with the eZdsp,
  22. //
  23. //       $Boot_Table:
  24. //
  25. //         GPIO87   GPIO86     GPIO85   GPIO84
  26. //          XA15     XA14       XA13     XA12
  27. //           PU       PU         PU       PU
  28. //        ==========================================
  29. //            1        1          1        1    Jump to Flash
  30. //            1        1          1        0    SCI-A boot
  31. //            1        1          0        1    SPI-A boot
  32. //            1        1          0        0    I2C-A boot
  33. //            1        0          1        1    eCAN-A boot
  34. //            1        0          1        0    McBSP-A boot
  35. //            1        0          0        1    Jump to XINTF x16
  36. //            1        0          0        0    Jump to XINTF x32
  37. //            0        1          1        1    Jump to OTP
  38. //            0        1          1        0    Parallel GPIO I/O boot
  39. //            0        1          0        1    Parallel XINTF boot
  40. //            0        1          0        0    Jump to SARAM            <- "boot to SARAM"
  41. //            0        0          1        1    Branch to check boot mode
  42. //            0        0          1        0    Boot to flash, bypass ADC cal
  43. //            0        0          0        1    Boot to SARAM, bypass ADC cal
  44. //            0        0          0        0    Boot to SCI-A, bypass ADC cal
  45. //                                              Boot_Table_End$
  46. //
  47. // DESCRIPTION:
  48. //
  49. //    This test transmits data back-to-back at high speed without
  50. //    stopping.
  51. //    The received data is verified. Any error is flagged.
  52. //    MBX0 transmits to MBX16, MBX1 transmits to MBX17 and so on....
  53. //    This program illustrates the use of self-test mode
  54. //
  55. //###########################################################################
  56. // Original Author H.J.
  57. //
  58. // $TI Release: 2833x/2823x Header Files V1.32 $
  59. // $Release Date: June 28, 2010 $
  60. //###########################################################################

  61. #include "DSP28x_Project.h"     // Device Headerfile and Examples Include File
  62. #include "H: icontrolsuitecontrolSUITEdevice_supportf2833xv132DSP2833x_headersincludeDSP2833x_ECan.h"
  63. // Prototype statements for functions found within this file.
  64. void mailbox_check(int32 T1, int32 T2, int32 T3);
  65. void mailbox_read(int16 i);

  66. // Global variable for this example
  67. Uint32  ErrorCount;
  68. Uint32  PassCount;
  69. Uint32  MessageReceivedCount;

  70. Uint32  TestMbox1 = 0;
  71. Uint32  TestMbox2 = 0;
  72. Uint32  TestMbox3 = 0;

  73. void main(void)
  74. {

  75.     Uint16  j;

  76. // eCAN control registers require read/write access using 32-bits.  Thus we
  77. // will create a set of shadow registers for this example.  These shadow
  78. // registers will be used to make sure the access is 32-bits and not 16.
  79.    struct ECAN_REGS ECanaShadow;

  80. // Step 1. Initialize System Control:
  81. // PLL, WatchDog, enable Peripheral Clocks
  82. // This example function is found in the DSP2833x_SysCtrl.c file.
  83.    InitSysCtrl();//系统初始化

  84. // Step 2. Initalize GPIO:
  85. // This example function is found in the DSP2833x_Gpio.c file and
  86. // illustrates how to set the GPIO to it's default state.
  87. // InitGpio();  // Skipped for this example

  88. // For this example, configure CAN pins using GPIO regs here
  89. // This function is found in DSP2833x_ECan.c
  90.    InitECanGpio();//这里IO口一定要选择该开发板引出的IO口,不同的可能引出的IO口不同

  91. // Step 3. Clear all interrupts and initialize PIE vector table:
  92. // Disable CPU interrupts
  93.    DINT;

  94. // Initialize PIE control registers to their default state.
  95. // The default state is all PIE interrupts disabled and flags
  96. // are cleared.
  97. // This function is found in the DSP2833x_PieCtrl.c file.
  98.    InitPieCtrl();

  99. // Disable CPU interrupts and clear all CPU interrupt flags:
  100.    IER = 0x0000;
  101.    IFR = 0x0000;

  102. // Initialize the PIE vector table with pointers to the shell Interrupt
  103. // Service Routines (ISR).
  104. // This will populate the entire table, even if the interrupt
  105. // is not used in this example.  This is useful for debug purposes.
  106. // The shell ISR routines are found in DSP2833x_DefaultIsr.c.
  107. // This function is found in DSP2833x_PieVect.c.
  108.    InitPieVectTable();//配置中断相量

  109. // Step 4. Initialize all the Device Peripherals:
  110. // This function is found in DSP2833x_InitPeripherals.c
  111. // InitPeripherals(); // Not required for this example

  112. // Step 5. User specific code, enable interrupts:

  113.     MessageReceivedCount = 0;
  114.     ErrorCount = 0;
  115.     PassCount = 0;

  116.         InitECana(); // Initialize eCAN-A module

  117.     // Mailboxs can be written to 16-bits or 32-bits at a time
  118.     // Write to the MSGID field of TRANSMIT mailboxes MBOX0 - 15
  119.     ECanaMboxes.MBOX0.MSGID.all = 0x9555AAA0;//设置邮箱ID
  120.     ECanaMboxes.MBOX1.MSGID.all = 0x9555AAA1;
  121.     ECanaMboxes.MBOX2.MSGID.all = 0x9555AAA2;
  122.     ECanaMboxes.MBOX3.MSGID.all = 0x9555AAA3;
  123.     ECanaMboxes.MBOX4.MSGID.all = 0x9555AAA4;
  124.     ECanaMboxes.MBOX5.MSGID.all = 0x9555AAA5;
  125.     ECanaMboxes.MBOX6.MSGID.all = 0x9555AAA6;
  126.     ECanaMboxes.MBOX7.MSGID.all = 0x9555AAA7;
  127.     ECanaMboxes.MBOX8.MSGID.all = 0x9555AAA8;
  128.     ECanaMboxes.MBOX9.MSGID.all = 0x9555AAA9;
  129.     ECanaMboxes.MBOX10.MSGID.all = 0x9555AAAA;
  130.     ECanaMboxes.MBOX11.MSGID.all = 0x9555AAAB;
  131.     ECanaMboxes.MBOX12.MSGID.all = 0x9555AAAC;
  132.     ECanaMboxes.MBOX13.MSGID.all = 0x9555AAAD;
  133.     ECanaMboxes.MBOX14.MSGID.all = 0x9555AAAE;
  134.     ECanaMboxes.MBOX15.MSGID.all = 0x9555AAAF;

  135.     // Write to the MSGID field of RECEIVE mailboxes MBOX16 - 31
  136.     ECanaMboxes.MBOX16.MSGID.all = 0x9555AAA0;//设置邮箱ID
  137.     ECanaMboxes.MBOX17.MSGID.all = 0x9555AAA1;
  138.     ECanaMboxes.MBOX18.MSGID.all = 0x9555AAA2;
  139.     ECanaMboxes.MBOX19.MSGID.all = 0x9555AAA3;
  140.     ECanaMboxes.MBOX20.MSGID.all = 0x9555AAA4;
  141.     ECanaMboxes.MBOX21.MSGID.all = 0x9555AAA5;
  142.     ECanaMboxes.MBOX22.MSGID.all = 0x9555AAA6;
  143.     ECanaMboxes.MBOX23.MSGID.all = 0x9555AAA7;
  144.     ECanaMboxes.MBOX24.MSGID.all = 0x9555AAA8;
  145.     ECanaMboxes.MBOX25.MSGID.all = 0x9555AAA9;
  146.     ECanaMboxes.MBOX26.MSGID.all = 0x9555AAAA;
  147.     ECanaMboxes.MBOX27.MSGID.all = 0x9555AAAB;
  148.     ECanaMboxes.MBOX28.MSGID.all = 0x9555AAAC;
  149.     ECanaMboxes.MBOX29.MSGID.all = 0x9555AAAD;
  150.     ECanaMboxes.MBOX30.MSGID.all = 0x9555AAAE;
  151.     ECanaMboxes.MBOX31.MSGID.all = 0x9555AAAF;

  152.     // Configure Mailboxes 0-15 as Tx, 16-31 as Rx
  153.     // Since this write is to the entire register (instead of a bit
  154.     // field) a shadow register is not required.
  155.     ECanaRegs.CANMD.all = 0xFFFF0000;//设置0-15为发送邮箱,16-31为接收邮箱

  156.     // Enable all Mailboxes */
  157.     // Since this write is to the entire register (instead of a bit
  158.     // field) a shadow register is not required.
  159.     ECanaRegs.CANME.all = 0xFFFFFFFF;//使能所有邮箱

  160.     // Specify that 8 bits will be sent/received
  161.     ECanaMboxes.MBOX0.MSGCTRL.bit.DLC = 8;//设置收发位数
  162.     ECanaMboxes.MBOX1.MSGCTRL.bit.DLC = 8;
  163.     ECanaMboxes.MBOX2.MSGCTRL.bit.DLC = 8;
  164.     ECanaMboxes.MBOX3.MSGCTRL.bit.DLC = 8;
  165.     ECanaMboxes.MBOX4.MSGCTRL.bit.DLC = 8;
  166.     ECanaMboxes.MBOX5.MSGCTRL.bit.DLC = 8;
  167.     ECanaMboxes.MBOX6.MSGCTRL.bit.DLC = 8;
  168.     ECanaMboxes.MBOX7.MSGCTRL.bit.DLC = 8;
  169.     ECanaMboxes.MBOX8.MSGCTRL.bit.DLC = 8;
  170.     ECanaMboxes.MBOX9.MSGCTRL.bit.DLC = 8;
  171.     ECanaMboxes.MBOX10.MSGCTRL.bit.DLC = 8;
  172.     ECanaMboxes.MBOX11.MSGCTRL.bit.DLC = 8;
  173.     ECanaMboxes.MBOX12.MSGCTRL.bit.DLC = 8;
  174.     ECanaMboxes.MBOX13.MSGCTRL.bit.DLC = 8;
  175.     ECanaMboxes.MBOX14.MSGCTRL.bit.DLC = 8;
  176.     ECanaMboxes.MBOX15.MSGCTRL.bit.DLC = 8;


  177.     // Write to the mailbox RAM field of MBOX0 - 15
  178.     ECanaMboxes.MBOX0.MDL.all = 0x9555AAA0;//写入邮箱RAM低8位
  179.     ECanaMboxes.MBOX0.MDH.all = 0x89ABCDEF;//写入邮箱RAM高8位

  180.     ECanaMboxes.MBOX1.MDL.all = 0x9555AAA1;
  181.     ECanaMboxes.MBOX1.MDH.all = 0x89ABCDEF;

  182.     ECanaMboxes.MBOX2.MDL.all = 0x9555AAA2;
  183.     ECanaMboxes.MBOX2.MDH.all = 0x89ABCDEF;

  184.     ECanaMboxes.MBOX3.MDL.all = 0x9555AAA3;
  185.     ECanaMboxes.MBOX3.MDH.all = 0x89ABCDEF;

  186.     ECanaMboxes.MBOX4.MDL.all = 0x9555AAA4;
  187.     ECanaMboxes.MBOX4.MDH.all = 0x89ABCDEF;

  188.     ECanaMboxes.MBOX5.MDL.all = 0x9555AAA5;
  189.     ECanaMboxes.MBOX5.MDH.all = 0x89ABCDEF;

  190.     ECanaMboxes.MBOX6.MDL.all = 0x9555AAA6;
  191.     ECanaMboxes.MBOX6.MDH.all = 0x89ABCDEF;

  192.     ECanaMboxes.MBOX7.MDL.all = 0x9555AAA7;
  193.     ECanaMboxes.MBOX7.MDH.all = 0x89ABCDEF;

  194.     ECanaMboxes.MBOX8.MDL.all = 0x9555AAA8;
  195.     ECanaMboxes.MBOX8.MDH.all = 0x89ABCDEF;

  196.     ECanaMboxes.MBOX9.MDL.all = 0x9555AAA9;
  197.     ECanaMboxes.MBOX9.MDH.all = 0x89ABCDEF;

  198.     ECanaMboxes.MBOX10.MDL.all = 0x9555AAAA;
  199.     ECanaMboxes.MBOX10.MDH.all = 0x89ABCDEF;

  200.     ECanaMboxes.MBOX11.MDL.all = 0x9555AAAB;
  201.     ECanaMboxes.MBOX11.MDH.all = 0x89ABCDEF;

  202.     ECanaMboxes.MBOX12.MDL.all = 0x9555AAAC;
  203.     ECanaMboxes.MBOX12.MDH.all = 0x89ABCDEF;

  204.     ECanaMboxes.MBOX13.MDL.all = 0x9555AAAD;
  205.     ECanaMboxes.MBOX13.MDH.all = 0x89ABCDEF;

  206.     ECanaMboxes.MBOX14.MDL.all = 0x9555AAAE;
  207.     ECanaMboxes.MBOX14.MDH.all = 0x89ABCDEF;

  208.     ECanaMboxes.MBOX15.MDL.all = 0x9555AAAF;
  209.     ECanaMboxes.MBOX15.MDH.all = 0x89ABCDEF;

  210.     // Since this write is to the entire register (instead of a bit
  211.     // field) a shadow register is not required.
  212.     EALLOW;
  213.     ECanaRegs.CANMIM.all = 0xFFFFFFFF;

  214.     // Configure the eCAN for self test mode
  215.     // Enable the enhanced features of the eCAN.
  216.     EALLOW;
  217.     ECanaShadow.CANMC.all = ECanaRegs.CANMC.all;
  218.     ECanaShadow.CANMC.bit.STM = 0;    // Configure CAN for self-test modeNO//关闭loop环回
  219.     ECanaRegs.CANMC.all = ECanaShadow.CANMC.all;
  220.     EDIS;

  221.     // Begin transmitting
  222.     for(;;)
  223.     {

  224.       // ECanaRegs.CANTRS.all = 0x0000FFFF;  // Set TRS for all transmit mailboxes
  225.        //while(ECanaRegs.CANTA.all != 0x0000FFFF ) {}  // Wait for all TAits to be set..
  226.        //ECanaRegs.CANTA.all = 0x0000FFFF;   // Clear all TAn
  227.        //MessageReceivedCount++;
  228.             if(ECanaRegs.CANRMP.bit.RMP16==1)//如果16邮箱收到信息
  229.             {
  230.                     ECanaRegs.CANRMP.bit.RMP16=1;//先将该标志位清零
  231.                ECanaRegs.CANTRS.bit.TRS0 = 1;  // Set TRS for all transmit mailboxes//发送数据
  232.                while(ECanaRegs.CANTA.bit.TA0 != 1 ) {}  // Wait for all TAn bits to be set..
  233.                ECanaRegs.CANTA.bit.TA0 = 1;
  234.             }

  235.     }
  236. }

  237. // This function reads out the contents of the indicated
  238. // by the Mailbox number (MBXnbr).
  239. void mailbox_read(int16 MBXnbr)
  240. {
  241.    volatile struct MBOX *Mailbox;
  242.    Mailbox = &ECanaMboxes.MBOX0 + MBXnbr;
  243.    TestMbox1 = Mailbox->MDL.all; // = 0x9555AAAn (n is the MBX number)
  244.    TestMbox2 = Mailbox->MDH.all; // = 0x89ABCDEF (a constant)
  245.    TestMbox3 = Mailbox->MSGID.all;// = 0x9555AAAn (n is the MBX number)

  246. } // MSGID of a rcv MBX is transmitted as the MDL data.


  247. void mailbox_check(int32 T1, int32 T2, int32 T3)
  248. {
  249.     if((T1 != T3) || ( T2 != 0x89ABCDEF))
  250.     {
  251.        ErrorCount++;
  252.     }
  253.     else
  254.     {
  255.        PassCount++;
  256.     }
  257. }


  258. //===========================================================================
  259. // No more.
  260. //===========================================================================
复制代码

一周热门 更多>