Home

ECE 395 Lab Manual - Research Centers and Specialized Labs

image

Contents

1. inputs in a pull up resistor configuration with one side of the switch to the GPIO and the other side to ground 2 Select the GPIO s to be used as the outputs Avoid the GPIO s assigned to the on board LED On the solderless breadboard wire the 3 outputs to the anode s of the red yellow and green LED s Tie the cathodes of the LED to ground though 200 ohm resistors 3 Modify the gpio_init routine from lab 2 to setup the GPIO inputs and outputs appropriately 4 Add code to handle the states of the Annunciator state machine 5 Test and debug the code 6 After fully testing the program demonstrate it to the course instructor for credit 3 4 Lab 4 UART Serial Port Lab Objectives e To learn how to setup and operate the MCU serial ports e To create portable functions for serial port initialization and write and read operations e To learn how to use an oscilloscope to observe a serial waveform e One lab report is required from group Background Serial communications is a fundamental principal for microprocessor systems In serial communications data is transferred sequentially bit by bit along a channel in contrast to parallel communications where multiple bits are sent Simultaneously over multiple channels In modern digital systems there are various protocols which employ serial transmission techniques that are aimed at a variety of applications Some common examples are USB Universal Serial Bus which is co
2. change value PUSH R1 R2 Save Rl and R2 to stack LDR RI RO Get value from memory ADD R1 1 Increment EORS R1 RO XOR with address MOVS R2 0xFF Set mask ANDS R1 R2 Mask STR R1 RO Save value back to memory POP R1 R2 Restore R1 and R2 BX LR Return Put constants here AREA data area DATA READWRITE gt Put variables here valuel DE ACE 4 valuez2 SPACE 4 END Figure 12 Code for Lab 1 Part 5 Page 19 3 2 Lab 2 General Purpose Inputs and Outputs Lab Objectives e To learn how to configure the MCU internal peripherals e To learn how to setup and operate the GPIO pins of the MCU Background When creating a design using a processor it is common to need inputs or outputs that operate in a binary on off fashion These signals are used for monitoring user inputs switches or pushbuttons driving indicators lights or audible controlling actuators monitoring driving discrete control lines from to other circuits in the design or for a variety of other purposes Microcontrollers typical will have pins that can be configured as either outputs that can be driven by or inputs that can be monitored by the processor These signals are commonly refer to as general purpose inputs and outputs GPIO s The FRDM KL25Z board provides 53 pins which can be used for assigned peripheral special functions e g UART IO DAC outputs ADC inputs etc If a specific peripheral which is tied to a given pin is
3. Step 3 Navigate to Project gt gt Open Project Then open the file called ece395 uvproj Step 4 In the project open the file main c Page 10 File Edit View Project Flash Debug Peripherals Tools SVCS Window Help 1S s selec Ho ER AR SS main Ee EENE ALS 5 1 C PE Micro Ram include lt MKL25Z4 H gt Ey System Code 7 SEA startup_MKL25Z4 s extern void asm main void Le E system _MKL25Z4 c 3 User Code int main void Eo eee i asm_main uncomment to use assembly i E asm_main s while 1 Pemicro OSJtag Multilink Qn Figure 5 Default project file main c Ed Causersiahsi Docum F s E 39 KL25 p ajecteces 95 uvproj Vision po ehh x n File Edit Wiew Project Flash Debug Peripherals Tools SVCS Window Help N a 4 alee eo BAR FE min Har ajo osen SE Ae AS ow Project iz of P main c a in C PE Micro Ram S System Code AREA asm area CODE READONLY FE startup_MKL2574 s5 EXPORT asm main system _MKL25Z4 c l l SES ller Code asm main assembly entry point for C function do not delete k Add program code here 4 main c Ray asm Eil m_main s b asm main AREA data area DATA READWRITE Put variables here eo Fu OyTe Build Output 4 Pemicro OSJtag Multilink Qn 3 Figure 6 Default project file asm_main s Page 11 Step 5 If this is a pr
4. Choose MBCDEFGHIIKLMMOPORSTUV SY Fase abedetghijkimnoparstuywayz BIT 0123456789 a 1OesH a Insert COL PL PF eos LCT CaS Preset scrolls through characters CLE Faon Display Enter Back Delete Labels Character space On Off Figure 33 Apply a label Page 46 Titer ous Display Hex Binary i ASC THETA E 00 us l FEEN 10 Hz Bus B Define Configure ABI Label Ass Inputs Thresholds JENN ESN Ti Bus Display Event Table Figure 34 Select how to view the characters Tek Trig i l NoiseFilter Off MME or If lt 10 He 42 06 Figure 35 The end result 0x65 ASCII e Store the waveform for the lab report Capture the waveforms for the configurations listed in Figure 36 for the lab report Page 47 ASCII Character Baud Rate Data Bits Stop Bits Last name initial of 115200 None report author Figure 36 Capture Waveform Settings 3 4 3 Lab 4 Lab report For the lab report on this lab be sure to include A description of how the lab was performed For Part 1 observed results and answers to two highlighted questions For Part 2 eight waveforms manual identification and serial decode of the four settings listed On the manual identification of the serial waveforms identify e the voltage levels for high and low e bit time e start bit data bits O thru 7 stop bit e data bit values 0 1 e match the data bits to the ASCII character value Also i
5. Development Platform for Kinetis KL14 15 24 25 MCUs aka FRDM KL25Z or KL25Z The KL25Z provides low cost less than 15 platform to explore microprocessor principles The KL25Z features e Kinetis L MCU MKL25Z128VLK4 O O O O O ARM Cortex M0 core up to48MHz CPU speed 128kB FLASH 16kB SRAM DMA UART 2 SPI 2 I C 12 bit DAC 16 bit ADC up to 24 inputs USB 2 0 OTG Host Device e Capacitive touch slider e MMA8451Q accelerometer I C e Tri color RGB LED e USB coin cell battery external source power supply options e I O via Arduino compatible I O connectors 53 I O s available e Programmable OpenSDA debug interface The FRDM KL25Z does not come with headers installed for accessing the board IO Headers need to be solderd to the board to gain acces to the IO for some of the experiments in this course Recommended headers are available from Digikey are Quantity 1 2 1 Part Description S6106 ND Female thru hole 20 Pin dual row 0 1 pitch 8 5mm high S 7111 ND Female thru hole 16 Pin dual row 0 1 pitch 8 5mm high S7109 ND Female thru hole 16 Pin dual row 0 1 pitch 8 5mm high Page 6 Be i USB KLZ 521 mU J6 38 Ee 2 AHH 38 35 Reset a 10 Qui E A RO po eR Yi a e ve p13 D6 omy T i ita 1S axe cat Be E R20 i if SS oR YZ Figure 1 FRDM KL25Z with headers installed Several software development tool sets support this processo
6. For inputs the pull resistors should be enabled and set appropriately based on the geometry if the circuit driving the input See Figure 14 vob Pull Push Button f i S Input Buffer i i D f Button i i sd Push Figure 14 Pull Resistor Configurations 3 Each Port has a data direction register GPIOx_PDDR where x it the port which configures whether a pin will be an input or output All 32 bits for the port are grouped in the single register See section 41 2 6 of the KL25 Sub Family Reference Manual for details on how to set the GPIOx_PDDR register After configuration if the GPIO has been configured as an input the state of the pin can be read using the GPIOx_PDIR register All 32 bits for the port are grouped in the single register See section 41 2 5 of the KL25 Sub Family Reference Manual for details on how to use the GPIOx_PDIR registers Otherwise if the GPIO has been configured as an output the state of pin can be controlled with several registers All 32 bits for the port are grouped in each single register Writing a 1 or O to a given bit in GPIOx_PDOR sets or clears the output based on the value in each bit Note that using this register requires setting all the pins on the port simultaneously as each of the 32 bits must have a value of 1 or 0 Using the GPIOx_PSOR and GPIOx_PCOR registers allows pins to be respectively set or cleared individually by writing a 1 to the desired bit
7. LR BNDEUNC UARTOInit FUNCTION SIM SOPTZ UARTOORG O16 MCGELLCLK of MCGPLLCLK Z Clock and SIM SOPT2 PLEPLESE I 1b for MGCPLLCLK 2 LDR RO SIM SOPLZ Load address Of SIM SOPI To RO LDR Ris RO PUC prescht Valus oT SIM SOPIT ANTO R1 LDR R2 0xF3FEFFFF Load bits to clear ANDS R1 R2 AND values to clear bits LDR R2 0x04010000 Load bits to set ORRS Jc RZ OR Values EO Set bits STR R1 RO PUE valus Dack INTO SIM SORTZ SIM SCGC4 UARTO 1 LDR RO SIM SCGC4 LDR R1 RO LDR R2 O0x00000400 ORRS R1 R2 STR R1 RO e DAM SCG LORIE einem AT Ly t r ony Cock Tor all ports LDR RO IMS CGCo FLOad AddreSS lt Or SIM CGC TO RU LDR R1 RO PUL Waele OL OIM Cel MEO Fil GOR R2 0x0000SE00 7 hoad value to turn On aLi port SCLOCKS into RZ ORRO Rig RZ POR RZ Tne zRul STR R1 R0 PUC Value back Into SIM SCGE5 2 r PORTA PCR y Clear Irom ane ser MUX LOR RO PORTA PCr LDR R1 RO LDR RZ 0x01000200 ORRS R1 R2 STR R1 RO Il NO A PORTA PERZ y Clear car and seu MUx EDR KRO PORTA PCRZ LDR R1 RO LDR R2Z 0x01000200 ORRS R1 R2 STR R1 RO Page 37 UARTO Cea lOoR 0R07 Lor osr LDR ROQ UARTO C4 MOVS R1 0x07 STRB R1 RO 9600 baud uart0 baud clk MGCPLLCLK 2 96MHz 2 48MHz SBR uartO baud clk baud osr SBR 48MHz 9600 8 SBR 625 0x027 1 UARTO BDH 0x02 LDR ROQ UARTO BDH MOVS R1 0x02 STRB R1 RO UARTO BDL 0x71 LDR
8. into PORTB_PCR18 directly writes the new value into the register This is ok here because the whole register only impacts the behavior of the concerned pin Follow these methods to set the remaining registers 3 Add code in the asm_main loop to e Read status of push button o Use the GPIOx_PDIR register for the input port to read the inputs o The appropriate bit can be masked then compared to test if it iS pressed e If pressed set LED to color 1 clear color 2 o Use the GPIOx_PSOR register to set the appropriate pin to turn off the one LED color Page 24 o Use the GPIOx_PCOR register to clear the appropriate pin to turn on the other LED color e Else set LED to color 2 clear color 1 o Do the opposite of the previous step 4 To test the program build the code and start a debug session The system registers can be viewed by selecting Peripherals gt gt System Viewer gt gt gt Register Group For this lab register groups SIM PORTB PORTD GPIOB and GPIOD should be selected The values of the registers should be observed as the program executes ash show in Figure 15 File Edit View Project Flash Debug Peripherals Tools SVCS Window Help i n a s aBl9cles PARR F FER _ hare seats G O 8 600 gt Aee 0a a a m e Registers q Disassembly Ox1FFFF522 6001 5TR ri r0 0x00 Ec LDR RO PORTB PCR18 Fb RO 040048038 eee Be ee Ox1FFFFS26 4910 ji T eii 64 Ox1FFFF568 aus pone 00001400 j RIKERUHA E E SOPTIC
9. not used in a design the pin is available for use as a GPIO When selecting pins to use as a GPIO it is important to avoid pins that are assigned to a special function that will also be used in the design For example if the DAC was to be used ina design pins associated with the DAC functions could not be used as GPIO For the KL25Z128VLK4 processor used on the KL25Z section 10 3 1 of the KL25 Sub Family Reference Manual lists a table showing how pins are mapped to functions The table lists up to 8 ALT options for any given pin It can be seen that certain pins can have multiple functions mapped to it If the function is set to ALT1 it is configured to be a GPIO Pins are grouped into 5 ports labeled A though E The architecture allows for ports to have up to 32 bits but some ports have less than 32 bits due to limitations on the number of pins available in the device package Pins are numbered O to 31 Figure 13 shows how the port pins are mapped to the headers on the FRDM KL52Z For example PTA1 is Port A Pin 1 Page 20 PTA2 4 2 113 PTCO PTD4 6 CE5 PTC3 PTA12 8 CE PTA4 10 CE PTCS PTAS 12 OXJ PTC6 PTC8 14 CX i13 PTC10 PICO 16 CKD 15 PTC11 PTAI3 2 BAUM PTCI2 PTDS ALAJ PTC13 PTDO 6 RAS PTC16 PTD2 8 Kd PTCI7 PTD3 10 Lao PTA16 PTDI 12 R PTAI7 GND 14 33113 PTE31 VREFH 16 PTEO 18 R i7 PTDG PTE1 20 PTD7 PTE30 11 PTE29
10. share in smart phones and appliances and are constantly growing in the embedded arena Because of ARM s current and anticipated future market standing it is an attractive architecture to use as a learning platform to explore microprocessors behaviors and their use All processors fundamentally run architecture specific machine languages to operate Writing programs directly in machine language is rarely done so assembly languages are used to provide a more human friendly way to generate machine language When higher level languages are complied or interpreted machine language is generated to runs on the processor In industry microprocessors are usually programmed in higher level languages for a variety of reasons including speeding development time code portability etc The language used varies depending on the application C is commonly used for embedded systems operating systems and device drivers Both C and C are used for applications along with languages such as Java C Python where higher capability operating systems are used In order to truly understand how microprocessors operate observing and manipulating the behavior of the processor at the machine language level is necessary Because of this a large part of this course focuses on development using assembly language Later labs do introduce the use of C to allow for more complicated programs and to see how higher level languages are translated into machine language Pa
11. status to the operator in the monitoring room The system has two objectives to notify the operator when the tank is near full so they can manually turn off the fill valve then to notify the operator when the tank has over flown so they can be sent to clean it up eS Annunciator Figure 17 Annunciator System There are 4 input to the system There are two level switches in the tank full level alarm FLA and overflow level alarm OLA On the Annunciator box in the control room there are two momentary push buttons acknowledge ACK and test TST On the Annunciator box there are 3 outputs from the system a green ok indicator a yellow full indicator and a red overflow indicator The system has 6 states as shown in Figure 18 Page 27 GRN FLYEL ACK FLA OLA YEL TST FLA FLRED RED Figure 18 Annunciator State Diagram Required Equipment and Parts Solderless breadboard 2 Pushbuttons 1 DIP switch 1 Red LED 1 Yellow LED 1 Green LED 3 220 ohm resistors Jumper wires Procedure Use the knowledge gained in lab 2 to configure the GPIO s to monitor the four inputs and control the three outputs Write software to implement the state machine for the annunciator system 1 Select the GPIO s to be used for the inputs Avoid the GPIO s assigned to the on board LED On the solderless breadboard wire the 2 pushbuttons and 2 of the DIP stitches to the 4 GPIO s selected as the Page 28
12. the USB cable from the KL25Z In Windows Explorer the drive should now be labeled FRDM KL25Z Proper installation can be verified by opening the file SDA_INFO HTM in the FRDM KL25Z and verifying the application version matches that of the firmware file listed in Step 6 e A ath Cer Ge oO GO Computer FRDM KL25Z H A el i o Organize Print Burn Open New folder Search FRDM KL25Z H Of d w Favorites Name E Desktop p Downloads ER i i Recent Places _ FSLWEB HTM _ LASTSTAT TXT L SDA_INFO HTM SERCDC89 CAT SERCDC89 INF _ TOOLS HTM d SPRUCE on GSSO com Work X 4 9 Libraries b B Documents S s T a FSL_WEB HTM Firefox HTML Document Date modified 8 8 2012 10 58 PM Size 512 bytes WH Date modified Type 8 8 2012 10 58 PM 8 8 2012 10 58 PM 8 8 2012 10 58 PM 8 8 2012 10 58 PM 8 8 2012 10 58 PM 8 6 2012 10 58 PM Firefox HTML C Text Documen Firefox HTML Security Catalo Setup Informat Firefox HTML Date created 4 18 2008 9 20 AM Figure 3 FRDM KL25Z drive Page 9 2 3 Developing With the Course Project File This section describes how to use the customized course project file with the KEIL tools This project file allows for both ASM and C programs targeted towards the KL25Z The project only supports the PE Micro OpenSDA driver and only supports loading code into RAM For each experiment it is HIGLY RECOMMEND
13. tools and software project used in the labs This process only needs to be done once initially on a new board or if there are problems connecting to the board Step 1 From PE Micro website registration required download and extract the OpenSDA Firmware http www pemicro com opensda Step 2 Connect the USB B end of a USB B to USB Mini cable to the development PC Step 3 While holding the RST button on the KL25Z connect the USB Mini connector of the USB cable to the connector labeled SDA on the KL25Z Step 4 Release the RST button The D4 LED should flash green Step 5 In Windows Explorer open the drive labeled BOOTLOADER Page 8 E jel Computer BOOTLOADER Ht gt 4 Search BOOTLOADER H P p Organize Share with Burn New folder Name al ait FSL_WEB HTM FSL_WEB E LASTSTAT TXT _ SDA_INFO HTM __ TOOLS HTM jE Computer amp OS C coy DATAPARTI D c READER E EB sD G we BOOTLOADER Hz _ ca Local Disk X Siu Network 4 items 7 Date modified 8 8 2012 10 58 PM 8 8 2012 10 58 PM 8 8 2012 10 58 PM 8 8 2012 10 58 PM Type Firefox HTML Doc Text Document Firefox HTML Doc Firefox HTML Doc Figure 2 BOOTLOADER drive Step 6 From the files extracted in Step 1 copy the firmware file MSD DEBUG FRDM KL25Z_ Pemicro_v114 SDA to the BOOTLOADER drive Step 7 Step 8 Disconnect and reconnect
14. 32 4807 LDR r0 pc 28 0x20000450 ess RG r0 const val oo RY RIO 6asm main assembly entry point for C function do not delete mas Ril 7 Add program code here om AZ 8 A R13 SP pe 9 LDR RO const val i a 14 LR Ox2000036 7 10 LDR RO const val ge R15 PC Ok 0000430 TI LDRH R0 const val 12 LDRE RO const_ val 13 i4 LDR RO equate val 15 116 LDR Ri const_val 17 STR RO R1 18 19 MOV R2 RO 20 MOVS R1 R4 El Project Registers Command eee Restricted Version with 32768 Byte Code Size Limi wew Currently used 1164 Bytes 3 BE AD DE OD 00 00 00 00 gt oe ea ASSIGN BreakDisable BreakEnable BreakKill BreakList ga Call Stack Locals E Memory 1 EEE Det Figure 7 Debug window Page 14 Part 1 This step demonstrates the basics of memory access and moving data within the processor Add the code shown in Figure 8 to the asm_main s file equate val EQU OQx8BADFOOD AREA asm area CODE READONLY EXPORT asm main asm Malm 7 assemoly entry point Tor function do not delete Add program code here LDR RO conse val Egad address to RU LDR RigConsc val Load word 32 bit from memory LDR R1 R0 GDRH R1ICRO J load half word 16 bit from mem LDRB R1 RO load byte 8 bit from memory LDR RO equatle Val p load Value Tto RO LDR Rly COnSse wa Load AGOTrSs Ss Lo Ri STR RO R1 load value in RO to memory at Rl MOV Ra pO PCODY RO TO RZ M
15. 9 PTE23 7 PTE22 5 PTE21 3 PTE20 1f PTES 15 3 PTE4 13 PTE3 11 PTE2 9 fy PTBI1 7 fy PTB10 5 pTBo 3 pTBs 1 EK YJ prc PTT 10 PTC2 116 P5 9V_VIN 14 GND 12 GND 4410 P5V_USB 4 P3V3 f2 SDA_PTOS Figure 13 Header Pin Assignments from the FRDM KL25Z User Manual Once a GPIO is selected several registers must be properly configured in the processor to allow it to be used as an input or output 1 Each Port has a separate clock gate that must be enabled if IO associated with the Port will be used The SIM_SCGC5 register contains the controls for the Port clock gates See section 12 2 9 of the KL25 Sub Family Reference Manual for details on how to enable the clock gates using the SIM_SCG5 register 2 Each pin has a pin control register PORTx_PCRn where x is the the Port and n is the Pin that is used to configure the pin behavior There are setting fields for the ALT option interrupt operation drive strength slew rate and pull up down resistor configuration See section 11 5 1 of the KL25 Sub Family Reference Manual for details on how to set the PORTx_PCRn registers Page 21 For this lab for the pins used as GPIO s the ALT option will be set to ALT1 interrupts will be disabled the drive strengths should be set to normal the slew rate should be set to slow and the passive filter Should be disabled For outputs the pull resistors will be disabled
16. ECE 395 Microprocessor Laboratory Department of Electrical and Computer Engineering New Jersey Institute of Technology Newark NJ Revision 3 05 March 26 2014 Revised by David Harrison 2014 New Jersey Institute of technology All rights reserved Page 1 Preface 2014 Course UpGal Quis vicviduatdduwesesd raat eedsiawtateaeewsineieanens 3 L SUVGH O GIG TIO liane cece racacaneaeuacan aadee cect cane steutane aeanisects cecee erecta 4 1 1 Course Objectives ccsccvsesvenduscasseeasackPaaneerssiatenoneiasaceeiaaanaes 5 12 REGENCE S oioiioiiiaia a aa 5 2 Microprocessor Experiment PlatforM sssssssssssrsrrsrsrenrerrsrensns 6 2 1 Initial Tool StU cc cccc cen eesecneececceceeuceseuueuueeseugeurenseuae 7 22 DOA SCUD essien vananewenday paces Oaa 8 2 3 Developing With the Course Project File ccceeceeeee eens 10 I JE XDen CM esuscacarsaneccsecesesieechnesiasaranabeiiinacvacsbenieaiaeasearusaaeeees 13 3 1 Lab 1 Microprocessor OperatiOn ccccccseeeeeeeeeeeeeeeeesenes 13 3 2 Lab 2 General Purpose Inputs and Outputs cseeeees 20 3 3 Lab 3 Annunciator GPIO Application ccccesseeeeeeeeeaaes 27 34 Lab 4s UART SerlaliPO mM cscicitiseden stan cdenidi se ENEE 29 3 5 Lab 5 Calculator UART Application cccccccseeeseseueeeenees 48 3 6 Lab 6 Digital to Analog COnVerter ccccee cece ee eeeeeee eee nees 48 3 7 Lab 7 Analog to Digital Converter ccccceee
17. ED that you start a new project in a new directory Step 1 Download from the course website the latest version of ECE395_ ML25Z Project_ zip where is the version number of the latest version and extract it to your working directory Organize Share with Libraries Documents a Music E Pictures E Videos PF Homegroup jl Computer amp OS C ca DATAPARTL D cy READER E AB sD G CD Drive H U3 Syst a SANDISK E a FRDM KL25Z J cow Local Disk X tu Network J 14 items 4 Burn New folder Documents library ECE395 KL25 Project ra Name asm_main s Dbg_RAM ini _ ece395 uvopt eces95 uvproj _ ece395_C PE Micro Ram dep _ ExtDIl tex E kl25z plg ap kl25z sct E main c pemicro_connection_settings ini startup_MKL2574 s system_MKL2574 c _ system_mkl25z4 crf __ Systemlnit s Date modified 1 12 2014 10 51 PM 12 31 2013 11 16 PM 1 12 2014 10 48 PM 014 10 48 PM 2014 10 52 PM 7 12 2014 10 44 PM 2014 10 51 PM 1 12 2014 9 58 PM 1 12 2014 10 53 PM 1 12 2014 10 44 PM 6 24 2013 10 32 AM 6 24 2013 10 44 AM 1 12 2014 10 48 PM 12 27 2013 10 41 PM Type S File Configuration setti UVOPT File uVision4 Project DEP File IEX File PLG File Windows Script Co C File Configuration setti S File C File CRF File S File Figure 4 Files in default project Step 2 Start KEIL uVision4 Arrange by
18. FG La 47 STR R1 R0 i R 000000000 Dod an SOPT2 1 bow Fg OxiFFFFSC8 5 RB OxIFFFFSC8 SOPT4 bho RE Oxo0000000 sm mains 2 mainc SOPTS i o poR7 Ox FFFF5SA7 4 SOPT7 RS Ox4FA2FB5A b loop bm RIO 0x1 FFFFBCE a Sees RA Ox 1FFFF5C8 anit pa i SCGCS 0x00001780 PoP RI2 OxDDAEAFF7 LDR RO SIM SCGC5 Load address of SIM SCGCS to RO LPTMR 0 0 Access disabled RIB SP OxFFFFFFFC LDR Ri R0 Put value of SIM_SCGC5 into R1 TSI et Ae ace be R14 LR Ox IFFFFS19 LDR R2 0x00001900 Load value to be OR d into R2 Se SSS PSE i ORRS R1 R2 JOR R2 into R1 eee STR Ri RO Put value back into SIM SCGC5 PORTB 1 1 Clock enabled PORTC 0 0 Clock disabled LDR RO PORTB PCR18 PORTD 1 1 Clock enabled LDR R1 0x00000100 r r a A Thread STR R1 R0 PORTE 0 0 Clock disabled Privileged SCGC6 MSP LDR RO PORTB PCR19 SCGC7 LDR R1 0x00000100 E CLKDN1 SA MAr EBA m FOFGL LDR RO PORTD PCR1 E FCFG2 LDR R1 0x00000100 f UIDMH STR Ri RO IT AL Bs nacnnnnn SCGC5 LDR RO GPIOB PDDR Bits 31 0 RW 0240048038 System Clock Gating Control Register 5 LDR R1 RO s LDR R2 0x000C0000 System Viewer EE Project E Registers PORTE SIM Command al Call Stack Locals Name Location Value 4 4 gt L ASSIGN BreakDisable BreakEnable BreakKill BreakList BreakSet BreakAccess ga Call Stack Locals L N PEMicro Debugger tl 0 00000000 sec L45 G1 Figure 15 Observing Registers with System
19. OVS R2 0 clear R2 B asm main Put constants here Conse Valk DED QOxDEADBEEF AREA qata area DATA READWRITE gt Put variables here END Figure 8 Code for Lab 1 Part 1 Page 15 Part 2 This step demonstrates some of the basic arithmetic and logic operations It is worth noticing that instructions ending with an S modify the application program status register APSR Modify the code as show in Figure 9 valuel EQU 50 value2 EOU 123 value3 EQU OxFFFFFFEFO AREA asm ar a CODE READONLY EXPORT asm main asm main 7 assembly entry point for T nction do mot celete Add program code here MOVS RO 0 clear RO LDR R1 valuel put valuel in Rl LDR R2 valuez2 put value2 in R2 LDR R3 value3 PpuL Values 1m RS MSR APSR RO clear flags ADDS R2 R1 Add values update APSR SUBS R2 R1 Subtract values update APSR ADDS RFR Add values update APSR SUBS IR 3s RL Subtract values update APSR MSR APSR RO clear flags ADD R3 R1 Add values CMP R1 R2 compare CMP R2 R1 compare CMP RLAR compare CMP R1 0x40 compare immediate CMP R2 0x40 compare immediate CMP R1 R3 compare negative CMN R1 R3 compare negative B asm main Put constants here AREA qata area DATA READWRITE gt Put variables here END Figure 9 Code for Lab 1 Part 2 Page 16 Part 3 This step demonstrates program flow control operations using unconditional braches Modify the code as
20. RO UARTO BDL MOVS R1 0x71 STRB R1 RO UARLOACZ 0x02 TE and RE 1 LDR RO UARTO C2 MOVS R1 0x0C STRB R1 RO BA dak ENDFUNC Put constants here AREA data area DATA READWRITE Put variables here END Figure 22 Starting Code to Serial Programs The aim is for the char_out char _in and UARTOInit functions to be callable from the main C program for use in subsequent experiments The EXPORT and FUCNCTION and ENDFUN statements make these runtimes appear as functions in C When C calls a function the first four parameters are passed to the function in RO R1 R2 and R3 So if the template for char_out in C is extern void char_out unsigned char Page 38 Then the character to be sent out the UART will be the first parameter in RO Likewise when a function return a value the value that will be returned is in RO So if the template for char_in in C is extern unsigned char char_in void Then the character that the UART received should be returned in RO Note that char_in and char_out are defined as unsigned char this means that they will be only 8 bits in length which is the length the UART uses When writing the char_out and char_in routines only use registers RO to R3 and R12 as using any other registers requires the values to be saved and restored in the function The char_out and char_in routines should implement the logic shown in Figure 23 char_out Read UARTO_ S1 Does UAR
21. TO_S1 RDRF 1 s Yes Yes WriteROto Read UARTO_D UARTO_D To RO 7 Return Figure 23 char_out and char_in diagrams Does UARTO 1 TDRE 1 The UARTOInit subroutine should be completely functional as provided By default it configures UARTO to use 8 data bits no parity 1 stop bit and a Page 39 baud rate of 9600 bps The clock source is configured to be MGCPLLCLK 2 which operates at 48MHz The asm_main routine is complexly functional as provided asm_main calls the UARTOInit subroutine then enters a loop that calls char_in followed by char_out char_in should wait for the user to enter a character into the terminal When a character is entered char_in should return the character in RO char_out is then called which should be echoed back to the user This process will then repeat indefinitely After completing the char_in and char_out routines connect the KL25Z to the PC Build debug and then run the code onto the board a usual Open Tera Term on the PC that is connected to the board other terminal programs can be used but Tera Term is recommended When Tera Term starts select New Connection Serial then the COM port labeled OpenSDA in the port pull down The hit the OK button Figure 24 u Tera Term disconnected VT File Edit Setup Tera Term Mew connection TCPHP 192 168 0 47 History Telnet SSH SSH UNSPEC Serial Figure 24 Tera Term New Connection Nex
22. Viewer 5 After fully testing the program demonstrate it to the course instructor for credit Page 25 SIM oC GCS EQU 0x40048038 poll SCGCo address POR DB PORTS EQU Ux4004A000 F A A 3 7 PORTB PCRL9 address AREA asm area CODE READONLY EXPORT asm main asm main jgassemoly entry point for CC function do not delete Add program code here BL Ine P40 loop B loop Tare gpro EDR ROp IMCO PLOd AVCLESS Or SIM SCGCo TO RO LDR R1 RO PUL Ve lue OF GIM SCECo INEO RI LDR R2 0x0Q0003E00 7 LOad Value to turn on all p rt PC lLoeks Into RZ ORRO RR OR R2 anto RI STR R1 RO PUG Value Dack INECO CIM SOGES LOR ROJS PORIB PORIS 7 UOaAC Addres OF PORTE POCRLS TO RO LDR R1 0x00000100 Load value to Rl STR R13 RO PUC Value Tto PORTE PCRS add other registers here BX LR Put constants here AREA data area DATA READWRITE Put variables here END Figure 16 Example Code to Initialize Registers Page 26 3 3 Lab 3 Annunciator GPIO Application Lab Objectives e To apply knowledge on the use of GPIO s gained in lab 2 to solve a design problem Problem A maple syrup factory in Vermont has a problem They have a holding tank that stores their product that overflows from time to time When this happens an operator in a remote monitoring room is sent to clean up the mess They have asked you group to implement an Annunciator system to monitor the holding tank and report its
23. apture the waveform for the lab report Next setup the serial decode tool on the oscilloscope Start by pressing the Bus B1 button Then do the steps in Figure 29 thru Figure 35 Page 44 Fun Moise Filter Off Vertical 100 diw 200 us ee i ee EN E N Le 11 40 04 Figure 29 Select bus type RS 232 Blaice Filter Ny 4R5 232 Inputs Channel Label E 200 us Polarity Define Inverted Inputs paengani ia High 13 Figure 30 Select the scope channel connected to the TX line Page 45 EC srmailcs leds r amliy YAE Threshold 1 44 BecOtth Threshold DOC y 1 4 TTL OY CMOS 25v i zaw CMOS 1 654 Choose Preset THT JOY CMOS 1 25 aid ECL 1 5 Apply Preset ep 200 ots 700 2 uy Dy BI Lat TH Configure S600 62N Define Inputs Bus BA papaa Thresholds Figure 31 Set the threshold using the TTL preset Tek Trig E n Configuration Wt iste Dil pale DS Ped m Bi pe Fal Bit Rate 38400 bps 83600 bps 31250 bps Data Bits 20000 bps eo E 3 15200 bps Parity rT is200bps 14400 bps Packets 200 us O 1447 Bin bps On Ltt End of Packet Bus Display Event Table Oo LF3 Bus B Define Configure ET Label Ag 232 Inputs uo cog B N TH Figure 32 Configure the serial settings to match the TX config ADDA ANALOG
24. create a new project file Configure the project to be an assembly project by uncommenting the call to asm_main in main c Add the code for each part to the asm_main s file Build then debug the code as explained in section 2 3 Figure 7 shows the typical debug window display Figure 7 Section A lists the program code Figure 7 Section B lists the disassembly of the code For and assembly program this window should match fairly closely the program code ForaC program both the C code and generated assembly code will be shown Also Shown in this window is the address and machine code for each Figure 7 Section C shows the registers as the program is debugged Figure 7 Section D show the contents of the processor memory This window can be displayed with the menu View gt gt Memory gt gt Memory 1 4 The address field sets the address of the memory that is to be displayed TL Step though the code a single line at a time using the step into button A Observe the behavior of each instruction and log the results on the lab worksheet Page 13 at aa a Se ae ea OSAT eat F vi 2 Blink AV Ji i Visi on File Edit View Project Flash Debug Peripherals Tools SVCS Window Help IS E 7 e he l s B c eoe RA R EEEa ka 0 IETJE RA A gt SBE A E a e o EA Registers a Ox2000042C 4770 BX ir _ semihosting library function 2000042E 0000 MOVS r0 r0 B o ldr r0 equate val _ ldr r0 const val ee R5 200004
25. ct the zip file then open the project 5 Document Change History 3 00 1 14 2014 Initial release for comment on sections 1 2 and 3 1 3 01 1 20 2014 DJH Completed lab 1 and added course objectives 3 02 1 29 2014 DJH Added lab 2 and modified initial install instructions for uVision 5 3 03 DJH Minor corrections to code in lab 1 and additions to troubleshooting section 3 04 3 05 DJH Page 50
26. ed where necessary due to the platform change or to enhance the educational value of the course Another change is the incorporation of higher level programming i e C for some of the experiments instead of solely using assembly language for the course This change is to more closely follow trends in industry and to allow for the execution of more complicated labs Page 3 1 Introduction Microprocessors touch almost every aspect of modern life They can be found in vehicles consumer electronics communications devices appliances toys and of course computers With the exception of full computers i e desktop or full laptops which use full microprocessors with separate memory and peripherals most applications today use system on chips SoC s or microcontrollers MCU s which integrate most of the processing and peripheral functions into a single integrated package A wide variety of processor architectures are available to address many applications The selection of a particular architecture for a design might be done for a range of reasons including technical features e g speed peripherals power consumption etc cost compatibility with existing software or previous experience of the designers One of the dominant architectures for SOC s and MCU s in the market today is the ARM family of processors ARM core devices are manufactured by dozens of IC vendors for a wide range of applications ARM s command a huge market
27. eeeeeeeeeeeeees 49 3 8 Lab 8 Interrupts and Exceptions ccccccecsecseeeeeeueeeeeeeeas 49 4 TFOUDISSHOOCING tasasasntanaansatecceaesaisamenssamanteneiacaseeneaemenamentearn 50 5 Document Change HIStOrsy cccccccscsssee eee eeeeeeeeeeeeeeeeeeagggeeenegs 50 Page 2 Preface 2014 Course Update This manual is for the 2014 update of ECE 395 Microprocessor Laboratory The major change made in the 2014 update is the adoption of the ARM architecture as the course experiment platform This change follows the fall of 2013 change in ECE 252 to focusing on the ARM as the primary architecture studied in the lecture course Prior to changing to the ARM ECE 252 and ECE 395 dating back to the mid 1990 s studied the Motorola 68k architecture During this time ECE 395 had several incarnations At first students hand assembled using wire wrapping techniques 68000 based single board computers SBC s and wrote code for various experiments on the platform In the early 2000 s the SBC design was re implemented as a PCB design which eliminated the need for the students to wire wrap In the later 2000 s the lab evolved to use a Coldfire Microcontroller Evaluation board from Freescale also a 68k core During this time software for the laboratory assignments was done strictly in assembly language The 2014 update leverages some of the experiments that date back to the Original versions of this course but have been updated and modifi
28. ge 4 1 1 Course Objectives 1 Understand and apply the fundamentals of assembly level programming of microprocessors 2 Work with standard microprocessor interfaces including GPIO serial ports digital to analog converters and analog to digital converters 3 Troubleshoot interactions between software and hardware 4 Analyze abstract problems and apply a combination of hardware and software to address the problem 5 Use standard test and measurement equipment to evaluate digital interfaces 1 2 References FRDMKL25ZUM FRDM KL25Z User s Manual This document provides an overview of the hardware board used in the course KL25P8OM48SFO KL25 Sub Family Data Sheet This document provides details on the microcontroller used on the FRDM KL25Z specifically the electrical specifications for the part KL2Z25P8OM48SFORM KL25 Sub Family Reference Manual This document provides details on the microcontroller control registers IO assignments etc KLQRUG KLQRUG Kinetis L Peripheral Module Quick Reference User Guide This document provides gives examples on how to operate the microcontroller for typical applications OPENSDAUG OpenSDA User Guide This document describes the debug interface used on the FRDM KL25Z Cortex MO Devices Generic User Guide Cortex M0O Technical Reference Manual Page 5 2 Microprocessor Experiment Platform The microprocessor platform used for this course is the Freescale Freedom
29. ill be captured for multiple UART configurations and analyzed both manually and with the serial decode utility on the scope Modify the code from the first part as follows In asm_main before the loop but after the call to UARTOInit load RO with the ASCII code for the group bench number In the loop in asm_main remove the call to char_in and add a call to a delay routine The delay is to add some time between sending so it is easy to observe individual characters on the oscilloscope Run the code and verify output of the characters on Tera term With the oscilloscope off install the Tektronix Computer Serial Module DPO2COMP into the DPO2012B oscilloscope Figure 27 Page 42 Figure 27 Installing the DPO2COMP Module Connect the oscilloscope to the KL25Z as shown in Figure 28 The UARTO transmit signal is output on pin PTA2 Use a scope probe to view the signal Connect the ground of the scope probe to one of the ground pins on the board Turn on the oscilloscope Page 43 FRDOM KL252 Cortex MO eC CCN 1 OOS o tama Figure 28 Oscilloscope Setup Verify the scope probe impedance is set to match the probe Verify the scope is set to DC coupling The vertical amplitude can be set to 1V div The time base can be set to 10uS div Set the triggering to manual Adjust the trigger level to about 1 5V The waveform should be seen on the scope Adjust the settings to optimize the view C
30. locations Using the GPIOx_PTOR register toggles a given pin writing a 1 to the desired bit location See sections 41 2 1 thru 41 2 4 of the KL25 Sub Family Reference Manual for details on how to use these registers Page 22 There is an LED on the FRDM KL25Z is a tri color red green blue device The common anode is tied to VDD The three cathodes are tied through resistors to GPIO s as listed in Table 1 Because the LED is wired with the common anode to VDD the GPIO s must be driven low to run on the LED color and driven high to turn off the LED Table 1 KL25Z LED GPIO Assignments LED Color GPIO PTB18 GREEN PTB19 BLUE PTD1 Required Equipment and Parts e Solderless breadboard e Pushbutton e Jumper wires Procedure The aim of this lab is to wire a pushbutton to a GPIO on the FRDM KL25Z then to write software to change the color of the on board LED when the button is pushed The LED colors for pressed vs not pressed may be chosen at the developers discretion 1 Select the GPIO to be used for the pushbutton Avoid the GPIO s assigned to the LED On the solderless breadboard wire the pushbutton in a pull up resistor configuration with one side of the switch to the GPIO and the other to ground 2 Write code to initialize the registers to enable the GPIO s for the LED Outputs and switch inputs as follows SIM_SCGC5 lt lt lt Enable the clocks for the IO ports to keep things simple all the clock can be e
31. mmonly used to interface peripherals to computers SATA Serial ATA which is used to interface storage devices in computers and Ethernet which is used for computer networks Other examples of serial buses are I2C and SPI Serial Peripheral Interface buses which are commonly found in embedded processor systems as interfaces busses for memories DAC s and ADC etc and CAN Bus Controller Area Network which is used to interface various systems in vehicles Page 29 One of the simplest implementations of serial communications is the asynchronous serial port Historically these were common on personal computers for uses such as interfacing to external modems peripherals such as mice and computer terminals On PC s these serial ports used RS 232 complaint signaling and DB 25 or DE 9 connectors RS 232 specifies the electrical characteristics of the signals In the last decade serial ports on PC s have become rarer features as USB has replaced most of the consumer applications that were previously handled by serial ports In embedded systems and industrial controls asynchronous serial communications is still very common and useful In one common embedded application asynchronous serial ports are used for debug console interfaces Most microcontrollers feature UART Universal Asynchronous Receiver Transmitters peripherals internal to the microcontroller A common implementation would be to connect the microcontroller UART to an RS 232 co
32. n Because the receiver re synchronizes its sampling after each transmitted byte differences of up to about 5 are possible in the transmit and receive clocks Start BitO Bit1 Bit2 Bit3 Bit4 BitS Bit6 Bit7 Stop Idle LSB MSB or 7 next byte a a at a a a a tn a ti te ee e e e me e e me e e e e e m Figure 20 Asynchronous Serial Transmission The processor on the KL25Z has 3 UART s UARTO is wired on KL25Z to the Open SDA interface hence it will be used in this lab The OpenSDA serial connection is wired to pins PTA1 RX and PTA2 TX To use a UARTO several parts of the processor must configured Code is provided that does the following 1 The UARTO clock source select bits UARTOSRC must be set in the SIM_SOPT2 register In the code provided these bits are set to 01b MCGFLLCLK clock or MCGPLLCLK 2 clock This means either the MCGFLLCLK 96MHz on the KL25Z or MCGPLLCLK 2 48MHz will be the clock that drives UARTO The next setting selects which one is used 2 The PLL FLL clock select PLLFLLSEL must be set in the SIM_SOPT2 register In the code provided this bit is set to 1b MCGPLLCLK clock with fixed divide by two This means the UARTO clock will be 48MHz 3 The UARTO Clock Gate Control UARTO in the SIM_SCGC4 register must be enabled set to 1 4 The Port A Clock Gate Control PORTA in the SIM_SCGC5 must be enabled set to 1 This is because the UARTO will u
33. nabled PORTB_PCR18 PORTB_PCR19 and PORTD_PCR1 lt lt lt Set to be outputs PORTx_PCRn lt lt lt Set to be input with pull up for the GPIO selected for the pushbutton input Page 23 GPIOB_PDDR bits 18 and 19 and GPIOD_PDDR bit 1 lt lt lt Set to make pins be outputs GPIOx_PDDR bits n lt lt lt Set to make pin input for GPIO selected for pushbutton Figure 16 shows some example code on a way to initialize registers There is sub routine called init_gpio that is called from the asm_main routine In the example two registers are initialized using slightly different methods For both registers there is an equate at the top of the file to assigned an address to a label matching the name of the register Note that the equate can contain math directives to produce the proper value as Shown in the assignment for PORTB_PCR18 This was done to match the address offset description used in the processor reference manual In the first method for loading the value to SIM_SCGC5 the code reads the original value of the register then OR s the bits that need to be set with the original value then writes the new value back to the register This is done to maintain any settings that were previously set Note that the value that is being written will turn on all the Port clocks This is not ideal for a design with an objective to minimize power consumption but it is fine for our needs The second method used for loading the value
34. nclude the new code that was written e g char_in and char_out routines and any changes made for each of the different setting configurations 3 5 Lab 5 Calculator UART Application Lab Objectives e To apply knowledge on the use of serial ports gained in lab 4 to solve a design problem 3 6 Lab 6 Digital to Analog Converter Lab Objectives Page 48 e To learn how to setup and operate the MCU digital to analog converter DAC e To use the DAC to create a waveform generator 3 7 Lab 7 Analog to Digital Converter Lab Objectives e To learn how to setup and operate the MCU analog to digital converter ADC e To use the ADC to create a voltmeter 3 8 Lab 8 Interrupts and Exceptions Lab Objectives e To learn how to setup and use interrupts and exceptions in the MCU Page 49 4 Troubleshooting Message Error 5 Cannot open source input file MKL25Z4 h Cause Kinetis KL25Z support pack not loaded after installing KEIL uVision 5 Fix Follow procedure in section 2 1 to install the Keil Kinetis_ KLxx_DFP Support pack Message Error A1163E Unknown opcode code XXXX expected opcode or macro Cause Label not in first character position in line of code Fix Make sure all labels are in the first column Message startup_MKL25Z4 s error A1023E File startup_MKL25Z4 s could not be opened No such file or directory Cause Caused by opening the project directly from the project zip file Fix Extra
35. nverter IC integrated circuit on the embedded system which would then interface to the RS 232 serial port on a PC In newer PC s which do not have built in RS 232 serial ports a USB to RS 232 converter would be used These converters usually have a DE 9 connector RS 232 converter IC and a serial to USB converter IC with a USB cable to interface to the PC These serial to USB converter IC s are available from a variety of manufactures Prolific and FTDI are very common The use of these IC s required a driver to be installed on the PC but typically do not required any custom firmware to use the IC In newer embedded systems in the Arduino for instance the RS 232 interface is completely removed and the serial to USB IC is directly put on the embedded board This allows the embedded system to directly connect to a PC without the use of a USB to RS 232 converter The KL25Z uses a similar approach but uses a secondary ARM processor as the serial to USB interface instead of the serial to USB IC This secondary ARM processor also serves as the programming and debug interface that is used to load and test code on the main ARM processor The functions performed by the secondary ARM processor are called OpenSDA Page 30 Touch Pad Slider B MHz yo 12C GPIO Inerhal Sense O Header Figure 19 KL25Z OpenSDA Interface Then using serial communications both the transmitter and receiver must use a similar clock rate
36. ogram in assembly in main c uncomment the beginning of the line asm_main and open the file asm_main s Step 6 Add your code to the appropriate file main c for a C project or asm_main s for an assembly project Follow the comments in the templates to keep the code in the correct sections Step 7 Navigate to Project gt gt Build Target hotkey F7 In the build output window make sure there are no errors and that any warnings are understood Step 8 Ensure the SDA connector on a FRDM KL25Z running the PE Micro Firmware see section 2 2 Board Setup is plugged into a USB cable connected to the PC Step 9 Navigate to Debug gt gt Start Stop Debug Session hotkey Ctrl F5 Note a warning about a 32k size limit may appear if you are using the lite version of the tool this is ok Step 10 At this point code can be ran single stepped etc To edit the code the debug session needs to be stopped navigate to Debug gt gt Start Stop Debug Session hotkey Ctrl F5 and Step 6 through Step 9 need to be repeated Page 12 3 Experiments 3 1 Lab 1 Microprocessor Operation Lab Objectives e To learn to create a uVision project then write assemble and debug code e To observe and document operation of microprocessor core as it executes code Procedure From the course website download and print the lab worksheet form for Lab 1 Follow the steps outlined in section 2 3 which explain how to
37. r and specifically the KL25Z including Codewarrior Development Studio IAR Embedded Workbench KEIL MDK uVision mbed The KEIL toolset has been selected for this course A limited free version of is available MDK Lite which is suitable to meet the development needs of this course The KEIL MDK uVision toolset features Support for Cortex M Cortex R4 ARM7 and ARM9 devices Support for C C and assembly uVision4 IDE debugger and simulation environment CMSIS Cortex Microcontroller Software Interface Standard compliant 2 1 Initial Tool Setup The following steps setup a Windows PC for developing and debugging programs on the FRDM KL25Z Page 7 Step 1 From the KEIL website registration required download and install KEIL MDK ARM uVision 5 Note the free MDK ARM Lite is sufficient for the lab https www keil com demo eval arm htm After installing uVision 5 run C Keil UV4 PackInstaller exe and install the option for Keil Kinetis_KLxx_DFP This will install the appropriate libraries for the processor used on the board Step 2 From the KEIL website download and install the Freescale Kinetis OSJTAG Drivers http www keil com download docs 408 asp Step 3 From PE Micro website registration required download and install the OpenSDA Windows USB Drivers http www pemicro com opensda 2 2 Board Setup The following steps must be executed to allow code to be loaded and debugged using the KEIL
38. se IO on port A 5 The Pin Mux Control MUX bits of PORTA_PCR1 and PORTA_PCR2 must be set to 010b Alternative 2 Alternate 2 on these pins is UARTO_RXfor PTA1 and UARTO_TX for PTA2 Page 32 6 The Over Sampling Ratio OSR size must be set in UARTO_C4 In the code provided it has been set to x8 This factors into the baud rate calculations 7 The Baud Rate Modulo Divisor SBR must be set in the UARTO_BDH and UARTO_BDL registers based on the desired baud rate and the clock settings The SBR is a 13 bit long field split between UARTO_BDH and UARTO_BDL The lower 8 bits SBR 7 0 are in UARTO_BDL and the upper 5 bits SBR 12 9 are the lowest bits in UARTO_BDH SBR clock_rate OSR baud_rate clock_rate 48MHz based on the settings for UARTOSRC and PLLFLLSEL OSR 8 For baud_rate 9600 bps SBR 48000000 8 9600 625 0x271 UARTO_BDH 0x02 UARTO_BDL 0x71 8 The Transmitter Enable TE and receiver Enable RE bits in UARTO C2 must be set to 1 to enable the transmitter and receiver After the UART is configured the UART can transmit and receive Data can be transmitted by writing to the UART Data Register UARTO_D Data should only be written to the UART if the transmitter is not busy e g still sending a byte The status of the transmitter can be monitored with the Transmit Data Register Empty Flag TDRE in UART Status Register 1 UARTO_S1 When TDRE is 1 the transmitter can be written to Recei
39. show in Figure 10 AREA asm area CODE READONLY EXPORT asm Main asm Mail 7 assemoly entry point Lor C Lunction dOn delete Add program code here Spotl B SPOT spot2 B Spot4 spot3 B spot2 spot4 B SpOGL Put constants here AREA data area DATA READWRITE Put variables here END Figure 10 Code for Lab 1 Part 3 Page 17 Part 4 This step demonstrates the use of conditional branches Modify the code as show in Figure 11 AREA asm area CODE z READONLY EXPORT asm main acm malin assembly entry point fOr funcliron do not delete Add program code here CSC OnE MOVS RO 3 doe ONE SUBS RO 1 BNE deC ECNE B ESC CNE Put constants here AREA data area DATA READWRITE Put variables here END Figure 11 Code for Lab 1 Part 4 Page 18 Part 5 This step demonstrates using linked branches for calling subroutines Modify the code as show in Figure 12 AREA asm area CODE READONLY EXPORT asm Main asm Mail 7 assemoly entry point Lor C Lunction dOn delete Add program code here loop LDR RO Valuel Call change val for valuel BL Change values LDR RO y V ae peak Change val Tor valve BL change value B TOOP ao 2 again rechange val takes 32 016 Value Drom memory polnled To RO zand modifies it by incrementing then XORing with the address then clearing all byte the lower byte This is then returned back to the address location in memory
40. t back to the UART This is known as echoing back A terminal emulator running on Page 34 the PC will be used to send characters to the board and display what the board sends back A starting point for the code for this program is given in Figure 22 This code needs to have the char_out and char_in functions completed Page 35 SIM SOPT2 SIM SCGC4 SIM SCGC5 PORTA PCR1 PORTA PCR2 PORTE PCR20 PORTE PCR21 UARTO BDH UARTO BDL UARTO Cl UARTO C2 UARTO S1 UARTO S2 UARTO C3 UARTO D UARTO MA1 UARTO MA2 UARTO C4 UARTO C5 AREA EXPORT EXPORT EXPORT EXPORT acm Melt jassemoly entry point Lor TURCI ON EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU EQU asm area asm main UARTOInit Ghar 10 char out Add program code here BL UARTOINIT loop BL char in read Char Trom UART BL Chat Out 7 Send Char Im RO Co UART b loop Wher Char OUL 16 Cal leg RO Contains CODE 0Ox40048004 0x40048034 0x40048038 Ox40049000 Ox40049000 Ox4004D000 Ox4004D000 Ox4006A000 Ox4006A001 Ox4006A002 Ox4006A003 Ox4006A004 Ox4006A005 Ox4006A006 Ox4006A007 Ox40060A008 Ox40060A009 Ox40060A00A Ox4006A00B the char to be sent out the UART char out FUNCTION BX LR BNDEUNC READONLY 20 al char in RO do not delete Page 36 When ohar qm Teturns RO Contains the char that was received char in FUNCTION BX
41. t select Setup gt gt gt Serial port In the Serial port setup dialog set the baud rate data parity stop and flow control to match the KL25Z settings In the default case use Baud 9600 Data 8 bit Parity none Stop 1 bit and Flow control none Then click the OK button Figure 25 Page 40 With the code running on the KL25Z and Tera Term setup properly anything typed on the Tera Term console will be echoed back and displayed in the console window Figure 26 Next stop the code running on the KL25Z then type characters in Tera Term Lab report What happens and why Next add a second BL char out line to the program after the first but before the b loop statement Build and run the code Lab report What happens and why W COM S600baud Tera Term VT Tera Term Seria port setup Port Baud rate Data Parity stop Flow control Transmit delay 0 msecfchar msecsline Figure 25 Tera Term Serial Port Setup Page 41 E COM 9600baud Tera Term VT File Edit Setup Control Window Help ello This is what I typed Figure 26 Tera Term Displaying Echoed Characters 3 4 2 Lab 4 Part 2 Observing the Serial Port on the Oscilloscope The objective of this part of the lab is to observe the serial port output on the oscilloscope The code will be modified to continuously stream a single character Then the oscilloscope will be used to view the output waveform Oscilloscope traces w
42. that are synchronized in some fashion so the receiver can sample and decide if a bit is high or low In some serial communications schemes a clock is sent in parallel with the data to align the transmitter and receiver In other schemes the receiver does clock recovery where it generates a local clock that is aligned to the transitions in the data pattern to provide a sampling clock The UART uses asynchronous Sampling to align the receiver to the transmit stream For asynchronous sampling to work both the transmitter and receiver must be pre configured to share the same data rate and format When no data is being sent the transmitter idles at a fixed level high in the case of traditional UART s When a data byte is to be transmitted the transmitter Starts will a start bit which is always a low The transmitter then follows with the data bits which are usually sent LSB least significant bit first high isa 1 and low is a 0 The transmitter closes the transmission with a stop bit which is always a high Page 31 When the receiver sees the transition from high idle to low start bit it knows a data byte is coming It starts sampling the subsequent bits roughly 1 5 bit periods after the beginning of the start bit It samples at the bit period for the number of data bits it has been configured for The presence of the stop bit forces the line to go high so the receiver can observe the next high to low transitio
43. ved data can be read from the UART Data Register UARTO_D Data is available when the Receive Data Register Full Flag RDRF in UARTO_S1 is 1 Data should only be read from UARTO_D after verifying RDRF is 1 Data transmitted and received on serial ports is often formatted as ASCII American Standard Code for Information Interchange characters ASCII provides a standard way to translate hex bytes to characters letters digits punctuation etc When using a terminal emulator to send text the data is usually ASCII Page 33 Figure 21 shows a Summary of the registers for UARTO Note that the fields that are described are in bold Also note all fields are 8 bits and length and Should be accessed with 8 bit instructions LDRB and STRB SE Ba a ed REALI LA A DN UARTO_C4 MAEN1 MAEN2 se S1 ae ae anal S2 Baat RXEDGIF Ead Racal cw Zs LBKDE aia UARTO_ BDH LBKDIE RXEDGIE SBNS SBR 12 8 UARTO BDL SBR 7 0 UARTO_D Data 7 0 Figure 21 UARTO Registers see section 39 of KL25 Sub Family Reference Manual for details Required Equipment and Parts e Tektronix DPO2012B Oscilloscope in lab e Oscilloscope Probe from stockroom e Tektronix DPO2Z2COMP Computer Serial Module from stockroom e Jumper wires Procedure 3 4 1 Lab 4 Part 1 Reading and writing characters for the UART The objective of this part is to develop a program to initialize the UART and enter a loop that reads a character from the UART and then writes i

Download Pdf Manuals

image

Related Search

Related Contents

INTRODUZIONE  Reg. 95  BIOPUR KIT EXTRAÇÃO MINI SPIN PLUS  HBP-1300 Manual de instrucciones  Toshiba 32DL834 LED TV  Lenco BTT-6 home audio set  Cyber Shot mode d`emploi  SAFEX C2 - Lascenter  USER MANUAL  Manuel d`utilisation  

Copyright © All rights reserved.
Failed to retrieve file