[DSP编程]

can如何获取数据存放数组

[复制链接]
875|5
手机看帖
扫描二维码
随时随地手机跟帖
彩月|  楼主 | 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<<这两句的作用。代码如下,求大神讲解,谢谢!
#include "DSP2833x_Device.h"     // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h"   // DSP2833x Examples Include File

Uint32  MessageReceivedCount;
Uint32  PassCount = 0;
Uint32  TestMbox1 = 0;
Uint32  TestMbox2 = 0;
Uint32  TestMbox3 = 0;
Uint32 buffer[80][2];

void mailboxb_read(int16);
void date_check(int32,int32);

void main(void)
{

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

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

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

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

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

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

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

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

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

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

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

   ConfigCpuTimer(&CpuTimer0, 150, 5);
   //ConfigCpuTimer(&CpuTimer1, 150, 1000000);
   //ConfigCpuTimer(&CpuTimer2, 150, 1000000);
        StartCpuTimer0();

// Enable CPU int1 which is connected to CPU-Timer 0, CPU int13
// which is connected to CPU-Timer 1, and CPU int 14, which is connected
// to CPU-Timer 2:
    IER |= M_INT1;
    //IER |= M_INT9;
   //IER |= M_INT13;
   //IER |= M_INT14;

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

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

        /* Configure eCANB Mailbox_20 as a Receive mailbox */
           ECanbMboxes.MBOX20.MSGID.all = 0x95555555; // Extended Identifier, same as the Transmitor
        /* Configure Mailbox under test as a Receive mailbox */
           ECanbShadow.CANMD.all = ECanbRegs.CANMD.all;
           ECanbShadow.CANMD.bit.MD20 = 1;
           ECanbRegs.CANMD.all = ECanbShadow.CANMD.all;
        /* Enable Mailbox under test */
           ECanbShadow.CANME.all = ECanbRegs.CANME.all;
           ECanbShadow.CANME.bit.ME20 = 1;
           ECanbRegs.CANME.all = ECanbShadow.CANME.all;
           ECanbMboxes.MBOX20.MSGCTRL.bit.DLC = 8;
        /* Write to DLC field in Master Control reg */
        //   ECanbMboxes.MBOX25.MSGCTRL.bit.DLC = 8;

           EDIS;

    while(1)
    {
                        mailboxb_read(20);                                 // read the received data
                        date_check(TestMbox1,TestMbox2);// Checks the received data
    }

}

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

   volatile struct MBOX *Mailbox;
   Mailbox = &ECanbMboxes.MBOX0 + MBXnbr;
   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
   TestMbox1 = Mailbox->MDL.all; // = 0x9555AAAn (n is the MBX number)
   TestMbox2 = Mailbox->MDH.all; // = 0x89ABCDEF (a constant)
   TestMbox3 = Mailbox->MSGID.all;// = 0x9555AAAn (n is the MBX number)
   MessageReceivedCount++;


}

void date_check(int32 T1, int32 T2)
{
        if((T1 == 48) && ( T2 == 0))
        {
                i=0;
        }

        if((T1 != 102) && ( T2 != 6))
        {
                buffer[i][0]=T1;
                buffer[i][1]=T2;
                i++;
        }
}

使用特权

评论回复

相关帖子

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

粉丝