📄 spi_test.c
字号:
#include "DSP28_Device.h"
//Relative to spi_receive,not use rightnow
//for ecan
//#define LED1_ON GpioDataRegs.GPFDAT.bit.GPIOF14=1
//#define LED1_OFF GpioDataRegs.GPFDAT.bit.GPIOF14=0
void mailbox_check(int32 T1,int32 T2,int32 T3);
void mailbox_read(int16 i);
void Gpio_select(void);
//for spi
unsigned int Spi_VarRx[100];
unsigned int i,j;
//-------------------------
//for ecan
unsigned int Led_Flag;
Uint32 ErrorCount;
Uint32 MessageReceiveCount;
Uint32 TestMbox1;
Uint32 TestMbox2;
Uint32 TestMbox3;
extern unsigned int Int_Flag;
void main(void)
{
unsigned int shownum;
//countnum = 0;
/*初始化系统*/
InitSysCtrl();
/* 关中断 */
DINT;
IER = 0x0000;
IFR = 0x0000;
/* 初始化PIE控制寄存器 */
InitPieCtrl();
/* 初始化PIE参数表 */
InitPieVectTable();
/* 初始化外设寄存器 */
InitPeripherals();
//for ecan
Gpio_select();/////////
/*初始化SCIA寄存器*/
InitECan();
#if Spi_Int
EALLOW; // This is needed to write to EALLOW protected registers
PieVectTable.SPITXINTA = &SPITXINTA_ISR;
PieVectTable.SPIRXINTA = &SPIRXINTA_ISR;
EDIS; // This is needed to disable write to EALLOW protected registers
/* 设置IER寄存器 */
IER |= M_INT6;
#endif
/* 开中断 */
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
Intensity(11);
ScanLimit(7);
DisplayTest();
ShutDown(NO);
DecodeMode(0x0ff);
while(1)
{
mailbox_read(5);
MessageReceiveCount++;
if((Spi_TxReady() == 1))
{
shownum=BIN2BCD(TestMbox1);
ShowBCD(shownum);
}
}
}
void Gpio_select(void)
{
EALLOW;
GpioMuxRegs.GPFMUX.bit.CANTXA_GPIOF6=1;
GpioMuxRegs.GPFMUX.bit.CANRXA_GPIOF7=1;
GpioMuxRegs.GPFMUX.bit.XF_GPIOF14=0;
GpioMuxRegs.GPFDIR.bit.GPIOF14=1;
EDIS;
}
/*读取邮箱中的内容*/
void mailbox_read(int16 MBXnbr)
{
volatile struct MBOX *Mailbox;
Mailbox = &ECanaMboxes.MBOX0 + MBXnbr;
TestMbox1 = Mailbox->MDRL.all; // = 0x9555AAAn (n is the MBX number)
TestMbox2 = Mailbox->MDRH.all; // = 0x89ABCDEF (a constant)
TestMbox3 = Mailbox->MID.all;// = 0x9555AAAn (n is the MBX number)
} // MSGID of a rcv MBX is transmitted as the MDL data.
void mailbox_check(int32 T1, int32 T2, int32 T3)
{
int i;
if((T1 != T3) || ( T2 != 0x89ABCDEF))
{
ErrorCount++;
/* LED1_ON;
for(i = 0; i < 0x5555; i++);
LED1_OFF;
for(i = 0; i < 0x5555; i++);*/
}else
{
// LED1_ON;
for(i = 0; i < 0x8000; i++);
//LED1_OFF;
for(i = 0; i < 0x8000; i++);
}
}
//===========================================================================
// No more.
//===========================================================================
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -