XC2287M HOT Solution CAN_3 Serial Communication using the CAN with external CAN Bus and RX FIFO Device: XC2287M-104F80 Compiler: Tasking Viper 2.4r1 Code Generator: DAvE 2.1 XC2287M HOT Exercise CAN_3 Serial Communication using the CAN_2 with external CAN-BUS and RX FIFO Let’s Let’s get get started started now! now! 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 2 XC2287M HOT Exercise CAN_3 Interaction of Development Tools IDE Compiler Compiler Assembler Assembler Linker Linker Locator Locator DAvE Programming Tool Debugger int main(){ char a; long b; … Target Debugger/Emulator SW SW 04.08.2010 HW HW Copyright © Infineon Technologies 2008. All rights reserved. Page 3 HOT Exercise CAN_3 Objective Use a terminal program to send ASCII characters via the serial port to ASC0 and forward to CAN Node 0 Transmit characters via external CAN-Bus to Node 1 Node 1 uses a FIFO and sends back the received charters via ASC when the FIFO buffer is full. Forward from CAN Node 1 back to ASC0 Transmit the received ASCII characters back to the PC PC Terminal XC2287M ASC 0 CAN Node 0 CAN Node 1 RX FIFO 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 4 HOT Exercise CAN_3 Block Diagram RXD: P7.4 TXD: P7.3 USIC 0 – ASC 0 RxD TxD Receive ReceiveBuffer Buffer PC PC RxD TxD U0C0 U0C0Receive ReceiveIRQ IRQ Priority Priority33 Transmit TransmitBuffer Buffer RS 232 via USB CAN Node 0 • 19200 Baud •8n1 • RX interrupt CAN CANMSG MSGOBJ OBJ10 10 ID=0x11 CAN_L Transfer by Interrupt handler Ext. CAN Bus CAN Node 1 CAN_L FIFO = CAN_H RX: P2.6 TX: P2.5 CAN_H CAN CANMSG MSGFIFO FIFO OBJ 0, OBJ 1, OBJ 0, OBJ 1,OBJ2 OBJ2 ID=0x11 RX: P2.4 TX: P2.2 FIFO FIFOOverflow OverflowIRQ IRQ Priority Priority55 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 5 HOT Exercise CAN_3 - DAvE Configurations Start DAvE Start DAvE Click on the Create a new project (Startup Dialog pop up automatically) Click on ‘Create a new project’ Select microcontroller: ‘XC2287M’ 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 6 HOT Exercise CAN_3 Start DAvE (cont.) 1 2 3 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 7 HOT Exercise CAN_3- DAvE Configurations Project Settings Project Settings Close the window 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 8 HOT Exercise CAN_3 - DAvE Configurations Save DAvE Project Save your DAvE project Path: C:\IFX_HOT\XC2287M\Examples\CAN_3 Project name: CAN_3\CAN_3.dav 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 9 HOT Exercise CAN_3 - DAvE Configurations Save DAvE Project Save your DAvE Project File 1 2 3 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. 4 Page 10 HOT Exercise CAN_3 - DAvE Configurations ASC settings RS232 Settings Baud Rate = 19200 Baud 8 bit data, 1 stop bit, no parity Receive interrupt RXD:P7.4 TXD: P7.3 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 11 HOT Exercise CAN_3 - DAvE Configurations ASC settings XC2287M USIC0 : ¬ Click on the 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 12 HOT Exercise CAN_3 - DAvE Configurations ASC settings XC2287M USIC0 : ¬ Select ASC for U0C0 protocol ¬ Click 04.08.2010 to exit Copyright © Infineon Technologies 2008. All rights reserved. Page 13 HOT Exercise CAN_3 - DAvE Configurations ASC settings XC2287M USIC0, CH0 : ¬ Click on the 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 14 HOT Exercise CAN_3 - DAvE Configurations ASC settings Configure CH0 ASC ASC General: ¬ Enable module clock ¬ Select P7.3 for TxD and P7.4 for RxD 1 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 15 HOT Exercise CAN_3 - DAvE Configurations ASC settings Configure CH0 ASC Control: ¬ Enable Receive Interrupt 1 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 16 HOT Exercise CAN_3 - DAvE Configurations ASC settings Configure CH0 ASC Interrupts: ¬ Drag ‘U0C0_0IC INT’ and drop it to Interrupt Level 3, Group 0 1 2 3 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 17 HOT Exercise CAN_3 - DAvE Configurations ASC settings Configure CH0 ASC Functions: ¬ Include ‘U0C0_ASC_vInit’ ¬ Include ‘U0C0_ASC_vSendData’ 3 1 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 18 HOT Exercise CAN_3 - DAvE Configurations Port settings XC2287M Port: ¬ Click on the 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 19 HOT Exercise CAN_3 - DAvE Configurations Port settings Parallel Ports Ports: ¬ Configure Port 10 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 20 HOT Exercise CAN_3 - DAvE Configurations Port settings Configure Port 10 Port 10: ¬ Use P10.0 as general IO ¬ Set Direction to Out ¬ Close the window 2 1 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 21 HOT Exercise CAN_3 - DAvE Configurations Port settings Parallel Ports Functions: ¬ Include ‘IO_vInit’ ¬ Include ‘IO_vTogglePin’ 3 1 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 22 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings CAN Settings Baud Rate = 500 kBaud CAN 0: RX: P2.6, TX P2.5 CAN 1; RX: P2.4, TX P2.2 Message Object 10 : CAN node 0, transmit, 1 byte, 11-bit ID = 0x11 Message Object 0 : CAN node 1, receive FIFO base object, 1 byte, 11-bit ID = 0x11 FIFO Overflow-Interrupt, level 5 Message Object 1 : CAN node 1, receive FIFO slave object, Message Object 2 : CAN node 1, receive FIFO slave object, 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 23 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings XC2287M MultiCAN : ¬ Click on the 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 24 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure MultiCAN General: ¬ Enable module 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 25 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure MultiCAN General: ¬ Select Node 0 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 26 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure CAN Node 0 General: ¬ Select P2.6 for Receive Input and P2.5 for Transmit Output ¬ Initialize the CAN node 0 automatically 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 27 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure CAN Node 0 Baud Rate: ¬ Required baud rate : 500 Kbaud ¬ Modify TSeg1/TSeg2 to get Real baud rate at 500 Kbaud 5 1 2 3 4 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 28 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure MultiCAN General: ¬ Select Node 1 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 29 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure CAN Node 1 General: ¬ Select P2.4 for Receive Input and P2.2 for Transmit Output ¬ Initialize the CAN node 1 automatically 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 30 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure CAN Node 1 Baud Rate: ¬ Required baud rate : 500 Kbaud ¬ Modify TSeg1/TSeg2 to get Real baud rate at 500 Kbaud 5 1 2 3 4 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 31 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure MultiCAN List1, 2: ¬ Drag 'MO10' and drop it to List 1 (Node 0) ¬ Drag 'MO0', 'MO1', 'MO2' and drop it to List 2 (Node 1) 1 2 3 04.08.2010 4 Copyright © Infineon Technologies 2008. All rights reserved. Page 32 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure MultiCAN M0s: ¬ Select MO0 1 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 33 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure CAN Message Object (M00) Object: ¬ Enable MO0, Select Receive data frames ¬ Identifier: 0x011, Data Length: 1 data bytes 1 4 3 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 34 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure CAN Message Object (M00) FIFO/Gateway: ¬ Enable MO0, Select Receive FIFO base object ¬ FIFO Pointers: Bottom MO0, Top MO2, Object select MO0 1 2 3 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 35 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure CAN Message Object (M00) Interrupt: ¬ Enable FIFO overflow interrupt ¬ Use CAN SRN 0 4 1 2 04.08.2010 3 Copyright © Infineon Technologies 2008. All rights reserved. Page 36 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure MultiCAN M0s: ¬ Select MO10 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 37 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure CAN Message Object (MO10) Object: ¬ Enable MO10, Select Transmit data frames ¬ Identifier: 0x011, Data Length: 1 data bytes 5 1 4 3 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 38 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure MultiCAN Interrupts : ¬ Drag ‘CAN INT 0’ and drop it to Interrupt Level 4, Group 0 1 2 3 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 39 HOT Exercise CAN_3 - DAvE Configurations MultiCAN settings Configure MultiCAN Functions: ¬ Include ‘CAN_vInit’ ¬ Include ‘CAN_vTransmit’, ‘CAN_ubWriteFIFO, CAN_ubReadFIFO’ 4 1 2 04.08.2010 3 Copyright © Infineon Technologies 2008. All rights reserved. Page 40 HOT Exercise CAN_3 - 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\XC2287M\Examples\CAN_3\CAN_3.dav” 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 41 HOT Exercise CAN_3 - DAvE Configurations Code Generation Let DAvE Generate Code for You Go to File Æ generate Code or click on DAvE generated code files are ¬ ¬ ¬ ¬ ¬ ¬ ¬ ‘CAN.c’, ‘CAN.h’ ‘U0C0.c’, ‘U0C0.h’ ‘IO.c’, ‘IO.h’ ‘USIC0.c’, ‘USIC0.h’ ‘MAIN.c’, ‘MAIN.h’ ‘SCS.c’, ‘SCS.h’ ‘XC22xxREGS.h’ In general: ¬ if the included function is a macro it is included in the ‘.h’ file ¬ if the included function is a function it is included in the ‘.c’ file 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 42 HOT Exercise CAN_3 – Tasking VX Toolset Open Project Work Space Click on Filename: browse to “c:\IFX_HOT\XC2287M\Examples” Click ‘OK’ 1 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 43 HOT Exercise CAN_3 – Tasking VX Toolset Create New Project 04.08.2010 Click on Workbench (if not already there…) Copyright © Infineon Technologies 2008. All rights reserved. Page 44 HOT Exercise CAN_3 – Tasking VX Toolset Import DAVE Project 1 Click on File -> Import Select Tasking VX-toolset for C166… Click ‘OK’ 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 45 HOT Exercise CAN_3 – Tasking VX Toolset Import DAVE Project Click `Infineon DAvE C166 Project´ Click ‘Next’ CAN_1 1 2 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 46 HOT Exercise CAN_3 – Tasking VX Toolset Import DAvE Project Add Dave Project ‘CAN_3´ Click `Finish´ 2 1 3 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 47 HOT Exercise CAN_3 – Tasking VX Toolset Configure Target Board 1 Select the project in the navigator Select ‘Project/Target Board 2 Configuration’ Select ‘Infineon XC2000/XE166 Easykit Board’ Choose `XC2287M-104F´ Click `Finish´ 3 4 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 48 HOT Exercise CAN_3 – 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 really have to add looks like this: while(1) { // USER CODE BEGIN (Main,4) BlinkLED(); // USER CODE END } 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 49 HOT Exercise CAN_3 - 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_MODATA10LL = U0C0_RBUF; //store received character in MO10 CAN_vTransmit(10); // USER CODE END U0C0_PSCR |= 0x4000; } // USER CODE BEGIN (ASC0IC,15) // USER CODE END // clear PSR_RIF } // End of function U0C0_ASC_vi0IC 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 50 HOT Exercise CAN_3 - Complete code Edit File ‘CAN.C’ In the ISR function ‘CAN_viSRN0(void)’ (almost at the end) _interrupt(CAN_SRN0INT) void CAN_viSRN0(void) { // USER CODE BEGIN (SRN0,2) IO_vTogglePin(IO_P10_0); U0C0_ASC_vSendData (CAN_MODATA0LL); U0C0_ASC_vSendData (CAN_MODATA1LL); U0C0_ASC_vSendData (CAN_MODATA2LL); // USER CODE END : } // End of function CAN_viSRN0 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 51 HOT Exercise CAN_3 – Tasking VX Toolset Build Project 1 Click on ‘Build Project CAN’ 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 52 HOT Exercise CAN_3 - Device Access Server Check for the latest DAS version Note: It is recommended to use the latest DAS version. Download the latest version at www.infineon.com\DAS 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 53 HOT Exercise CAN_3 - Device Access Server 1.) Checking USB connections This gets identified only when COM port is used •Via the USB interface on the Easykit with FTDI chip The DAS JTAG composite device gets identified •When miniWiggler is connected •When USB Wiggler Box is connected •Via the USB interface on the Easykits with FTDI chip 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 54 HOT Exercise CAN_3 - Device Access Server 2.) Check DAS status 1. Start DAS device scanner 2. Start DAS Server Control panel 3. If DAS device scanner does not show any device, start the appropriate DAS server Incase you are connected via the USB Wiggler box, then start „JTAG over USB Box“ Incase you are connected via the FTDI chip or mini wiggler, then start „UDAS“ 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 55 HOT Exercise CAN_3 - Device Access Server 3.) Starting the servers manually 4. Incase „UDAS“ server is started and XC2000 easykit is connected via on-chip FTDI or via separate miniWiggler, following status changes could be noted 5. Incase „JTAG over USB Box“ server is started and XC2000 starter kit is connected via Wiggler box, following status changes could be noted 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 56 HOT Exercise CAN_3 Connect XC2287M Board Disconnect power supply from the board Connect CAN nodes: Connect wires from node A to node B (connect CAN1_L to CAN2_L and CAN1_H to CAN2_H) CAN 1 CAN 2 1 USB 1 Infineon XC2287M 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 57 HOT Exercise CAN_3 Connect XC2287M Board Internal start from Flash Connect XC2287M Board to PC Modify the DIP switch settings, S102: OFF-OFF-OFF-OFF-OFF Reset the board (press the reset button) S102 Standard Internal Start configuration ON 1 2 3 4 DIP 5 USB DC power supply Reset button 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 58 HOT Exercise CAN_3 – Tasking VX Toolset Run Debugger 1 Click on 2 Click on ‘Resume’ and start program 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 59 HOT Exercise CAN_3 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 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 60 HOT Exercise CAN_3 Start HyperTerminal 1. 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 19200 baud, no Parity, 8 Data Bits and 1 Stop Bit 6. Click ‘OK’ 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 61 HOT Exercise CAN_3 Running the program Start typing Enter ASCII characters in the HyperTerminal At each third character you are typing the Interrupt routine sends back the received characters through the CAN bus 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! 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 62 HOT Exercise CAN_3 See Result The yellow LED will toggle when three characters are´receive in CAN Node1s FIFO LED blinking 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 63 HOT Exercise CAN_3 Verification Verification 1: (stop the program) Go to Tasking debugger Click on ‘Suspend’ Go back to the terminal program and start typing again: ⇒ you will no longer see what you are typing. Verification 2: (start the program) Go to Tasking debugger and start the program. Go back to the terminal program and start typing again: Pull out the CAN cable ⇒ you will no longer see what you are typing 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 64 Tasking Viper "Profile Storage Space Exceeded" Edit config.ini C:\Program Files\TASKING\C166-VX v2.4r1\eclipse\configuration\ . . . # The default configuration location for this run of the platform. The configuration # determines what plug-ins will run as well as various other system settings. # osgi.configuration.area = @user.home/.eclipse_c166_v2.4r/config osgi.configuration.area = C:/UserData/_login-name_/.eclipse_c166_v2.4r/config # The default location of the user area. The user area contains data (e.g., preferences) # specific to the OS user and independent of any Eclipse install, configuration or instance. # osgi.user.area = @user.home/.eclipse_c166_v2.4r osgi.user.area = C:/UserData/_login-name_/.eclipse_c166_v2.4r # The default workspace location # osgi.instance.area.default = @user.home/workspace_c166_v2.4r osgi.instance.area.default = C:/UserData/_login-name_/workspace_c166_v2.4r # TASKING plugins require at least Java runtime environment v1.5 osgi.requiredJavaVersion = 1.5.0 # The build identifier eclipse.buildId=I20070625-1500 # End of file marker - must be here eof=eof 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 65 Tasking Viper "Profile Storage Space Exceeded" Delete old directories in profile space C:\Documents and Settings\_login-name_\.eclipse_c166_v2.4r Rescan Profile Storage (double click; OK) 04.08.2010 Copyright © Infineon Technologies 2008. All rights reserved. Page 66