#include "DSP2833x_Device.h" // external function prototypes extern void InitSysCtrl(void); extern void InitPieCtrl(void); extern void InitPieVectTable(void); extern void InitCpuTimers(void); extern void InitECan(void); extern void ConfigCpuTimer(struct CPUTIMER_VARS *, float, float); extern void InitECan(void); // Prototype statements for functions found within this file. void Gpio_select(void); interrupt void cpu_timer0_isr(void); //########################################################################### // main code //########################################################################### void main(void) { struct ECAN_REGS ECanbShadow; int counter=0; int counter2=0; int counter3=0; Uint16 temp; Uint16 temp2; Uint16 temp3; Uint16 temp4; InitSysCtrl(); // Basic Core Init from DSP2833x_SysCtrl.c EALLOW; SysCtrlRegs.WDCR= 0x00AF; // Re-enable the watchdog EDIS; // 0x00AF to NOT disable the Watchdog, Prescaler = 64 DINT; // Disable all interrupts Gpio_select(); // GPIO9,GPIO11,GPIO34 and GPIO49 as output (LEDs @ peripheral explorer) /* Initialize the CAN module */ // NOTE: first modify TI-file: InitECan() to 100kbps by setting BTR = 49 InitECan(); /* Write to Mailbox 2 message ID field */ ECanbMboxes.MBOX2.MSGID.all = 0x00500000; // extended identifier ECanbMboxes.MBOX2.MSGID.bit.IDE = 0; /* Configure Mailbox 2 as Receiver mailbox */ ECanbShadow.CANMD.all = ECanbRegs.CANMD.all; ECanbShadow.CANMD.bit.MD2 = 1; ECanbRegs.CANMD.all = ECanbShadow.CANMD.all; /* Enable Mailbox 1 */ ECanbShadow.CANME.all = ECanbRegs.CANME.all; ECanbShadow.CANME.bit.ME2 = 1; ECanbRegs.CANME.all = ECanbShadow.CANME.all; InitPieCtrl(); // clear all pending PIE-Interrupts and to disable all PIE interrupt lines InitPieVectTable(); // default ISR's in PIE,This function will initialize the PIE-memory to an initial state. EALLOW; PieVectTable.TINT0 = &cpu_timer0_isr; EDIS; InitCpuTimers(); // basic setup CPU Timer0, 1 and 2,Timer0 set edildi ConfigCpuTimer(&CpuTimer0,150,10000); // CPU - Timer0 at 100 milliseconds //parametre1=adress of core,parametre2=internal speed of DSP,paramtre3=period time for timer overflow PieCtrlRegs.PIEIER1.bit.INTx7 = 1;//to enable interupt mask of cputimer IER |=1;//enable interrupt core INT1 EINT;//enable control interrupt lines 2 macros ERTM;//....... CpuTimer0Regs.TCR.bit.TSS = 0; // start timer0 while(1) { while(CpuTimer0.InterruptCount ==0) // wait for 10*100 milliseconds { EALLOW; SysCtrlRegs.WDKEY = 0x55; // service WD #2 EDIS; } CpuTimer0.InterruptCount = 0; if(ECanbRegs.CANRMP.bit.RMP2 == 1 ) // valid new data in MBX1? { counter = (ECanbMboxes.MBOX2.MDL.all); counter2=ECanbMboxes.MBOX2.MDH.all; counter3=ECanbMboxes.MBOX2.MSGID.all; temp2=(ECanbMboxes.MBOX2.MDL.byte.BYTE1 & 0xFF); temp3=(ECanbMboxes.MBOX2.MDL.byte.BYTE2 & 0xFF); temp4=(ECanbMboxes.MBOX2.MDL.byte.BYTE3 & 0xFF); // clear the status flag RMP1 ECanbRegs.CANRMP.bit.RMP2 = 1; // and prepare MBX1 for next receive GpioDataRegs.GPBTOGGLE.bit.GPIO34 = 1; // toggle red LED LD3 @ 28335CC } } } void Gpio_select(void)// Register secimi yap1yoruz I/O olarak { EALLOW; GpioCtrlRegs.GPAMUX1.all = 0; // GPIO15 ... GPIO0 = General Puropse I/O GpioCtrlRegs.GPAMUX2.all = 0; // GPIO31 ... GPIO16 = General Purpose I/O GpioCtrlRegs.GPAMUX1.bit.GPIO10 = 2; // CANB_RX GpioCtrlRegs.GPAMUX1.bit.GPIO8 = 2; // CANB_TX GpioCtrlRegs.GPBMUX1.all = 0; // GPIO47 ... GPIO32 = General Purpose I/O GpioCtrlRegs.GPBMUX2.all = 0; // GPIO63 ... GPIO48 = General Purpose I/O GpioCtrlRegs.GPCMUX1.all = 0; // GPIO79 ... GPIO64 = General Purpose I/O GpioCtrlRegs.GPCMUX2.all = 0; // GPIO87 ... GPIO80 = General Purpose I/O GpioCtrlRegs.GPADIR.all = 0; GpioCtrlRegs.GPADIR.bit.GPIO9 = 1; // peripheral explorer: LED LD1 at GPIO9 GpioCtrlRegs.GPADIR.bit.GPIO11 = 1; // peripheral explorer: LED LD2 at GPIO11 GpioCtrlRegs.GPBDIR.all = 0; // GPIO63-32 as inputs GpioCtrlRegs.GPBDIR.bit.GPIO34 = 1; // peripheral explorer: LED LD3 at GPIO34 GpioCtrlRegs.GPBDIR.bit.GPIO49 = 1; // peripheral explorer: LED LD4 at GPIO49 GpioCtrlRegs.GPCDIR.all = 0; // GPIO87-64 as inputs EDIS; } interrupt void cpu_timer0_isr(void) { CpuTimer0.InterruptCount++; EALLOW; SysCtrlRegs.WDKEY = 0xAA; // service WD #2 EDIS; PieCtrlRegs.PIEACK.all = PIEACK_GROUP1; } //=========================================================================== // End of SourceCode. //===========================================================================