// // Lab CAN_1 : TMS320F2812 // (C) Frank Bormann // //########################################################################### // // FILE: Lab_CAN_1.c // // TITLE: DSP28 CAN - Transmission with the Zwickau-adapterboard // // Jumper JP4 : 2-3 ( 120 Ohm enabled) // Jumper JP5 : 1-2 ; Jumper JP6 _ 1-2 ( highspeed transceiver SN // // Aim of the test : // Transmit the status of the 8 switches from GPIO - Port B15...B8 // repeat the transmission every second // Mailbox 5 is used for transmission // 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_1 // 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); void delay_loop(); Uint16 loopcount =0; // 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 */ ECanaMboxes.MBOX5.MSGID.all = IDENTIFIER; ECanaMboxes.MBOX5.MSGID.bit.IDE = 1; // Extended Identifier /* Configure Mailbox under test as a Transmit mailbox */ ECanaShadow.CANMD.all = ECanaRegs.CANMD.all; ECanaShadow.CANMD.bit.MD5 = 0; ECanaRegs.CANMD.all = ECanaShadow.CANMD.all; /* Enable Mailbox under test */ ECanaShadow.CANME.all = ECanaRegs.CANME.all; ECanaShadow.CANME.bit.ME5 = 1; ECanaRegs.CANME.all = ECanaShadow.CANME.all; /* Write to DLC field in Master Control reg */ ECanaMboxes.MBOX5.MSGCTRL.bit.DLC = 1; ECanaMboxes.MBOX5.MDL.all = 0x00000005; ECanaMboxes.MBOX5.MDH.all = 0x00000005; /* Begin transmitting */ for(;;) { ECanaShadow.CANTRS.all = 0; ECanaShadow.CANTRS.bit.TRS5 = 1; // Set TRS for mailbox under test ECanaRegs.CANTRS.all = ECanaShadow.CANTRS.all; do { ECanaShadow.CANTA.all = ECanaRegs.CANTA.all; } while(ECanaShadow.CANTA.bit.TA5 == 0 ); // Wait for TA5 bit to be set.. ECanaShadow.CANTA.all = 0; ECanaShadow.CANTA.bit.TA5 = 1; // Clear TA5 ECanaRegs.CANTA.all = ECanaShadow.CANTA.all; loopcount ++; } asm(" ESTOP0"); // Stop here } 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; } void delay_loop() { long i; for (i = 0; i < 10000000; i++) {} }