Home

Using the MCF51EM Family for Infrared Communication

image

Contents

1. UINT8 ee temp Table HEX BUFFER SIZE Buffer used by Table 0 Buffer used by Table 2 Buffer used by Table 3 Backup table used in flash write b To add a new table saved in RAM it must be added as shown here RKKKKKKKKKKKKEK DECLARATION OF TH EF VOLATILE TABLES Fe KK KK UINT8 TableO TABLEO_ SIZE UINT8 Table2 TABLE2 SIZE UINT8 Table3 TABLE3_ SIZE UINT8 newTable newTABLE SIZE E UINT8 temp Table HE X BUFF ER SIZE l 7 g Generate tables located in flash Buffer used by Table 0 Buffer used by Table 2 Buffer used by Table 3 Buffer used by new Table Backup table used in flash write To locate tables in flash memory the Linker Command file must be edited as shown here a Open the file Project Icf b In anew project the original lines are Memory ranges MEMORY code RX ORIGIN 0x00000410 LENGTH 0x0003FBFO userram RWX ORIGIN 0x00800000 LENGTH 0x00004000 Using the MCF51EM Family for Infrared Communication Rev 0 22 Freescale Semiconductor Software c To allow storing data in flash the lines must be replaced with Memory ranges MEMORY code RX ORIGIN 0x00000410 LENGTH 0x0001FBFO my tables RX ORIGIN 0x00020800 LENGTH 0x00000400 userram RWX ORIGIN 0x00800000 LENGT
2. Freescale Semiconductor 33 Hardware tests f Cursor 2 243 us 80 0m M S 00us CHI Z 2 08 30 Jan 09 17 24 133 640H2 Figure 20 Modulating signal period 5 4 Test 3 Pulse stretcher modulation This test shows the implementation of the timer TPM in PWM mode to generate a pulse signal applied to the transmission signal to get pulse stretcher modulation This kind of modulation is used in IrDA The conditions for this test are e Modulation to 3 16 of a bit using SCI and timer in PWM mode e A pulse indicates a logical 0 e Baud rate is 9600 bps and transmitted data is 0x41 In Figure 21 channel 1 of the scope is the signal without modulation and channel 2 is the modulated signal ame CH1 200 CH2 200V M 100us CHI Z 2 004 6 Jan 03 16 07 23 03 11Hz Figure 21 Pulse stretcher signal 5 5 Test 4 Protocol implementation This test shows the implementation of the communication protocol using two demo boards one used as an infrared bridge and the other executing the protocol Here are the conditions for this test e Computer is connected to DEMOEM 1 which has been programmed with BridgeIR software e DEMOEM 2 has been programmed with protocol software e Boards are aligned TX gt RX RXDTX e Computer is running the Terminal Window application because DEMOEM has an embedded serial port through USB port supported only by this application If you want to use any other 1 TerminalWindow exe is included in AN3938
3. Main Loop Tasks prototypes void vfnTSK welcome void void vfnTSK show _change_br void void vfnTSK show _ir void void vfnTSK show tx _ irda void void vfnTSK protocol welcome void void vfnTSK comm protocol void Relations between tasks are shown in Figure 10 Double line circles are the tasks and the single line circles are functions called by each task Using the MCF51EM Family for Infrared Communication Rev 0 26 Freescale Semiconductor Software Start Increase baud rate Switch 2 pressed Switch 1 pressed time expired Switch 1 pressed and pulse stretcher modulation enabled Reduce baud rate Change baud rate Execute protocol Switch 3 pressed Switch 1 pressed Enable disable modulation Switch 4 pressed Protocol welcome Switch 1 pressed and pulse stretcher modulation enabled Increase and transmit shown data Switch 1 pressed Show IrDA Switch 2 pressed pulse stretched Switch 3 pressed Switch 4 pressed Switch 1 pressed Enable disable pulse stretcher modulation Switch 4 pressed Decrease and transmit shown data Enable disable drive strength Figure 10 EM256DemolR project state tasks diagram vfnTSK_ welcome This task shows a welcome message on the LCD screen The screen shows IR demoEM for three seconds and then jumps to vfnTSK_show_cha
4. e ANSIC prototype UINT8 u8SCL init UINT8 port UINT32 baudrate UINT8 length UINT8 parity UINT8 TXmode UINT8 RXmode Table 1 Input parameters Name Type port unsigned char baudrate unsigned long length unsigned char parity unsigned char TXmode unsigned char RXmode unsigned char Table 2 Return value unsigned char Value Description 0 Successful function execution 1 Invalid port 2 Baud rate error 3 Parity error 4 Transmission mode error 5 Reception mode error 4 1 4 Function u8IR_TX_ init e Description Configures pin options drive strength modulation source and interrupt enable for transmission of an SCI module e ANSIC prototype UINT8 u8IR_TX_init UINT8 port UINT8 tx_pin_option UINTS8 strength UINTS8 modulation UINTS8 tx_ie Table 3 Input parameters Name Type port unsigned char tx_pin_option unsigned char strength unsigned char modulation unsigned char tx_ie unsigned char Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor Software Table 4 Return value unsigned char Value Description 0 Successful function execution 1 Invalid port 2 Invalid modulation source 3 Incorrect selection 4 1 5 Function u8IR_RX_ init e Description Configures pin options comparator referen
5. Write R ONLY for read only tables W_ONLY for write only tables and R AND W for tables used for read and write Ifa new table was included its proprieties must be defined here f Locate these lines to define the type of tables TABLEx TYPE type of the table define RAND W 0 read and write define R_ONLY 1 read only define W_ONLY 2 write only define TABLEO TYPE R AND W define TABLE1 TYPE R AND W define TABLE2 TYPE R AND W define TABLE3 TYPE R AND W g define TABLEO TYPE R AND W define TABLE TYPE R AND W define TABLE2 TYPE R AND W define TABLE3 TYPE R AND W define newTABLE TYPE R AND W h Open the file com_protocol c i Locate these lines to generate the table description RK RK KK RK KKK oy struct Table Description 1 he r amp Table0d 0 amp Tablel 0 amp Table2 0 amp Table3 0 i f g m TRU TAB TAB TAB TAB CT FOR TABLES PROPERTIES xxx Table list TABLES NUMBER EO_SIZE TABLEO_TYPE TAB LE1 SIZE TABLE1 TYPE TABLE1 SECURITY 1 LE3 SIZE TAB LE3 TYPE TAB struct Table Description p table list E0 SECURITY 0 E2_SIZE TABLE2 TYPE TABLE2 SECURITY 2 LES SECURITY 3 Measurements Calibration Settings y Data logger Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 21 Software j The first parameter is the name of
6. executing test Figure 24 is a screen capture of the Terminal Window application showing the protocol executing commands Using the MCF51EM Family for Infrared Communication Rev 0 36 Freescale Semiconductor Considerations and references Terminal Window application v1 00 s Tool Kit Link Close Port Terminal Window Clear Window Communication Protocol using MCF51EM256 2300001 0000205441424C45204E554D04245522031204925320534156454420494E20464C415348CA gt 466662 662G6AGA1A2ZA3A4A5SAGA7ASAPAAABACADAEAFBGB1 B2 B3 B4B5 B6 B7 BS B BABBBCBDBEBF16 Bo gt 3 F6661 6666626085 60805 424045 264EBF gt 4F6061 666062 6665 6162636465F1 515 gt 3 88882 MG8G2GAGA1LAZA3A4A5SAGA7A8AIAAABACADAEAFBGB1 B2B3 B4B5 B6 B7B8 B BABBBCBDBEBF19 Communication Protocol using MCF51EM256 gt 366661 16662 65 441 616263646555 4D42 455226312649532053415645 442849 4E264640415348FC 2300002 OONAZAOOOHOAOOOOOHOOOOOOOOOOHOOOONOOHOOHONHONOOOOAOONOOOOOHONOOOOOHONHOAHA Figure 24 Terminal Window application protocol executing commands First command is Full Read on Table 1 Next command is Full Write on Table 2 Next command is an Offset Read command on Table 1 followed by an Offset Write command on Table 1 Then a reset was applied to the board and the protocol was restarted The next command a Full Write of Table 1 shows the nonvolatile data stored in Table 1 But the data in Table 2 was lost as shown in the last co
7. or le a external reference On board componente Analog comparator PTB2 Ala 3 Siso Faxie O 1 MQ R12 Digital 1 kQ buffer ai J16 C50 QTLP610CPD 1 2 0 1 uF P PTB3 TX1 2 BD 3x2 header TPM CHO output TPM CH1 output T1 MTIM2 output SIMIPS2 MODTX1 gt l A Pih or MODTX2 j YM I MTIM8 output QTLP610CIR SIMIPS2 MTBASE1 or MTBASE2 On chip components Figure 1 Hardware on MCF51EM256 and DEMOEM Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 3 Software Figure 2 shows the components on the DEMOEM board used for infrared communication Infrared Infrared transmitter receiver Jumpers Switch 1 Switch 2 e Switch 3 e Switch 4 MC9S08QE8 emulating 3 ph signals Figure 2 Hardware dedicated to infrared on DEMOEM 4 Software The software is divided into three separate projects e Infrared bridge e Protocol implementation e Infrared demo software Each of them is explained here 4 1 BridgelR project This project provides a tool to communicate between a wired serial interface and an infrared communication port using the DEMOEM board 4 1 1 Software Architecture The architecture of this project is based in the use of interruptions The main function initializes the hardware modules and enables the SCI interrupts When a character is received by the wired port 1 Data is taken from the reception register 2 The re
8. origin and the amount of data to be read 3 Full write Provides a fast command to write a complete data table 4 Offset write Useful to write a portion of a table For this implementation data is sent through an ASCII interface allowing the use of a simple terminal to send and receive data in hexadecimal format This ASCII interface can be removed easily to support binary communication Some considerations in the use of this protocol software are e Data length to be written using the FULL_ WRITE command must be less than or equal to the buffer size including command length e The OFFSET WRITE command must be used to send more data than the buffer size will hold e Tables located in nonvolatile memory must be in the second flash array from 0x20000 to Ox3FFFF and must be aligned within a flash page It is recommended to update as much information as possible on a single flash page which is 1024 bytes However it is allowed to write a single byte of information e Itis possible to execute code from one flash array while the other is being programmed but it is not allowed to simultaneously program and execute code in a single flash array 4 2 1 Packet structure This section describes how packets are structured for implemented commands Packets sent through the ASCII interface begin with the character gt ASCII 0x3E then have the command code followed by the table identifier The next parameters can change depending on a
9. showing measurements of the transmitted and received signals Channel 1 yellow is the signal sent by the transmission board Channel 2 blue is the signal received by the phototransistor and applied to the SCI RX pin Channel 3 pink is the received signal at the output of the analog comparator Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 31 Hardware tests MEASURE MEASURE 1 Apr Figure 14 Distance 0 cm baud rate 2400 bps MEASURE 116 Figure 16 Distance 1 8cm baud rate 300 bps Using the MCF51EM Family for Infrared Communication Rev 0 32 Freescale Semiconductor 5 3 Hardware tests Figure 18 Distance 1 8cm baud rate 9600 bps Test 2 High frequency modulation This test shows the implementation of the timer TPM to generate a 38 kHz signal applied to the transmission signal to get modulation Here are the conditions for this test Modulation at 38 kHz using timer TPM channel 0 Serial port SCI1 Transmitted data 0x41 Drive strength enabled Light conditions indoor fluorescent lamps Figure 19 shows transmitted data modulated by a 38 kHz modulating signal Figure 20 shows the period of the modulating signal Source E HI Wi M 5 00ms CHI Z 1 32 30 Jan 03 17 13 6 17853kHz Figure 19 Transmission modulated at 38 Hz baud rate is 300 bps Using the MCF51EM Family for Infrared Communication Rev 0
10. the RX status flag indicates that the protocol is waiting to receive a new command COMMAND WAITING Disable watchdog a ae Initialize flash Initialize SCI and configure TX Y Send through SCI port Communication Protocol using MCF51EM256 Configure SCI RX Y Enable global interrupts Z Execute protocol Flow charts of this project are shown below Figure 7 Flowchart of main function of Protocol project Using the MCF51EM Family for Infrared Communication Rev 0 16 Freescale Semiconductor Reception interruption Received data sent to u8received_data variable y Clear interrupt flag l Command End received and status flag receiving command Command Start received eceived data Command Start Status flag command received Yes Received data counter 0 Status flag receiving command No Y and status flag receiving Quantity of received data gt buffer size y Store received data in next buffer position Buffer invalidation Store received data in last buffer position RTI Figure 8 Flowchart of reception interrupt of Protocol project Using the MCF51EM Family for Infrared Communication Rev 0 Software Freescale
11. zip the associated software for this application note Using the MCF51EM Family for Infrared Communication Rev 0 34 Freescale Semiconductor Hardware tests terminal application you must populate the DB9 connector and U2 integrated circuit transceiver and change J7 and J8 jumpers Terminal Window application is configured with these settings e Port USB COM e Baud rate 4800 recommended value e Parity none e Bits 8 e Duplex Full e Char delay ms 5 e EOL delay ms 15 To execute a command write it in the base of the packet example structure explained in Section 4 2 1 Packet structure Pre written commands are included in AN3938 zip as text files and are organized in four folders according to the command function To execute a pre written command click on the button Download File to ComPort and select the text file you want to download Figure 22 and Figure 23 show an overview of the connections and orientation of the boards to execute the tests Infrared DEMOEM 2 communication Protocol Emitter gt i Receiver Receiver lt 4 Emitter DEMOEM 1 BridgelR Acrylic E EN Computer Serial interface wired Figure 22 Block diagram of connections between boards Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 35 Hardware tests EELEE Figure 23 Aligned boards
12. 1EM Family for Infrared Communication Rev 0 Figure 4 Flowchart of reception interrupt on wired port of BridgelR project Freescale Semiconductor Software Reception interrupt on infrared port Received data sent to temporal variable I Clear interrupt flag Temporal variable transmitted by wired port Figure 5 Flowchart of reception interrupt on infrared port of BridgelR project Transmission complete interrupt on infrared port Disable transmission interrupt of infrared port as Enable reception interrupt of infrared port RTI Figure 6 Flowchart of transmission complete interrupt of BridgelR project 4 1 2 Hardware customization code This section shows how to customize the code Code lines in red are customizable by the user 1 Customize SCI module for wired communication WIRED PORT SCI module for infrared communication IR_PORT and baud rate used BAUDRATE a Open the file main c b Locate these lines at the beginning of the file Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor Software c d e include m5lem256demo h include sci h include infrared h define IR PORT 1 define WIRED PORT 3 THESE PORTS CAN NOT BE THE SAME Write the number of the SCI modules you want to use only 1 2 or 3 These cannot be the same infrared p
13. C devices that are based on the 32 bit ColdFire V1 core and have these hardware key features for IR communication Drive strength for TX1 and TX2 pins can be enabled to drive twice the current of any other pins up to a maximum of 50 mA without an external driver SCII and SCI2 TX can be modulated by internal Timers This allows an AND operation of the SCI TX signal with TPMCHO TMPCH1 MTIM2 or MTIM3 outputs SCII and SCI2 Reception can be routed through the ACMP ACMP output is available via an external pin to add an external resistor R15 allowing the ACMP to provide positive feedback hysteresis The hardware provided by the MCF51EM on chip components and DEMOEM on board components have these advantages see Figure 1 The initialization requires only a few lines of code The hardware does the task by itself data transmission modulation signal conditioning using ACMP so the processor can perform other tasks in parallel or go to low power mode Timers provide an accurate modulation of the transmission signal The on chip analog comparator at the receiver avoids the need of using an external comparator to condition the signal Figure 1 shows internal external connections associated with IR communication that are implemented on the MCF51EM and DEMOEM PTEO VDD SIMIPS2 RX1 IN or RX2IN Internal
14. Freescale Semiconductor Application Note Document Number AN3938 Rev 0 10 2009 Using the MCF51EM Family for Infrared Communication by Carlos Casillas and Luis Puebla RTAC Americas Guadalajara Mexico 1 Introduction This application note shows the implementation of an infrared communication system composed of hardware and software The hardware takes advantage of specific features of Freescale s MCF51EM256 while the software protocol is based on the command structure of protocol C12 18 for metering applications This application note is divided into several sections Section 2 Basic information provides background information about infrared communication and hardware modules present in the MCF51EM256 that are used in this kind of communication Also the software projects included in this application note are listed Section 3 Hardware shows characteristics of the MCF51EM256 and the advantages of using them to implement infrared communication Section 4 Software includes software projects and shows flowcharts and customization options Freescale Semiconductor Inc 2009 All rights reserved RON Contents MoU s i ink deo eben stewed in da Seeds oa 1 Basic information 2 icidacnevet od oeeee e reb AE 2 ARO WARS EET Sd nied we E E stance eis eed wee 3 SOWA arei c3tcceaeceeee eet tealicdeeaaeeas 4 4 1 BridgelR project ccs cocseceseeaeeanae wees 4 4 2 Protocol project nic cas
15. H 0x00004000 FORCE ACTIVE Tablel In this case the code will be located only in flash array 1 128 KB and a new type of data is created and saved in flash array 2 which begins at address 0x0020000 But the first two pages contain configuration registers so the code will be used from the third page address 0x0020800 The size of this data type is 1024 bytes one memory sector and is named my_tables Anew memory range must be added for each table to locate it in a different memory sector allowing erasing and programming each of them independently For example a new table saved in flash is added at the last sector of flash array 2 address 0x0003FC00 and its memory ranges must be declared as shown here Memory ranges MEMORY code RX ORIGIN 0x00000410 LENGTH 0x0001FBFO my tables RX ORIGIN 0x00020800 LENGTH 0x00000400 my table2 RX ORIGIN 0x0003FC00 LENGTH 0x00000400 userram RWX ORIGIN 0x00800000 LENGTH 0x00004000 FORCE ACTIVE Tablel FORCE ACTIVE newTable d Insert these lines in the Project Icf file to create a new memory section to store flash tables EOM Symbols __ROM SYMBOLS start address of the 4x1024 bytes symbols romsymbols gt my tables FSL copy during runtime ROM SYMBOLS ROM SYMBOLS ADDR my_ tables One section must be created for each table For example to add the secti
16. Semiconductor 17 Software Protocol execution RX buffer conversion to hex buffer Conversion Invalidate successful buffer y Mt Send error Extract command response code from buffer Command Yes Execute code 0x30 Full Read command Command Yes Execute code 0x3F Offset Read command Command Yes Execute code 0x40 Full Write command Command Yes Execute code 0x4F Offset Write command a _ Send OK y No response Q Status flag command waiting END Figure 9 Flowchart of protocol function of Protocol project Using the MCF51EM Family for Infrared Communication Rev 0 18 Freescale Semiconductor 4 2 3 Software Software Customization Software customization is divided into two parts The first configures the hardware required by the protocol and its parameters can be customized SCI module used for communication Reference level used by the analog comparator Baud rate Enable and disable inversion on transmission The second part customizes the properties of the protocol and its parameters can also be customized Size of buffer used for reception Quantity of tables Type of tables read only write only read and write Location of the tables RAM or flash 4 2 3 1 Hardware customization code This section shows how to customize the code Re
17. ansmission pins can drive up to 50 mA SCI TX1 and SCI TX2 pins allowing an IR diode to be connected just by adding a series resistor e Signal conditioning Two reception pins RX can be internally connected to an analog comparator ACMP This is useful for conditioning the infrared analog signal to a digital signal e Modulation Two serial communication interface SCI transmission pins TX are capable of being internally modulated through the timer output e Dual flash array The MCF51EM has two flash memory arrays allowing erasing and writing one of them while code is executing from the other Software for this application note includes three different projects e IR RS 232 bridge Provides a communication bridge between a standard RS 232 PC serial port and an IR port This project is used as a tool to verify the functionality of the infrared communication It is implemented in DEMOEM e Protocol Offers an example of communication using basic commands to read and write data tables based on the ANSI C12 18 It can be customized to be used for a specific hardware application configuration e IR demo software This platform provides an LCD user interface and task manager customized to test modules in the MCF51EM that are associated with IR SCI ACMP TPM GPIOs Using the MCF51EM Family for Infrared Communication Rev 0 2 Freescale Semiconductor 3 Hardware Hardware The MCF51EM family are system on chip So
18. ble inversion for transmitted data a Open the file com_protocol h b Locate this line define REFERENCE LEVEL 27 Reference voltage used by the comparator define IR ACTIVE 1 1 TX INVERTED reference level used 0 TX NORMAL Dy reference level ignored c Write 1 if you want to invert the SCI transmission used in infrared or write 0 if you do not want to invert the signal normal mode 4 2 3 2 Protocol customization code 4 Customize the size of the buffer used for reception a Open the file com_protocol h b Locate this line R KK KK KK KK CONSTANTS DEFINITIONS kkkkkk kk kk kkkk kkxkkxk define RX_BUFFER_SIZE 2048 Defines the buffer size used for reception define HEX BUFFER SIZE RX BUFFER SIZE 2 Defines the buffer size used for converted values c Write the size of the buffer you want to use This value is the maximum number of ASCII characters that the system can receive per packet The recommended maximum value is 2048 because the buffer of hexadecimal data is half of this value and 1024 bytes is the size of a flash page If you need to send more data you must use the Offset Write command 5 Customize the quantity size and type of tables and generate the table description a Open the file com_protocol h b Locate this line to define the number of tables define TABLES NUMBER 4 defines numbe
19. bution Center 1 800 441 2447 or 303 675 2140 Fax 303 675 2150 LDCForFreescaleSemiconductor hibbertgroup com Document Number AN3938 Rev 0 10 2009 Information in this document is provided solely to enable system and software implementers to use Freescale Semiconductor products There are no express or implied copyright licenses granted hereunder to design or fabricate any integrated circuits or integrated circuits based on the information in this document Freescale Semiconductor reserves the right to make changes without further notice to any products herein Freescale Semiconductor makes no warranty representation or guarantee regarding the suitability of its products for any particular purpose nor does Freescale Semiconductor assume any liability arising out of the application or use of any product or circuit and specifically disclaims any and all liability including without limitation consequential or incidental damages Typical parameters that may be provided in Freescale Semiconductor data sheets and or specifications can and do vary in different applications and actual performance may vary over time All operating parameters including Typicals must be validated for each customer application by customer s technical experts Freescale Semiconductor does not convey any license under its patent rights nor the rights of others Freescale Semiconductor products are not designed intended or authorized for use as components
20. ce level and interrupt enable for reception of an SCI module e ANSIC prototype UINT8 u8IR_RX_init UINT8 port UINT8 rx pin option UINT8 cmp level UINTS8 rx ie Table 5 Input parameters Name Type port unsigned char rx_pin_option unsigned char cmp_level unsigned char rx_ie unsigned char Table 6 Return value unsigned char Value Description 0 Successful function execution 1 Invalid port 2 Invalid comparator reference level 3 Incorrect selection 4 2 Protocol project This project includes a basic protocol with commands based on the ANSI C12 18 including values packet structure and length of commands The protocol is based on data interchange from and to information tables These tables have properties that allow partial or complete read and write operations The project includes four tables of data three located in RAM which lose their value if the system is restarted or powered off and one located in flash to conserve its value even if the system is powered off or restarted Using the MCF51EM Family for Infrared Communication Rev 0 10 Freescale Semiconductor Software As stated the protocol is based on the ANSI C12 18 command structure In this application note these are the services commands that are implemented 1 Full read Reads a complete data table 2 Offset read Reads a portion of a table specifying the offset to be added to the table
21. ception interrupt of the IR port is disabled to avoid receiving data to be transmitted if the signal is reflected Using the MCF51EM Family for Infrared Communication Rev 0 4 Freescale Semiconductor Software 3 The transmission complete interrupt on the IR port is set to enable the reception interrupt on the IR port when data has been completely transmitted 4 Finally the data is transmitted by the IR port When a character is received on the IR port the data is taken from the reception register and is transmitted by the wired port Flowcharts of the main function and of the interrupts of this project are shown below NOTE RTI indicates a return from interrupt main Set system clock to 48 MHZ and disable watchdog y Infrared port initialization and reception interrupt enabled o Y Wired port initialization and reception interrupt enabled y Endless loop Figure 3 Flowchart of main function of BridgelR project Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 5 Software Reception interrupt on wired port Received data sent to temporal variable l Clear interrupt flag Disable reception interrupt of infrared port Enable transmit complete interrupt of infrared port r Temporal variable transmitted by infrared port RTI Using the MCF5
22. cessful response NOK NOK is a one byte response that indicates that the command was not supported or contains an error Its y p pp value is 01 Table 10 Packet Example Offset Write Command Request Response lt command gt 4F lt tablelD gt 0002 lt offset gt 000000 lt octet count gt 0020 lt checksum gt 76 lt data gt 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 If communication is unsuccessful lt NOK gt 01 If communication is successful lt OK gt 00 For more information about the protocol refer to the ANSI C12 18 and ANSI C12 19 specifications Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 15 Software 4 2 2 Software Architecture Reception interrupt of the SCI stores received data in a buffer If a command start is received RX_ status variable indicates COMMAND RECEIVING if the command end is received RX status indicates COMMAND RECEIVED Command received flag is read to know when a command has been received completely to allow the buffer conversion into hexadecimal format and analyze command that was received Depending on the command the program jumps to execute a specific function for each command to perform the required task The function returns an error if the command is wrong or contains incorrect information After the response is sent
23. d LED4 blinks when the command is received and a response is sent Press switch 1 to jump to the next task Press switch 1 to jump to vfnTSK_show_change_ br task The flow charts of the main and interrupt sections of this project are shown in Figure 11 Using the MCF51EM Family for Infrared Communication Rev 0 28 Freescale Semiconductor Hardware tests main Disable watchdog y Initialize timers MTIM RTC TPM y Initialize GPIOs LCD flash y Initialize and configure SCls a ae Next task Welcome y Enable global interrupts Do next task Figure 11 Flowchart of main function of EM256DemolR project 5 Hardware tests The tests discussed in this section show results and measurements done on DEMOEM and highlight the features of the MCF51EM256 used for infrared communication such as the use of 2x drive strength reception through the analog comparator the possibility of generating a modulating signal using timers plus the implementation of the provided communication protocol Figure 2 shows the switches and jumpers mentioned in the tests A brief description of each test is given below e Test 1 Drive strength and analog comparator functions Transmission on infrared port with 2x drive strength and infrared reception with SCI RX input connected through analog comparator e Test 2 High frequency modulation High frequency modulation 38 kHz using 2x dri
24. d code lines are customizable Blue lines are an example of how to add a new table l Customize SCI module and baud rate used for communication a Open the file com_protocol h b Locate this line at the beginning of the file RRKKK KKK DEFINES THE SCI PORT USED AND BAUDRATE xk xxx define USED PORT 1 selects the port used for communication define BAUDRATE 4800 300 600 1200 2400 4800 9600 max c Write the number of the SCI module you want to use only 1 2 or 3 d Locate this line RK KK KKK DEFINES THE SCI PORT USED AND BAUDRATE eka define USED PORT 1 selects the port used for communication define BAUDRATE 4800 300 600 1200 2400 4800 9600 max e Write the value of the baud rate bps you want to use only the values shown in the comment are valid Customize reference level used by the analog comparator a Open the file com_protocol h b Locate this line define RE Hy ERENCE LEVEL 27 Reference voltage used by the comparator define IR ACTIVE 1 1 TX INVERTED reference level used 0 TX NORMAL reference level ignored Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 19 Software c Write the value of the reference you want to use The minimum is 0 and the maximum is 31 recommended values are 26 to 30 3 Enable or disa
25. d port initialization and settings Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 25 Software e infrared h e infrared c For ASCII interface used by terminal e ascii h e ascii c For flash initialization and erase and write functions e flash h e flash c For SCI functions such as message transmission and others e sci h e SCi c In addition the line shown here must be added in your main initialization to configure the flash properties allowing erase and write operations void main void SOPT1 COPT 0 Turn off Watchdog Timer FlashInit Configures the Flash clock for erase and program operations Also depending on the application initialization and configuration lines for SCI modules could need to be included In the EM256DemolR project these lines are inserted if u8SCI_init USED PORT 300 DATA LENGTH EIGTH PARITY NONE IR _ACTIVE 1 RX NOT INVERTED for if u8IR_TX init USED PORT TX PIN OPTION DEFAULT DRIVE STRENGTH DISABLED MODULATION DISABLED TX INTERRUPT DISABLED for if u8IR_RX init USED PORT RX PIN OPTION DEFAULT REFERENCE LEVEL IR ACTIVE RX INTERRUPT ENABLED for 4 3 2 Software Architecture This software is a task scheduler and each task does a different function The task initialization prototypes are
26. e sence re caaasevaes 10 4 3 EM256DemolR projec icc seccee ieee tawnes 25 FIAROWare tesis is ade ad t rantos ENSAFRANA aang 29 5 1 Test considerations s lt 02 e 004e0eeeaaes 30 5 2 Test 1 Drive strength and analog comparator func MCS icc Sie abuse th x te rie vide atin Bok be mA TE ae ch NS gS 30 5 3 Test 2 High frequency modulation 33 5 4 Test 3 Pulse stretcher modulation 34 5 5 Test 4 Protocol implementation 34 Considerations and references 2 37 CCONGMISION 6 25454 dcdetund So betas be hot daa See 38 2 freescale semiconductor Basic information e Section 5 Hardware tests shows several tests done on the DEMOEM board e Finally Section 6 Considerations and references and Section 7 Conclusion include some considerations and concluding information for the entire application note 2 Basic information Infrared is the basis for a type of optical communication that allows complete isolation between electric or electronic devices because the communication channel is only light and has no electrical connections Using it for communication in metering applications is valuable because doing so avoids the handling of high voltages which can be dangerous for people or for other devices The features that take advantage of the specific hardware configuration inside the MCF51EM microcontroller unit MCU are these e Output driving Tr
27. in systems intended for surgical implant into the body or other applications intended to support or sustain life or for any other application in which the failure of the Freescale Semiconductor product could create a situation where personal injury or death may occur Should Buyer purchase or use Freescale Semiconductor products for any such unintended or unauthorized application Buyer shall indemnify and hold Freescale Semiconductor and its officers employees subsidiaries affiliates and distributors harmless against all claims costs damages and expenses and reasonable attorney fees arising out of directly or indirectly any claim of personal injury or death associated with such unintended or unauthorized use even if such claim alleges that Freescale Semiconductor was negligent regarding the design or manufacture of the part RoHS compliant and or Pb free versions of Freescale products have the functionality and electrical characteristics as their non RoHS compliant and or non Pb free counterparts For further information see http www freescale com or contact your Freescale sales representative For information on Freescale s Environmental Products program go to http www freescale com epp Freescale and the Freescale logo are trademarks of Freescale Semiconductor Inc All other product or service names are the property of their respective owners Freescale Semiconductor Inc 2009 All rights reserved lt p 2 freesca
28. l port SCI1 PRACMP 1 without feedback resistor e Transmitted data 0x41 e Drive strength enabled e Distance is taken from board edges with 6 mm acrylic between boards and transmitter aligned with receiver e Light conditions indoor fluorescent lamps and without optical filter e Comparator reference is 28 Table 11 summarizes the results of the test at different baud rates and distances Figure 12 is a schematic of the hardware used in the test 1 DEMOEM board is originally populated with R13 15 kQ resistor Using the MCF51EM Family for Infrared Communication Rev 0 30 Freescale Semiconductor Hardware tests Table 11 Test 1 results Distance Baud Rate Successful Notes cm bps Communication o 300 Yes Figure 13 o 600 Yes o 1200 Yes o 2400 Yes Figure 14 o 4800 Yes o 9600 Yes Figure 15 1 8 300 Yes Figure 16 1 8 600 Yes 1 8 1200 Yes Figure 17 1 8 2400 Yes 1 8 4800 Yes 1 8 9600 Yes Figure 18 1 The distance between IR transmitter and receiver plus the thickness of the acrylic is 1 5 cm VDD R13 1 5 kQ eat x QTLP610CPD Analog comparator R15 output AAA _ 1 MQ To SCI RX R12 kd gt 1 kQ C50 0 1 uF T1 From SCI TX a R14 gt l NVV 33 0 QTLP610CIR Figure 12 Connection of IR transmitter and receiver with feedback resistor Figure 13 through figure 18 are screen captures of the oscilloscope
29. le semiconductor
30. lt OK gt 00 lt octet count gt 0020 lt data gt 10 1112131415161718191A1B1C1D 1E 1F 20 21 22 23 24 25 26 27 28 29 2A 2B 2C 2D 2E 2F lt checksum gt 10 4 2 1 2 Offset Read Command Request start end gt 3F tablelD offset element count CR Using the MCF51EM Family for Infrared Communication Rev 0 12 Freescale Semiconductor Element Description gt Indicates that a command starts 3F One byte command code for Offset Read tablelD Two byte identifier for each table offset Three byte field that indicates the offset to be applied to the table to read sections of information element count Two byte field that indicates how many bytes will Successful response be read CR Carriage return indicates command termination OK element count data checksum Element Description OK One byte response that indicates that command was supported and executed Its value is 00 element count Two byte length data that indicates how many bytes will be sent in response to Read command data The read information Its length is defined by element count parameter checksum One byte of data is the two s complement of the result of the addition of all data bytes sent Unsuccessful response NOK Software NOK is a one byte response that indicates that the command was not supported or contains an e
31. mmand a Full Read of Table 2 6 Considerations and references e The user has to be careful when applying customization to the software to avoid conflicts or short circuits Commented text can help to avoid this kind of issue e Recommended baud rates and reference levels help to achieve better results in communication because higher values for the baud rate could corrupt information and greater values of the reference level could cause the signal not to be recognized e Baud rate can be increased if wired communication is used The protocol was tested up to 19200 bps working without problems via wired communication e For more information about SCI ACMP and TPM refer to Freescale document MCF51EM256RM MCF51EM Family ColdFire Integrated Microcontroller Reference Manual available at www freescale com Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 37 Conclusion e The software was developed and tested with CodeWarrior for Coldfire v6 2 1 e Download the tools and source files for AN3938SW zip from www freescale com 7 Conclusion This application note showed the use of specific hardware features of the MCF51EM256 to establish infrared communication The transmission distances shown in Test one were obtained without using any optical protection of infrared elements higher distances can be obtained using infrared optical protection that avoids external light interference The provided p
32. nge br task Press switch 1 to jump immediately e vfnTSK_ show change br Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 27 Software This task sets the baud rate to be used by the application Switch 2 increases the baud rate and switch 3 decreases it This function also enables and disables the high frequency modulation by pressing switch 4 Press switch 1 to jump to vfnTSK_show_ir task vfnTSK_show_ir This task sends and receives characters via the IR port and values are shown on the LCD screen Press switch 2 to increase the data to be sent and switch 4 to reduce it Press and hold switch 3 or switch 4 to send data every 100 milliseconds It also enables and disables the 2x drive strength by pressing switch 4 Press switch 1 to jump to vfnTSK_show_tx_irda task vfnTSK_show_tx_irda This task enables and disables the pulse stretcher modulation by pressing switch 4 If pulse stretcher modulation is enabled the baud rate is forced to 9600 bps and the task used to change baud rate is not available until the pulse stretcher modulation is disabled Press switch 1 to jump to vfnTSK protocol welcome task vfnTSK_protocol_ welcome This task sends the text Protocol through the SCI port displays it on the LCD screen and then immediately jumps to vfnTSK_comm_ protocol task vfnTSK_comm_protocol This task executes the protocol explained previously The LCD screen shows the message Protocol an
33. on called romsymbols Using the MCF51EM Family for Infrared Communication Rev 0 24 Freescale Semiconductor Software pragma section my tables begin UINTS Tablel TABLE1 SIZE here must be the table data pragma section my tables end end of pragma pragma define section my table2 romsymbols2 start of pragma following code will be located in memory section called romsymbols2 pragma section my table2 begin UINT8 newTable newTABLE SIZE here must be data of new table e pragma section my _table2 end end of pragma NOTE Each flash array has reserved flash locations on pages 1 and 2 These registers must not be used to save tables It is recommended to create sections to save nonvolatile tables from page 3 address 0x0020800 on flash array 2 4 3 EM256DemolR project This project consists of the execution of several different tasks and the protocol is included as one of those tasks It also uses the other tasks to implement different hardware tests using modules present in the MCF51EM series such as e LCD driver e RTC timer e SCI and infrared hardware e TPM in PWM mode e Analog comparator e 2x drive strength functions for SCI TX1 and TX2 4 3 1 Including protocol as a task To add the protocol to an application the files to be added are For protocol definition and functions e com_protocol h e com_protocol c For infrare
34. on for a new table add these lines Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 23 Software rom symbols __ROM SYMBOLS start address of the 4x1024 bytes symbols romsymbols gt my table FSL copy during runtime ROM SYMBOLS __ROM SYMBOLS ADDR my_ table rom_symbols2 __ ROM SYMBOLS2 start address of the 4x1024 bytes symbols romsymbols2 gt my _table2 FSL copy during runtime ROM_SYMBOLS2 __ROM_SYMBOLS2 ADDR my_table2 These lines locate the variables type my_tables in the memory section called romsymbols Table 1 is saved here The next steps explain how to do this e Open the file com_protocol c f Locate these lines RRKKKKKKKEKK DECLARATION OF THE NON VOLATILE TABLES kkkKKKK This is used to locate Nonvolatile Tables in Flash memory pragma define section my tables romsymbols start of pragma following code will be located in memory section called romsymbols pragma section my tables begin UINT8 Tablel TABLE1 SIZE here must be the table data e pragma section my tables end end of pragma The pragma must be started and finished after invoking it To add a new flash table a new pragma must be inserted to include its array declaration in this part as shown here pragma define section my tables romsymbols start of pragma following code will be located in memory secti
35. ort must be SCII in demo board Locate this line define BAUDRATE 4800 1200 2400 4800 9600 max Write the value of the baud rate bps you want to use commented values are standard baud rates The max baud rate is limited to 9600 bps to assure signal integrity for the infrared communication 2 Customize reference level used by the analog comparator a b c Open the file main c Locate this line define REFERENCE LEVEL 27 Write the value of the reference you want to use The minimum is 0 and the maximum is 31 recommended values are 26 to 30 where the voltage reference level is VDD x REFERENCE LEVEL 32 3 Enabling or disabling the analog comparator and the 2x drive strength a b c Open the file main c Locate these lines define COMPARATOR USED 1 define DRIVE STRENGTH USED 1 0 disables the function 1 enables the function Write 0 to disable each function or write 1 to enable it NOTE SCI3 does not support input through the analog comparator on the MCFS51EM256 Here are explanations of the functions included in the infrared c file as well as of its input parameters 4 1 3 Function u8SClL init e Description Initializes the SCI modules configuring port baud rate data length parity transmission mode and reception mode Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor Software
36. r of tables c Write the number of tables you want to use For example to add a new table in existing code the code line will be define TABLES NUMBER 5 defines number of tables d Locate these lines to define the size of each table TABLEx SIZE size of the table in bytes define TABLEO SIZE 64 Defines the buffer size of Table 0 electrical measurements define TABLE SIZE 32 Defines the buffer size of Table 1 calibration needs password Using the MCF51EM Family for Infrared Communication Rev 0 20 Freescale Semiconductor define TAB define TAB LE2 SIZE LES SIZE 32 128 Defines the buffer size of Table Defines the buffer size of Table Software 2 3 seetings data logger e Write the size you want for each table If a new table was inserted its size must be defined in this part TABLEx SIZE siz define TABLEO SIZE measurements define TABLE SIZE password define TABLE2 SIZE define TABLE3 SIZE define new TABLE SIZE 16 of the table in bytes 64 Defines the buffer size of Table 0 electrical 32 Defines the buffer size of Table 1 calibration needs 32 Defines the buffer size of Table 2 seetings 128 Defines the buffer size of Table 3 data logger Defines the buffer size of new table
37. rotocol is a portion of the C12 18 Protocol that allows a complete data interchange It also provides bases to allow the user to complete the protocol or customize it to a specific application Using the MCF51EM Family for Infrared Communication Rev 0 38 Freescale Semiconductor THIS PAGE IS INTENTIONALLY BLANK Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 39 How to Reach Us Home Page www freescale com Web Support http www freescale com support USA Europe or Locations Not Listed Freescale Semiconductor Inc Technical Information Center EL516 2100 East Elliot Road Tempe Arizona 85284 1 800 521 6274 or 1 480 768 2130 www freescale com support Europe Middle East and Africa Freescale Halbleiter Deutschland GmbH Technical Information Center Schatzbogen 7 81829 Muenchen Germany 44 1296 380 456 English 46 8 52200080 English 49 89 92103 559 German 33 1 69 35 48 48 French www freescale com support Japan Freescale Semiconductor Japan Ltd Headquarters ARCO Tower 15F 1 8 1 Shimo Meguro Meguro ku Tokyo 153 0064 Japan 0120 191014 or 81 3 5437 9125 support japan freescale com Asia Pacific Freescale Semiconductor China Ltd Exchange Building 23F No 118 Jianguo Road Chaoyang District Beijing 100022 China 86 10 5879 8000 support asia freescale com For Literature Requests Only Freescale Semiconductor Literature Distri
38. rror Its value is 01 Table 8 Packet Example Offset Read Command Request Response lt command gt 3F lt tablelD gt 0002 lt offset gt 000004 lt octet count gt 0010 If communication is unsuccessful lt NOK gt 01 If communication is successful lt OK gt 00 lt octet count gt 0010 lt data gt A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF BO B1 B2 B3 lt checksum gt 48 Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 13 Software 4 2 1 3 Request Full Write Command start end gt 40 tablelD element count data checksum CR Element Description gt Indicates that a command starts 40 One byte command code for Full Write tablelD Two byte identifier for each table element count Two byte field that indicates how many bytes will be written data The information to be written Its length is defined by element count parameter checksum One byte of data is the two s complement of the result of the addition of all data bytes sent CR Carriage return indicates command termination Successful response OK OK is a one byte response that indicates that the command was supported and executed Its value is 00 Unsuccessful response NOK NOK is a one byte response that indicates that the command was not suppo
39. rted or contains an error Its value is 01 4 2 1 4 Request Table 9 Packet Example Full Write Command Request Response lt command gt 40 lt tablelD gt 0001 lt octet count gt 0020 lt data gt A4 A5 A6 A7 A8 A9 AA AB AC AD AE AF BO B1 B2 B3 lt checksum gt CA If communication is unsuccessful lt NOK gt 01 If communication is successful lt OK gt 00 Offset Write Command Using the MCF51EM Family for Infrared Communication Rev 0 14 Freescale Semiconductor start gt 4F tablelD end offset element count data checksum CR Element Description gt Indicates that a command starts 4F One byte command code for Offset Write tablelD Two byte identifier for each table offset Three byte field that indicates the offset to be applied to the table to write sections of information element count Two byte field that indicates how many bytes will be written data The information to be written Its length is defined by element count parameter checksum One byte of data is the two s complement of the result of the addition of all data bytes sent CR Carriage return indicates command termination Successful response OK Software OK is a one byte response that indicates that the command was supported and executed Its value is 00 Unsuc
40. specific command but all packets are terminated with a carriage return CR character ASCII 0x0D NOTE All values are in hexadecimal format 4 2 1 1 Full Read Command Request start end gt 30 tablelD CR Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 11 Software Element Description gt Indicates that a command starts 30 One byte command code for Full Read tablelD Two byte identifier for each table CR Carriage return indicates command termination Successful response OK element count data checksum Element Description OK One byte response that indicates that command was supported and executed Its value is 00 element count Two byte length data that indicates how many bytes will be sent in response to Read command data The read information Its length is defined by element count parameter checksum One byte of data is the two s complement of the result of the addition of all data bytes sent Unsuccessful response NOK NOK is a one byte response that indicates that the command was not supported or contains an error Its value is 01 Table 7 Packet Example Full Read Command Request Response lt command gt 30 If communication is unsuccessful lt tablelD gt 0001 lt NOK gt 01 If communication is successful
41. the array that contains the table and is explained in the next step Fill the rest of the parameters for each table with the parameters that were defined above If a new table was inserted its table descriptor will be added as shown here KKK KKKKKK STRUCT FOR TABLES PROPIE struct Table Description Table lis amp Table0d 0 TABLEO SIZE TABL ld amp Table1 0 TABLE1 SIZE TABL q q amp Table2 0 TAB 1 1 0 1 E2 SIZE TABLE2 1 3 amp Table3 0 TAB E3 SIZE TABLE amp newTable 0 newTABLE SIZ struct Table_Description p_table_ TIES KOK RK KK KK t TABLES NUMBER TYPE TABLEO SECURITY 0 Measurements TYPE TABLE SECURITY 1 Calibration YP TABLE2 SECURITY 2 Settings TYPE TABLE3 SECURITY 3 Data logger TABLE TYPE newIABLE SECURITY 4 New list 6 Generate the tables that will be located in RAM a The previous lines explain how to define table properties and its descriptor but the table was not yet created Tables are an array of variables and if they are located in RAM open the file com_protocol c and locate these lines J OOOO eke DECLARATION OF THE VOLATILE TABL ES KAAKAA KKKKKKK UINT8 Table0 TAB UINT8 Table2 TAB UINT8 Table3 TAB EO SIZE E2 SIZE E3 SIZE
42. ve strength Modulated signal is generated by timer TPM e Test 3 Pulse stretcher modulation Using the MCF51EM Family for Infrared Communication Rev 0 Freescale Semiconductor 29 Hardware tests Timer TPM generates a PWM signal to modulate SCI transmission in pulse stretcher mode e Test 4 Protocol Implementation Implementation of the communication protocol showing screen captures of the request and response codes received and sent by the PC 5 1 Test considerations Tests one two and three are implemented using the EM256DemoIR project and these hardware considerations e VDD 3 3V Ry3 1 5 KQ and Ry is 33 Q Test four is implemented using the BridgeIR project on one DEMOEM board and the protocol project on the other DEMOEM board To do these tests these jumper configurations on DEMOEM must be used e J16 populated for PTEO PTB2 and PTB3 e J7 and J8 connecting pin 1 and pin 2 e J9 and J10 connecting pin 2 and pin 3 For more information about jumper settings or other hardware issues concerning the demo board refer to document DEMOEMUM DEMOEM User Manual available at www pemicro com and or schematic 5 2 Test 1 Drive strength and analog comparator functions This test shows the behavior at different baud rates of a transmission signal using 2x drive strength with reception using an analog comparator and the relation of this behavior to distance of communication Here are the conditions for this test e Seria

Download Pdf Manuals

image

Related Search

Related Contents

User Manual - IRT Communications  XtremeMac Luna Voyager II  allgemeine betriebserlaubnis gasdruckunterstützte  

Copyright © All rights reserved.
Failed to retrieve file