XC2287 HOT Exercise CAN_ Communication using the CAN Module
XC2267 HOT Exercise CAN_ Serial Communication using the CAN Let s get started now! Page 2
HOT Exercise CAN_ Simple USIC Example In this exercise you will: Configure the XC2000 with DAvE Configure USIC 0 Channel 0 as a UART Receive a character from a PC and generate a receive interrupt Transmit the character on CAN node 0 and receive the CAN message on CAN node Transmit the value back to the PC and toggle one of the LEDs on the board on receipt of every character Page 3
HOT Exercise CAN_ RS232 & CAN settings RS232 Settings Baud Rate = 9200 Baud 8 bit data, stop bit, no parity Receive interrupt RXD:P7.4 TXD: P7.3 CAN Settings Baud Rate = 500 kbaud Message Object 2 : CAN node 0, transmit, byte, -bit ID = 0x Message Object 5 : CAN node, receive, byte, -bit ID = 0x RX-interrupt, level 5 CAN 0: RX: P2.0, TX P2. CAN ; RX: P2.4, TX P2.2 Page 4
HOT Exercise CAN_ Flow Chart /2 Init CAN Module Module enable Fractional Divider EINIT write protected register Init CAN Node Enable node and interrupts Configure pin connections Set baud rate Assign Message Objects to node Init Message Objects (MO) RX/TX mode data length INT pointer and enable Identifier Data content Enable MO CAN_2 Init Main fsys=80mhz Init USIC Init MultiCAN Module Node 0 Node Message Objects Start nodes While() Start Node on CAN Bus Page 5
HOT Exercise CAN_ Flow Chart 2/2 USIC 0 Channel 0 (ASC) Interrupt ASC RX Interrupt Clear ASC status register Received Character -> MOData2 Sent MOData2 Exit CAN Message Object 5 Interrupt CAN MO5 RX Interrupt Clear CAN status register Received Character -> U0C0 ASC TX Sent U0C0 ASC Exit Page 6
HOT Exercise CAN_ Start DAvE Start DAvE Select Open an existing project' from the startup dialog or click Select the USIC_ project from the previous example Page 7
HOT Exercise CAN_ - DAvE Configurations Project Settings Now do File and Save As Browse and create folder c:\ifx_hot\vx_code_workspace\can_ Enter project name: CAN_' Click 'Save. Page 8
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings XC2287 MultiCAN : Click on the Page 9
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure MultiCAN General: Enable module Page 0
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure MultiCAN General: Select Node 0 Page
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure CAN Node 0 General: Select P2.0 for Receive Input and P2. for Transmit Output Initialize the CAN node 0 Page 2
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure CAN Node 0 Baud Rate: Required baud rate : 500 Kbaud TSeg2 : 5 to get Real baud rate at 500 Kbaud Page 3
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure MultiCAN General: Select Node Page 4
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure CAN Node General: Select P2.4 for Receive Input and P2.2 for Transmit Output Initialize the CAN node Page 5
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure CAN Node Baud Rate: Required baud rate : 500 Kbaud TSeg2 : 5 to get Real baud rate at 500 Kbaud Page 6
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure MultiCAN List, 2: Drag M02 and drop it to List (Node 0) Drag M05 and drop it to List 2 (Node ) Page 7
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure MultiCAN M0s: Select M02 Page 8
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure CAN Message Object (M02) Object: Enable MO2, Select Transmit data frames Identifier: 0x0, Data Length: data bytes Page 9
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure MultiCAN M0s: Select M05 Page 20
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure CAN Message Object (M05) Object: Enable MO5, Select Transmit data frames Identifier: 0x0, Data Length: data bytes Page 2
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure CAN Message Object (M05) Interrupt: Enable receive interrupt Use CAN SRN 0 Page 22
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure MultiCAN Interrupts : Drag CAN INT 0 and drop it to Interrupt Level 4, Group 0 Page 23
HOT Exercise CAN_ - DAvE Configurations A MultiCAN settings Configure MultiCAN Functions: Include CAN_vInit Include CAN_vTransmit and CAN_vLoadData Page 24
HOT Exercise CAN_ - DAvE Configurations Save DAvE Project Save your DAvE Project File Go to File Save (or Save As) or click on Filename entered previously: c:\ifx_hot\vx_code_workspace\can_\can_.dav Page 25
HOT Exercise CAN_ - DAvE Configurations Code Generation Let DAvE Generate Code for You Go to File generate Code or click on DAvE generated code files are MAIN.C, MAIN.H USIC0.C, USIC0.H U0C0.C, U0C0.H IO.C, IO.H SCS.C, SCS.H CAN.C CAN.H XC22XXREGS.H Page 26
HOT Exercise CAN_ Tasking VX Toolset Open Project Work Space if not already open Click on Filename: browse to c:\ifx_hot\vx_code_workspace Click OK 2 Page 27
HOT Exercise CAN_ Tasking VX Toolset Create New Project Click on Workbench (if not already there ) Page 28
HOT Exercise CAN_ Tasking VX Toolset Create New Project Click on File and New Select Tasking VX-toolset Click OK 2 Page 29
HOT Exercise CAN_ Tasking VX Toolset Create New Project Create Project name `CAN_ Same name as DAvE directory Select Default Location Select Empty project Click Next 2 3 4 Page 30
HOT Exercise CAN_ Tasking VX Toolset Create New Project Select Configuration just Debug (this enables symbolic debug information automatically) Set Options 3 2 4 Page 3
HOT Exercise CAN_ Tasking VX Toolset Refresh files in the project Right click on CAN_ in the navigator Select Refresh from the pull down menu Click on the + to the right of ADC_ to expand the project to be able to see all the files 2 Page 32
HOT Exercise CAN_ Tasking VX Toolset Exclude the CAN_.asm file Right click on CAN_.asm in the file list Select Exclude from build Then check Debug 2 3 Page 33
HOT Exercise CAN_ Tasking VX Toolset Set Target Board Configuration for Project ADC_ Click on Select Infineon XC2287 Easy Kit Board Select DAS over MiniWigglerII Select Single Chip Select XC2287-96F 2 3 Page 34
HOT Exercise CAN_ Tasking VX Toolset Set Project Properties Click on Project and Properties Click Setting and Preprocessing Disable Automatic inclusion of.sfr file 3 4 5 2 6 Page 35
HOT Exercise CAN_ Tasking VX Toolset Set Project Properties Click on Project and Properties Click Run/Debug Settings Select CAN_ simulator and click on delete 3 4 5 2 6 Page 36
HOT Exercise CAN_ Tasking VX Toolset 4 3 3 2 Page 37
HOT Exercise CAN_ Tasking VX Toolset Software Hint DAvE doesn t change code that is inserted in the USER CODE sections if you let DAvE regenerate the code. Therefore, whenever adding code to the generated code, write it into a USER CODE section. The code you have to add should look like this: while() { // USER CODE BEGIN (Main,4) BlinkLED(); // USER CODE END } Page 38
HOT Exercise CAN_ - Complete code Edit File U0C0.C In the ISR function U0C0_ASC_vi0IC(void) (almost at the end) _interrupt(u0c0_0int) void U0C0_ASC_vi0IC(void) { // USER CODE BEGIN (ASC0IC,2) // USER CODE END if (U0C0_PSR & 0x4000) { // USER CODE BEGIN (ASC0IC,4) CAN_MODATA2LL = U0C0_RBUF; //store received character in MO2 CAN_vTransmit(2); // USER CODE END } U0C0_PSCR = 0x4000; // clear PSR_RIF // USER CODE BEGIN (ASC0IC,5) // USER CODE END } // End of function U0C0_ASC_vi0IC Page 39
HOT Exercise CAN_ - Complete code Edit File CAN.C In the ISR function CAN_viSRN0(void) (almost at the end) _interrupt(can_srn0int) void CAN_viSRN0(void) { uword uwsrn0objhandler; : : while (CAN_MSID0!= 0x0020) { switch(can_msid0){ case 5: // message object 5 interrupt uwsrn0objhandler = CAN_HWOBJ[5].uwMOCTRL; if(uwsrn0objhandler & MOSTAT_RXPND) // if message object 5 receive { // USER CODE BEGIN (SRN0_OBJ5,) IO_vTogglePin(IO_P0_0); U0C0_ASC_vSendData(CAN_MODATA5LL); // USER CODE END : : Page 40
HOT Exercise CAN_ Tasking VX Toolset Build Project Click on Build Project CAN_ Result should be Linking to CAN_.elf Page 4
HOT Exercise CAN_ Connect XC2267 Board Disconnect power supply from the board Connect CAN nodes: Connect wires from node A to node B (connect CAN_L to CAN2_L and CAN_H to CAN2_H) CAN USB CAN 2 Infineon XC2267 Page 42
HOT Exercise CAN_ Tasking EDE Connect XC2287 Easy Kit Connect XC2287 Board to PC Check the DIP Switch Settings on S02: OFF-OFF-OFF-OFF (Start from Internal Flash) Reset The Board (Press The Reset Button) S02 Standard Internal Start configuration ON DIP 2 3 4 USB Reset button Page 43
HOT Exercise CAN_ Start HyperTerminal With the FTDI chip an on board, USB interface can be used for UART. FTDI device will converts the USB protocol the ASC protocol. Both USB and UART can be used at the same time. Open Device Manger and check which COM port is activated for the FTDI chip Page 44
HOT Exercise CAN_ Start HyperTerminal. Start->Programs->Accessories->Communications->HyperTerminal 2. Enter any name and click OK 3. Connect using: COMx (COM port activated for the FTDI chip) 4. Click Configure to enter Port settings 5. Select 9200 baud, no Parity, 8 Data Bits and Stop Bit 6. Click OK Page 45
HOT Exercise CAN_ Tasking VX Toolset Run Debugger Click on Click on Resume and start program 2 Page 46
HOT Exercise CAN_ Running the program Start typing Enter ASCII characters in the HyperTerminal The characters you enter are sent to the XC2287 and back to the Terminal Program so that you can read them on the screen The characters are not sent directly from the keyboard to the screen! Hold the reset button down to verify that the screen no longer displays the typed characters Page 47
HOT Exercise CAN_ Tasking VX Toolset Run Debugger See Results The LED toggles as keys are pressed on the keyboard LED Toggles Page 48
HOT Exercise CAN_ Tasking VX Toolset Run Debugger Verifications Click on Suspend Click on Restart The LED no longer toggles when a key is pressed Click on Resume LED toggles again when a key is pressed Page 49