// // Lab CAN_2 : TMS320F2812 // (C) Frank Bormann // //########################################################################### // // FILE: Lab_CAN_2.c // // TITLE: DSP28 CAN - Receive with the Zwickau-adapterboard // // Extended CAN-Frame is received with 1 MBPS // from highspeed-CAN // Jumper JP4 : 2-3 ( 120 Ohm enabled) // Jumper JP5 : 1-2 ; Jumper JP6 _ 1-2 ( highspeed transceiver SN // // Aim of the test : // Receive a 1 byte dataframe with Identifier 0x10000000 // and show the databyte on the LED's at GPIO-Port B7...B0 // Mailbox 1 is used as receiver // Identifier : 0x1000 0000 // DLC = 1 // // Frequency Osscillator : 30MHz // PLLCR = 0xA : multiply by 5 // SYSCLKOUT = CLKIN = 150MHz // Highspeed - Prescaler (HISPCP = 0x0001; div by 2 ) : 75 Mhz // Lowspeed - Prescaler (LOSPCP = 0x0002; div by 4 ) : 37.5 Mhz //########################################################################### // // Ver | dd mmm yyyy | Who | Description of changes // =====|=============|======|=============================================== // 1.0 | 09 May 2003 | F.B. | Startup Version for Lab_CAN_2 // 2.0 | 27 Nov 2003 | F.B. | adapted to header-files Version 1.00 //########################################################################### // CAUTION : DSP281x_ECan.h , Version 1.0 ( Hareesh) contains an error // the byte field of struct CANMDL_BYTES and CANMDH_BYTES // have the wrong order ( Byte1 to 4)instead of Byte 4 to 1) // MODIFY : inside DSP281x_ECan.h modify the two structures to : // struct CANMDL_BYTES { // bits description // Uint16 BYTE3:8; // 31:24 // Uint16 BYTE2:8; // 23:16 // Uint16 BYTE1:8; // 15:8 // Uint16 BYTE0:8; // 7:0 // }; // // struct CANMDH_BYTES { // bits description // Uint16 BYTE7:8; // 63:56 // Uint16 BYTE6:8; // 55:48 // Uint16 BYTE5:8; // 47:40 // Uint16 BYTE4:8; // 39:32 // }; //########################################################################## #include "DSP28x_Project.h" #define IDENTIFIER 0x10000000 // Prototype statements for functions found within this file. void Gpio_select(void); // Global Variables /* Create a shadow register structure for the CAN control registers. This is needed, since, only 32-bit access is allowed to these registers. 16-bit access to these registers could potentially corrupt the register contents. This is especially true while writing to a bit (or group of bits) among bits 16 - 31 */ struct ECAN_REGS ECanaShadow; main() { // Initialize System Control registers, PLL, WatchDog, Clocks to default state: // This function is found in the DSP28_SysCtrl.c file. InitSysCtrl(); // Initialise the physical pins of the DSP Gpio_select(); /* Initialize the CAN module */ InitECan(); /* Write to the MSGID field - MBX number is written as its MSGID */ ECanaMboxes.MBOX1.MSGID.all = IDENTIFIER; // extended identifier ECanaMboxes.MBOX1.MSGID.bit.IDE = 1; /* Configure Mailbox 1 as Receiver mailbox */ ECanaShadow.CANMD.all = ECanaRegs.CANMD.all; ECanaShadow.CANMD.bit.MD1 = 1; ECanaRegs.CANMD.all = ECanaShadow.CANMD.all; /* Enable Mailbox 1 */ ECanaShadow.CANME.all = ECanaRegs.CANME.all; ECanaShadow.CANME.bit.ME1 = 1; ECanaRegs.CANME.all = ECanaShadow.CANME.all; /* Begin Receiving */ while(1) { do { ECanaShadow.CANRMP.all = ECanaRegs.CANRMP.all; } while(ECanaShadow.CANRMP.bit.RMP1 != 1 ); // Wait for RMP1 to be set.. ECanaShadow.CANRMP.bit.RMP1 = 1; ECanaRegs.CANRMP.all = ECanaShadow.CANRMP.all; // Clear RMP1 bit and start again } } void Gpio_select(void) { EALLOW; GpioCtrlRegs.GPAMUX1.all=0; //PORT A IS THE can PORT GpioCtrlRegs.GPAMUX2.all=0; GpioCtrlRegs.GPBMUX1.all=0; GpioCtrlRegs.GPBMUX2.all=0; GpioCtrlRegs.GPAMUX2.bit.GPIO19 = 3; // setting gpio19 as CANTXA GpioCtrlRegs.GPAMUX2.bit.GPIO18 = 3; // setting gpio18 as CANRXA GpioCtrlRegs.GPADIR.all=0; // GPIO PORTs as input GpioCtrlRegs.GPBDIR.all=0x00ff; // GPIO Port B15-B8 input , B7-B0 output GpioCtrlRegs.GPCDIR.all=0; GpioCtrlRegs.GPAQSEL1.all=0; // Set GPIO input qualifier values GpioCtrlRegs.GPAQSEL2.all=0; GpioCtrlRegs.GPBQSEL1.all=0; GpioCtrlRegs.GPBQSEL2.all=0; GpioDataRegs.GPBDAT.all = 0x0000; // Switch off LED's ( B7...B0) EDIS; }