Home
Kinetis Quick Reference User Guide
Contents
1. 13 L2 Code oor D mec 13 L RE AU oor poo cT 13 LJ TS e T T Dub m otsrse E E E aie 14 13 5 Device State Biter TESOL aute ieuas ply Od bog E CHER PUER A RES FUR ERREUR KL Mn RE EH ER EQUE Ma Haa ER C E ar P ER 14 123 Topical system Mmm A alio dise dii iei odd aaa uva eiae ned Lastra pui du teca ra E uU dU Aaaa S d MN 14 14l Lowes leyelassembly Tonne eR e H 14 fE C I Ur general Pe T Ae T oS SET 14 E Ta dulerempbs AARM CODE Gi iie edes ennn ipi patrol oc cuui 15 1AL2 Bronchtostarlof amiabisaton Gud uei que tide kde lagu E 1S D ME c s EHS Sman a ura seantaereranio ae unocnaieablaneaiasseaidebines 15 IE MERITI 15 14 22 EMINET RAM sas Rm 15 L423 Enable port COCKS T 16 1424 Ramp system clock so selected feeguelicy usus eise preter eor ene HE DR Ou eee i p penso 16 Baie TELS par NRSC NE RENTE UU o o IIT 16 1426 Enable UART for terminal corneal Op ao eiectus eb Rd re E HARD Lipa bed kaiaa I 14 27 Tump te Siap of main nction for application armenn ennaii 17 Chapter 2 General System Setup Hardware Considerations el QV a 19 FAUNE cr m 19 atoll ec e T 19 EN NES DC RU SUE saad Ssh ce
2. 149 Iova eau HI PI 150 ICM c i ON P mem 151 R siiesiicotantanietsinecinaptensesanioveian E abstain aehnesie E E Samuels A E A E 153 DOWN n T liv fere 152 163 1 General routing and PC Sa 0 nos tton a Rte sebo EIU R HP MNV UR Fax EP RR PER DURO REIR IMPER PAR EHb ERES oS REX ER 152 166 EMC and ESD ue IS IG E 152 166 1 Codecxample and LAU 152 16 7 Demonstration COSE vae vereint edlesitoree ke p e a Fried ea bu ed inve eb bed accedi cu Ea ev i biet 154 Chapter 17 Touch Sense Input TSI Module IKE E o m 157 LAC madu ioa O A Ley Ip B I i0 m 159 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 11 Section Number Title Page IA TSO Ur Atti M 160 LESE C oBnHEBESBOERECERTIE ascensus eges en gulsinpr bn Da Deas Dui tale poco adea day bc bed EIS EI A EET ead pw owe deoa tineis 162 FALI Code Example and bxplungbotiaus iet bi pecias Mac eerta nre biblia Fab bcp S EE E e Sd ee 163 RS T Ba IE T uis deiode mote Dad ea pen qt E eee MErE M ea IEEE A aper E E Susa d resp dia ved iar duties 165 173 1 PCE Rounne aud PLIacenmelila eden cde bsp erbbd AE qbus Pup dpa Eb edad 166 Chapter 18 Using Peripheral Delay Block PDB to Schedule Analog to Digital Converter ADC Conversions ISA OVV M 167 A TOG n A E TE
3. There are two registers in the mode controller the PMPROT register and the Power Management Protection register This is a write once register after a reset This means that once written all subsequent writes are ignored In our example system above our two basic modes of operation are run mode and LLS mode If we do not want the MCU to be in any other low power mode we would want to write the ALLS bit in the PMPROT register MC PMPROT MC PMPROT ALLS MASK This write allows the MCU to enter LLS only It is then no longer possible to enter any other low power mode Once the PMPROT register has been written the write to the PMCTRL control register sets the mode entry and exit selection For our example entry into LLS mode would be enabled with this write MC PMCTRL MC BMCTRL LPLLSM 0x3 set LPLLSM 0b11 5 2 2 2 Entering low leakage stop LLS mode Once the previous two setup steps have been done the low power stop mode would be entered with a write to the SCR register in the core control logic to set the SLEEPDEEP bit SCB SCR SCB SCR SLEEPDEEP MASK When the WFI instruction is executed the mode controller will step through the low power entry state machine making sure all of the modules are ready to enter the low power mode If for instance the UART is finishing a serial transmission it would hold off the entry into the LLS until the transmission was completed In C the syntax to execute the core instruction WFI is
4. 0 pceBufPointer for ux 0 ux lt configNUM ENET TX BUFFERS ux xENETTxDescriptors ux status TX_BD_TC ifdef NBUF_LITTLE_ENDIAN xENETTxDescriptors ux data uint8 t REV uint32_ t pcBufPointer else xENETTxDescriptors ux data pcBufPointer endif pcBufPointer configENET TX BUFFER SIZE xENETTxDescriptors ux length 0 ifdef ENHANCED BD xENETTxDescriptors ux ebd status TX BD IINS TX BD PINS endif pcBufPointer amp ucENETRxBuffers 0 while unsigned long pcBufPointer amp OxOfUL 0 pcBufPointer for ux 0 ux lt configNUM ENET RX BUFFERS ux xENETRxDescriptors ux status RX BD E xENETRxDescriptors ux length 0 ifdef NBUF LITTLE ENDIAN xENETRxDescriptors ux data uint8 t REV uint32_ t pcBufPointer else xENETRxDescriptors ux data pcBufPointer endif pcBufPointer configENET RX BUFFER SIZE ifdef ENHANCED BD xENETRxDescriptors ux bdu 0x00000000 xENETRxDescriptors ux ebd status RX BD INT endif Set the wrap bit in the last descriptors to form a ring xENETTxDescriptors configNUM ENET TX BUFFERS 1 status TX BD W xENETRxDescriptors configNUM ENET RX BUFFERS 1 status RX BD W uxNextRxBuffer 0 uxNextTxBuffer 0 12 3 PHY management interface The PHY management interface is the path to communicate to the PHY control status registers whic
5. 011 Execute STOP LLS RUN Wakeup from enabled LLWU pin or module source or Re set pin 9 VLPR LLS Set ALLS in PMPROT LPLLSM 011 Execute STOP 10 RUN VLLS 3 2 1 Set AVLLSx in PMPROT LPLLSM 101 for VLLS3 110 for VLLS2 111 for VLLS1 Execute STOP VLLS 3 2 1 RUN Wakeup from enabled LLWU input source or Reset All wakeup goes through Reset sequence Check SRS for source of wakeup Check LPLLSM for mode 11 VLPR VLLS 3 2 1 Set AVLLSx in PMPROT LPLLSM 101 for VLLS3 110 for VLLS2 111 for VLLS1 Execute STOP 5 6 Source of wakeup pins and modules Table 5 3 Source of wakeup pins and modules LU inion LLWU_PO LLWU_MOIF LLWU P1 PTE2 DSPI SCK SDHCO DCLK LLWU P2 PTEA DSPI1 PCSO SDHCO D3 LLWU_P3 PTAA FTMO CH1 NMI LLWU P4 PTA13 CANO_RX FTM1_CH1 FTM1 QD PHB LLWU P5 PTBO I2CO SCL FTM1 CHO FTM1 QD PHA LLWU P6 PTC1 SCI1 RTS FTMO CHO LLWU_P7 PTC3 SClI1_RX FTMO_CH2 LLWU_P8 PTCA DSPIO PCSO FTMO CHS38 LLWU_P9 PTC5 DSPIO_SCK LLWU_P10 PTC6 PDBO EXTRG LLWU_P11 PTC11 SSIO RXD Table continues on the next page Kinetis Quick Reference User Guide Rev 0 11 2010 64 Freescale Semiconductor SSS EI eee al Chapter 5 Power Management Controller PMC MODECTL Table 5 3 Source of wakeup pins and modules continued LU ition LLWU_P12 PTDO DSPIO PCSO SCI2 RTS LLWU P13 PTD2 SCI2 RX
6. 96 MHz the PLLS bit is set to enable the PLL the clock monitor is enabled CME 1 to cause a reset if crystal fails LOLIE can be optionally set to enable the loss of lock interrupt MCG C6 MCG C6 CME MASK MCG C6 PLLS MASK wait until the source of the PLLS clock has switched to the PLL while MCG S amp MOG S PLLST MASK wait until the PLL has achieved lock while MCG S amp MCG S LOCK MASK set up the SIM clock dividers BEFORE switching to the PLL to ensure the system clock speeds are in spec core PLL 96MHz bus PLL 2 48MHz flexbus PLL 2 48MHz flash PLL 4 24MHz SIM CLKDIV1 SIM CLKDIV1 OUTDIV1 0 SIM CLKDIV1 OUTDIV2 1 SIM CLKDIV1 OUTDIV3 1 SIM CLKDIV1_OUTDIV4 3 Transition into PEE by setting CLKS to 0 previous MCG C1 settings remain the same just need to set CLKS to 0 MCG C1 amp MCG C1 CLKS MASK Wait for MCGOUT to switch over to the PLL while MCG S amp MCG S CLKST MASK gt gt MCG S CLKST SHIFT 0x3 The USB clock divider in the System Clock Divider Register 2 SIM CLKDIV2 should be configured to generate the 48 MHz USB clock before configuring the USB module SIM CLKDIV2 SIM CLKDIV2 USBDIV 1 sets USB divider to 2 assuming reset state of the SIM CLKDIV2 register 4 3 2 Transitioning between PLL engaged external mode and bypassed low power internal mode To be able to move the MCU into the
7. Freescale Semiconductor 179 8 9 10 11 12 13 14 Compile the project by clicking the Make icon or right click on the project and select Make In the build dialog box at the bottom you will see any errors or warnings If the compilation was successful you will see something like the image below if there are no errors there may be some warnings depending on the code k60_tower_demo out Performing Post Build Action Total number of errors 0 z Total number of warnings 0 o Now download the code to the board and start the debugger by pressing the Download and Debug button The code will download into RAM or flash depending on the project settings and the debugger screen will appear and pause at the first instruction Hit the Go button to start running EF EIM SWO X Lan dama c reki After you have selected Go the software will print out some basic chip information and then write Hello World to the terminal After that it will echo anything typed into the terminal screen Hit the Break button to pause the debugger You can then step line by line via the Step Over button and dive into function calls with the Step Into button Hit the Stop button to end the debugging session Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor How to Reach Us Home Page www freescale com Web Support http www freescale com support USA Europe
8. Freescale Semiconductor KQRUG Users Guide Rev 0 11 2010 Kinetis Peripheral Module Quick Reference A Compilation of Demonstration Software for Kinetis Modules This collection of code examples useful tips and quick reference material has been created to help you speed the development of your applications Most chapters in this document contain examples that can be modified to work with Kinetis MCU Family members When you re developing your application consult your device data sheet and reference manual for part specific information such as which features are supported on your device Sample code can be found at KINETIS512_SC zip available from http freescale com Information about the ARM core can be found in the help center at http ARM com The most up to date revisions of our documents are on the Web Your printed copy may be an earlier revision To verify that you have the latest information available refer to http freescale com ey oe TM Freescale Semiconductor Inc 2010 All rights reserved e freescale semiconductor Revision History Revision yd Page Date Level Description Number s 11 2010 0 Initial release N A Kinetis Peripheral Module Quick Reference Rev 0 Freescale Semiconductor Contents Section Number Title Page Chapter 1 General System Setup Software Considerations Del e UL
9. Low power mode current adder can be 1uA Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 159 EB TSI configuration 16 input capacitive touch sensing pins each with individual result registers Automatic detection of electrode capacitance changes with programmable upper and lower threshold for each electrode s TSI interrupt end of scan Interrupt after scanning all electrodes once Electrode short Detects when electrode is shorted to Vpp or Vss e Conversion overrun If the conversion time of electrodes goes above scan period NOTE This feature will be available in the second mask of the TSI These features enable the following special characteristics Noexternal components needed the pin can be directly connected to an electrode a series resistor can be used to limit the current that might flow into the pin in case of an ESD event but it is not necessary e Single pin per electrode architecture Operation of 16 electrodes on run modes and 1 wake up electrode in all low power modes Automatic touch event interrupt from any of the electrodes External and reference oscillator subject to the same temperature variation so calibration thresholds are compensated no touch detection variations over temperature range Number of scan can be configured for faster response time or for higher resolution Current sources are far more robust than external weak pull ups used in tradi
10. ezp wrdi cmd ezp write byte EZPORT WRDI while MCF5282 OSPI OIR amp MCF5282 OQSPI QIR SPIF NOTE The code above assumes lower level byte sending with QSPI has been implemented with ezn write byte You could easily implement this and port it to other SPI modules like DSPI 9 1 2 3 Sector erase and program The SP command programs up to one section of flash memory that has previously been erased by an SE command The starting address of both commands should be 64 bit aligned three LSBs being zero The Ezport module buffer will receive program data in FlexRAM programming acceleration RAM before executing the SP command so the number of bytes to be programmed should be a multiple of eight and up to one section size at a time Example code set to ezp mode ezp spi init 0 6 0 0 max permitted clock speed for read 1 Boot up from reset with EZPORT enabled ezp wren cmd 2 Verify WEN flag is set Sr ezp rdsr cmd if sr EP SR WEN printf Failure in SR value WEN not set n error _count 3 Sector erase ezp se cmd sector addr Loop till command has completed sr EP SR WIP Poll SR until WIP goes low while sr amp EP SR WIP EP SR WIP Kinetis Quick Reference User Guide Rev 0 11 2010 90 Freescale Semiconductor LA Chapter 9 EzPort Module sr ezp rdsr cmd ezp_wren_cmd 4 Sector program ezp pp cmd sector addr 64 pg buffer Loop till comma
11. 94 Freescale Semiconductor Chapter 10 Flexbus Module FB_AD FB_AD FB_AD 31 24 23 16 15 8 Address Z 32 bit port Data Address 16 bit port 8 bit port By Address phase B Data phase Figure 10 1 FlexBus multiplexed operating modes 10 1 1 2 3 Modes of Operation Table 10 1 and Table 10 2 show the assignment of FlexBus signals available for the Kinetis MCUs depending on the package Non LCD devices are those without a segment LCD peripheral Table 10 1 FlexBus signals on non LCD devices A 29 16 AD 31 0 AD 31 24 5 AD 19 0 4 CS AD 19 0 2 CS AD 17 0 2 CS nals AD 81 0 CS 5 CS 5 0 CS 0 Muxed Up to 32 ad Up to 32 ad Up to 21 ad Up to 20 ad Up to 20 ad Up to 18 ad N A N A mode dress Up to 32 dress Up to 32 dress Up to 16 dress Up to 16 dress Up to 16 dress Up to 16 data lines data lines data lines data lines data lines data lines AD 31 0 AD 81 0 AD 15 0 AD 15 0 AD 15 0 AD 15 0 Non Up to 30 ad Up to 24 ad Up to 21 ad N A N A N A N A N A muxed dress dress dress mode _ A 29 16 AD 23 0 Up to AD 20 0 Up to AD 15 0 Up to 8 data lines 8 data lines 16 data lines AD 31 24 Up AD 31 24 AD 31 16 to 16 address AD 15 0 Up to16 data lines AD 31 16 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 95 Using the Flexbus module Table 10 2 FlexBus signal
12. LLWU P14 PTD4A SCIO RTS FTMO CHA EWM IN LLWU P15 PTD6 SCIO RX FTMO CH6 FTMO FLTO LLWU MOIF LPT1 LLWU MIE CMPO LLWU_M2IF CMP1 LLWU_MSIF CMP2 LLWU_M4IF TSI LLWU MBSIF RTC LLWU_M6IF Reserved LLWU MTIF Error Detect wake up source unknown Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 65 Source of wakeup pins and modules Kinetis Quick Reference User Guide Rev 0 11 2010 66 Freescale Semiconductor Chapter 6 Memory Protection Unit MPU 6 1 Using the memory protection unit module 6 1 1 Overview This chapter demonstrates how to use the MPU module which concurrently monitors system BUS activities and its access privileges on internal RAM The following example shows how to program the region descriptors that define internal RAM memory spaces and their access rights 6 1 2 Introduction The MPU is a Freescale Kinetis module for memory protection This module should not be confused with ARM s MPU ARM s MPU is not integrated in Kinetis MCUs However both Freescale and ARM MPU shared the same purposes regions protection access permissions and overlapping regions protection In addition the Freescale MPU provides access error detection and multiple bus masters monitor 6 1 3 Features A Memory Management Unit MMU is designed for complex memory management and memory protection in microprocessors with Translation Look aside Buffer TLB paging dynamic allocatio
13. Port Memory Figure 10 2 Sequential 32 bit transfers byte lane shift differences 10 1 1 2 6 Memory map Typical memory mapping as shown in Figure 10 3 0x6000_000 0xA000 0000 is the FlexBus space used for execution OxXA000 0000 OXEO00 0000 can only be used for data Figure 10 3 FlexBus memory range 10 1 1 2 7 Reference clock Figure 10 4 shows a high level diagram for the FlexBus reference clock The maximum FlexBus clock frequency in run mode is up to 50 MHz Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 97 Using the Flexbus module Figure 10 4 Clocking diagram 10 1 1 3 Configuration examples In this example the FlexBus is connected to the MRAM memory of the TWR MEM board 10 1 1 3 1 Code example and explanation Figure 10 4 shows the FlexBus reference clock derived from the MCGOUTCLK The software needs to configure a stable clock This example configures 96 MHz of core frequency Example code Code Snippet int MRAM START ADDRESS 0x60000000 uint8 wdata8 0x00 uint8 rdata8 0x00 uintl6 wdatal6 0x00 uintl6 rdatal6 0x00 uint32 wdata32 0x00 uint32 rdata32 0x00 Set Base address FB CSARO MRAM START ADDRESS Enable CS signal FB CSMRO FB CSMR V MASK FB CSCRO FB CSCR BLS MASK right justified mode Kinetis Quick Reference User Guide Rev 0 11 2010 98 Freescale Semiconductor FB CSCR PS 1 8 bit
14. SIM SCGC3 SIM SCGC3 FLEXCAN1 MASK Configure NVIC to enable corresponding interrupts for FlexCAN Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 143 Configuration examples Configure NVIC to enable interrupts if isCANO NVICICPRO NVICICPRO amp 0x07 lt lt 29 0x07 29 Clear any pending interrupts on FLEXCANO NVICISERO NVICISERO amp 0x07 lt lt 29 0x07 29 Enable interrupts for FLEXCANO NVICICPR1 NVICICPR1 amp 0x1F lt lt 0 Ox1F Clear any pending interrupts on FLEXCANO NVICISER1L NVICISER1 amp OxlF 0 OxlF Enable interrupts for FLEXCANO else NVICICPR1 NVICICPR1 amp OxFF 5 OxFF 5 Clear any pending interrupts on FLEXCAN1 NVICISER1 NVICISER1L amp OxFF 5 OxFF 5 Enable interrupts for FLEXCAN1 Now configure pins for FlexCAN Configure CAN RX TX pins muxed with PTE24 25 for FlexCAN1 PORTE PCR24 PORT PCR MUX 2 PORT PCR PE MASK PORT PCR PS MASK PORTE PCR25 PORT PCR MUX 2 PORT PCR PE MASK PORT PCR PS MASK Now everything is ready and it is time to initialize the FlexCAN step by step as shown below 1 Make sure FlexCAN module is disabled after reset it is disabled Select clock source for FlexCAN by setting clearing CTRL1 CLK_SRC bit Enable FlexCAN module by clearing MCR MDIS bit Wait until FlexCAN module is out of low power mode MCR LP
15. Section Number Title Page 239 Using The Liew leakape wakeup UMi Me 58 KH 9 i i A A EN A E A NEO A aaa eae 58 E Mode Tans ONE narrgemri eiri nede aaa AESKA U G 58 LX 9 Be e o iM E 58 3932 LOBDPEBEAHOD eT TTT 58 v MEE oU ric ree T c T 58 SO R God debian a dbaplatas toute dps dba as a uda to tuba tabs e teu pde 59 224 9 LLWU pon ma module WHS PIES au ed ipid dboitelo tube ped pe rdp pisc REA M DOR I Or i dla p didam priui 59 Dee WF iUc n jor an E A 60 Sa Module operation im Low power ModE E 61 39 Mod Transition LET m 63 S6 SOM oi wakeup fats Eri THT e 64 Chapter 6 Memory Protection Unit MPU Gl Using the ae ARTE IUE modien E e A AA 67 GLN REE UE Wo an TEN 67 Hee DD S e HER 67 5 FENES ve EN 67 6J4 Conicyraion SRS cu a dp ae dide diei didi du piod pididui d e ie imde ie cipi 68 GLA Region ai ric IR 68 Chapter 7 Enhanced Direct Memory Access eDMA Controller NES oo c T Hm 69 FA TAMER P 69 p s Deo T TEN 71 Fad Sicut 71 PO NEN buc quss tr 72 px NE Multiple ALI T 13 Ta Transfer process major and inor TT A sntensnccnvassatdqsavcnvaseueayraenvencavaneybant ERAS ER PLUS IRURE gib dn 74 Kinetis Quick Reference User Guide Rev 0 11 2010 6 Freescale Semiconductor Section Number Title Pag
16. UARTx SI RDRF and transmit data register empty flag UARTx SI TDRE would be enabled using the UARTx_C2 TIE RIE bits The names of these flags are a bit misleading since they don t always indicate a full or empty condition For UARTs that include a FIFO the full or empty condition is determined based on the amount of data in the FIFO compared to a programmable watermark If both the RDRF and TDRE interrupt requests are enabled then the UART interrupt handler would need to read the S1 register to determine which condition is true then read and or write to the UART data register UARTx_D to clear the flags Since the CPU is still responsible for moving data there is CPU loading associated with an interrupt driven software approach Using the DMA to move data can help to decrease the CPU loading even more than using the UART interrupts The UART s same RDRF and TDRE flags used for an interrupt driven software approach can be re routed to the DMA controller instead This is done by setting the UARTx_CS TDMAS RDMAS bits Each of these requests would be routed to a different DMA channel the specific DMA channels would be selected by programming the DMA channel mux One DMA channel would be responsible for handling receive traffic so it would read one or more bytes from the UART for each request The second DMA channel would be responsible for handling the transmit traffic so it would write one or more bytes to the UART for each request When th
17. and the 5 bit fractional baud rate divider the VARTx_C4 BRFA field Enable the transmitter and receiver to start the UART Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 103 Configuration example 11 3 2 UART receive example The function below shows an implementation for a simple polled UART receive function The parameter passed in to this function is the UART channel to receive a character uartch The function returns the character that is received char uart getchar UART MemMapPtr channel Wait until character has been received while UART S1 REG channel amp UART S1 RDRF MASK Return the 8 bit data from the receiver return UART D REG channel Since this is a polled implementation the function will wait until a character is received If no character is received then the code will remain in the while loop indefinitely In order to avoid code getting stuck when no traffic is being received it is a good idea to include a function to test if a character is present or not The uart getchar present function can be called prior to calling the uart getchar function in cases where UART receive traffic is not guaranteed or required before moving on with program execution int uart getchar present UART MemMapPtr channel return UART S1 REG channel amp UART S1 RDRF MASK 11 3 8 UART transmit example The function below shows an implementation for a simple polle
18. copper pours on signal layers where possible All ground planes and ground pours must be connected with plenty of vias Likewise all like power planes and power pours must be connected with plenty of vias Recommended layer stackups 4 Layer PCB A Layer 1 top MCU location Ground plane and pads for top mounted components no signals Layer 2 inner signals and power plane Thick core Layer 3 inner signals and power plane Layer 4 bottom ground plane and pads for bottom mounted components no signals 4 Layer PCB B Layer 1 top MCU location signals and poured power Layer 2 inner ground plane Thick core Layer 3 inner ground plane Layer 4 bottom signals and poured power 6 Layer PCB A Layer 1 top MCU power plane and pads for top mounted components no signals Layer 2 inner signals and ground plane Layer 3 inner power plane Layer 4 inner ground plane Layer 5 inner signals and power plane Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 29 EA PCB layer stack up Layer 6 bottom ground plane and pads for bottom mounted components no signals 6 Layer PCB B Layer 1 top MCU signals and power plane Layer 2 inner ground plane Layer 3 inner signals and power plane Layer 4 inner ground plane Layer 5 inner power plane Layer 6 bottom signals and ground plane 6 Layer PCB C Layer 1 top MCU signals and power p
19. the NVICSER2 is used because the LPTMR IRQ is 85 The NVICCPRx takes on the same number in this case NVICCPR2 3 To know which bit to set perform a modulo operation to obtain the remainder by 32 of the IRQ number This number is used to enable the interrupt on NVICSER2 and to clear the pending interrupts from NVICCPR2 Example LPTMR BIT 85 mod 32 LPTMR BIT 21 4 At this point the interrupt for the LPTMR can be configured NVICICPR2 1 21 Clear any pending interrupts on LPTMR NVICISER2 1 21 Enable interrupts from LPTMR module 5 Next set the interrupt priority level This is application dependent On Kinetis MCUs there are 16 different priority levels To set the priority write to the NVICIPxx register the xx represents the IRQ number in this example NVICIP85 Note the most significant nibble is used to set up the priority the lower nibble is reserved and reads as zero The LPTMR example sets the priority to 3 NVICIP85 0x30 Set Priority 3 to the LPTMR module 6 After the NVIC registers are set up finish the peripheral configuration that must enable the interrupt 7 In the ISR clear the peripheral interrupt flag to avoid re entrance For this example Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 37 Configuration examples void vfnLPTMR_ISR void LPTMRO CSR LPTMR CSR TCF MASK Clear LPTMR Compare flag ISR code goes here 3 2 2 Relocating the
20. 148 Freescale Semiconductor Chapter 16 Segment LCD Controller 16 1 Overview This document explains how to use the segment LCD controller SLCD for the Kinetis family It includes module initialization power supply clock source load adjustment frame frequency interrupts and the use of features as blinking alternate display segment fault detection and using the module on low power modes 16 1 1 Introduction The segment LCD module SLCD generates all the waveforms required for an LCD The SLCD module supports up to 64 pins The K40 family implements up to 48 LCD pins Eight of them can be configured as COM or backplane allowing control of up to 8 x 40 320 segments The power supply for the LCD can be selected from different options depending on the LCD panel voltage the application environment and the way the contrast control is required The SLCD has a charge pump that allows to control both 3 V and 5 V LCD panels Automatic blinking and the capacity to display two messages in alternate mode without refreshing the segments when less than five backplanes are used are available These features can be used to simplify the code and reduce power consumption in low power modes Segment fault detection is now possible by measuring the capacitance in each pin of the LCD The module measures the capacitance of each pin including cables connector and the LCD panel A reference capacitance must be determined when the LCD is oper
21. 20 pin header implementation 19 pins populated as used on the TWR system boards Figure 2 8 shows the 10 pin header implementation 9 pins populated Kinetis Quick Reference User Guide Rev 0 11 2010 32 Freescale Semiconductor Chapter 2 General System Setup Hardware Considerations PTA3 JTAG_TMS SWD_DIO PTAO JTAG_TCLK SWD_CLK EZP_CLK PTA2 JTAG_TDO TRACE_SWO EZP_DO PTA1 JTAG_TDI EZP_DI RESET_b PTAG TRACE_CLKOUT PTA10 TRACE_DO PTA9 TRACE D1 PTAS TRACE D2 PTA7 TRACE D3 PTA4 EZP CS b TARGET POWER 5V TARGET POWER 5V Figure 2 7 20 pin debug interface PTA3 ITAG TMS SWD DIO PTAO JTAG_TCLK EZP_CLK PTA2 JTAG_TDO TRACE_SWO EZP_DO PTA1 JTAG_TDI EZP_DI PTA4 EZP_CS_b RESET_b Figure 2 8 10 pin debug interface The debug signals are multiplexed with general purpose I O pins so some signals will require proper biasing to select the operating mode The JTAG_TMS signal on PTA3 requires a strong pullup resistor for mode selection The Cortex Debug specification recommends that the JTAG_TCLK and JTAG TDI pins on PTAO and PTA1 have pull resistors high or low to force a known state on these debug input pins Note that the RESET b signal in the debug interface is the MCU s reset pin and not the JTAG_TRST signal The connectors for this interface are keyed dual row 0 050 centered headers When implementing either of these headers on a target system pin 7 must be depopulated to use the 19 pin or 9 pin adapters
22. 5 Module configuration 14 5 1 Module dependencies Clock Source The USB module needs a 48 Mhz clock to operate There are three possible sources for the USB clock PLL FLL and an external pin called USB_CLKIN With PLL or FLL there is a fractional divider after the MUX It divides the frequency of the PLL or FLL to enable the MCU to operate at higher frequencies than 48 Mhz The output of the fractional divider goes to a MUX and then a choice is made between this signal and the USB_CLKIN pin The fractional divider value can be configured in the SIM_CLKDIV2 register inside the system integration module SIM MCGFLLCLK i MCGPLLCLK st H SIM_SOPT2 SIM _SCGC4 Figure 14 5 USB clock diagram Voltage Regulator The USB transceiver power supply comes directly from VOUT33 voltage regulator output Therefore the regulator must be enabled to supply 3 3 V to the transceiver 14 5 2 USB initialization process The USB module can work in either device or host mode During initialization the two modes are similar but there are minor differences between the two Device Mode Initialization In device mode the USB module activates the pullup resistor after initialization is complete to be detected by the remote host Kinetis Quick Reference User Guide Rev 0 11 2010 130 Freescale Semiconductor Chapter 14 Universal Serial Bus OTG Module amp 99 272922222222222922222292229929229222292222222234 USB Init USB ResetiSR Sy
23. Configure System Integration Module for defaults as far as ADC 3 Configure the Peripheral Delay Block PDB 4 Determine the configuration the ADC using a structure to store the desired configuration 5 Use the ADC driver to send the desired configuration to the ADC s Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 169 Configuration example 6 Calibrate the ADCs in the configuration in which they will be used and then restore the desired configuration 7 Enable the ADC and PDB interrupts in NVIC 8 Software trigger the PDB The PDB will then start triggering the ADC as it times the intervals 9 Handle the PDB ADCO and ADC interrupts 18 2 1 1 Turn on ADC and PDB clocks Example Code from the adc_demo project Clocks need to be turned on to the ADC and PDB using the SIM module Turn on the ADCO and ADC1 clocks as well as the PDB clocks to test ADC triggered by PDB SIM sccce SIM SCGC6 ADCO MASK SIM SCGC3 SIM SCGC3 ADC1 MASK SIM SCGCe SIM SCGC6 PDB MASK 18 2 1 2 Configure System Integration module for ADC defaults SIM SOPT7 amp SIM SOPT7 ADCIALTTRGEN MASK SIM SOPT7 ADCIPRETRGSEL MASK SIM SOPT7 ADCOALTTRGEN MASK SIM SOPT7 ADCOALTTRGEN MASK SIM SOPT7 SIM SOPT7 ADCOTRGSEL 0 applies only in case of ALT trigger in which case selects PDB not ALT trigger selects PDB not ALT trigger PDB external pin input trigger for ADC SIM SOP
24. E A E E A 167 E ME ur E E E E A E A E E E 168 E E R pac seta E E I E EE E E TOT N 169 18 21 PDB triggered single ended ADC CODVELSIOUS iiooc iiir pkre a tbt ore eui epar esta e bab Sex e ende Med s EEEREN raV 169 ILI Tie et DC un POB SIOSESL Lu ier estate bend MK terraa tex R AEA Sabes piter pce beca t Pas deat 170 18 2 1 2 Configure System Integration module for ADC defaults eee 170 16 218 Gonhpure Perpberal Delay Block PDB i iieiouiseeitieeuicace a eda vnius deca cgi tke uud 170 15 2 1 5 Derme DC GOOD EURO oie cits cc sda Facere ted Hiec us fades tedtteDa atc R Oda Ne cqpds Hn D Rab dede deu DiRda 171 pss MED UE Ib Erici cec m 172 fr ll et E R Re ep 172 15 2 1 7 Enable ADC aud PDE ite tS oed iiti de bdo pablo dpi dU de cola db di dpa AU RN dite aunt T72 RALE Sonwae EE T ol POB eoira a R A EaR OA TRE 172 15 2 1 9 Handle ADC and POB a 173 13 2 2 ADC device hardware mplemen aLIOI oo caeco trek erret p Pra po eR E pe Rr R ER PURI PERPE eR EUR EAR EAT EEEN NAAN ER PUR PAP eA 174 18 23 PDB device hardware mpg Ie ABD axis danke ytd au REPRE MEp HERE Mero pere PIA TDIE REPE LK Ure i re didt e pM Re ER ieaie dq 174 18 2 IDEE dene ad CODEC SU ORE dedos teli at erp RESI EUER EMEN Fe SY R Hs Fel eb PU verd s por cR lvo du PETI pee Ls ir YR EA 174 RENE US DE QUE UI EET m TE 174 T MEE ord toate 8d eos cape M a A E 174 18 3 2 ESDEMI gonsiderat ions naui a Hd HR RPM Hd ATAQUE App NELLE PM IM E ad abd ba M de RETE
25. FINO poc dU Ata da ahn ainan dist db RUE 132 IS NER ric pu cirniveee dara miesaianpamlaneselaotancendpraisuiabiocieteitolse a 132 14 6 2 Components and placement SUEEBSHOFIS qe de araa aR api acte aione e ea de da aba 134 146 2 Layout fecorumob a Roa occa eet RR PREAR pH R S PIRCOAR EON aR E KURSEN DAR NUR ERREUR UR ERN RAUM OR 135 ICE eod roro ER ATR RE EE REA ERRER www 136 TELAI R a Tea T A Hn 136 r HONTO e E 137 Chapter 15 FlexCAN Module CHER o UE 141 XN MOMENO TTE 141 Cx coi aaa aecatd aan a asap a 142 Kinetis Quick Reference User Guide Rev 0 11 2010 10 Freescale Semiconductor Section Number Title Page EM IO P e Ta MN nom 142 Viigo PECAN maour tunes PEEK DEEANN EAE EEA 143 IS bi Codeeximpile and e aaaeeeaa a E riie 143 KRE e e A ET E A A E E E E PE E iie tua 145 15 2 21 Code example and e ei Te nenii Eai RE eaaa 145 ESAMI TOR S a E 145 13 5241 Codecsampl and Sx lam at On innia ee E AREA 145 oes e m m 146 DAI ode exaniple und L D iooavrooap ionis adiau niat ord V EY o dicant de diae dii onisaa dU Lip l quiu alpoal auta pio ie dota da ddp 146 15 2 5 Configuration of Rx FIFO ID filter table elements ioco riter Sr HH rt riv Hab ebbe e HDI ORE FEE Qr EHE ER 147 1525 1 Code example and explanafl Ol senes erbe pet tho rho SPI RR SEXE HEP AREIS RS RE NP ETARE AARI EEE AIEE 147 Chapter 16 Segment LCD Controller DD Sod eH R 149 IS NND Si isi P
26. Freescale Semiconductor PORTA PCR11 PORTA PCR25 PORTA PCR9 PORTA PCR10 PORTA PCR28 PORTA PCR24 PORTA PCR26 PORTA PCR27 PORTA PCR29 else PORTA PCR14 PORTA PCR5 PORTA PCR12 PORTA PCR13 PORTA PCR15 PORTA PCR16 PORTA PCR17 endif PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX Can we talk to the PHY do MI RTOS DELAY netifLINK DELAY usData mii read 0 while usData Start auto negotiate Oxffff configPHY ADDRESS Oxffff y Chapter 12 ENET Module IO RXCLK IO TXCLK IO RXD3 IO RXD2 IO TXER IO TXD2 IO TXD3 I0 CRS I0 COL IIO CRS DV MIIO RXDV IIO RXER MIIO RXER IIO RXD1 MIIO RXD1 IIO RXDO MIIO RXDO IIO TXEN MIIO TXEN IIO TXDO MIIO TXDO IIO TXD1 MIIO TXD1 PHY PHYIDR1 amp usData mii write 0 configPHY ADDRESS PHY BMCR PHY BMCR AN RESTART PHY BMCR AN ENABLE Wait for auto negotiate to complete do RTOS DELAY netifLINK DELAY mii read 0 configPHY ADDRESS PHY BMSR amp usData while usData amp PHY BMSR AN COMPLETE When we get here we have a link find out what has been negotiated usData 0 mii read 0 configPHY ADDRESS PHY STATUS amp usData Clear the Individual and Group Addres
27. Hardware considerations 16 5 1 General routing and placement Minimize the trace length Take advantage of any LCD pin that can be configured as FP or BP to reduce trace lengths and routing of the LCD Place the capacitors for the charge pump VLL1 VLL2 and VLL3 as close as possible to the MCU 16 6 EMC and ESD considerations The charge pump can be sensitive in a noisy environment Therefore use the external voltage for the LCD reference VLL3 to EXT V When the VLL3 is connected to 3 3 V either the charge pump or the bias resistor network can generate VLLI and VLL2 16 6 1 Code example and explanation For LCD initialization and use of the SLCD module these steps must be followed 1 Enable the SCLD clock gate SCGC3 SLCD 1 LCD clock gate enable 2 LCD analog operation for all used LCD pins PORTx PCRn MUX 0 3 Prepare and ensure that the LCD clock source is available Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor Chapter 16 Segment LCD Controller 4 Configure the NVIC The SLCD interrupt vector in K40 is 102 the NVIC must be configured as follows NVICISER2 I 1 22 NVICICPR2I 1 22 5 LCD General Control Register GCR Aun SOQ HORA te Configure the LCD clock source SOURCE bit Select 1 0 V or 1 67 V for 3 V or 5 V glass HREFSEL Enable regulated voltage RVEN Trim the regulated voltage RVTRIM Enable charge pump CPSEL bit Configure ch
28. ID pIDTabElement id 1 bIsExtID 30 bISRTR 31 single ID acceptance codes else Format A with standard ID pIDTabElement id lt lt 19 bISRTR 31 single ID acceptance codes Example code for configuring ID table in Format B Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 147 Configuration examples Format B two IDs pIDTabElement id amp OxO3fff 16 1 bISExtID 3 bIsExtID lt lt 30 bISRTR lt lt 31 RXIDB 0 i if i lt nIDTab id idList i amp CAN MSG IDE MASK CAN MSG TYPE MASK bIsExtID idList i amp CAN MSG IDE MASK gt gt CAN MSG IDE BIT NO bIsRTR idList i amp CAN MSG TYPE MASK CAN MSG TYPE BIT NO pIDTabElement id amp OxO3fff 1 bISExtID 3 bIsExtID lt lt 14 bISRTR 15 RXIDB 1 lt Example code for configuring ID table in Format C j 0 pIDTabElement id amp OxOOff lt lt 24 j 3 RXIDC 0 i j do if i lt nIDTab id idList i amp CAN MSG IDE MASK CAN MSG TYPE MASK bIsExtID idList i amp CAN MSG IDE MASK gt gt CAN MSG IDE BIT NO bISRTR idList i amp CAN MSG TYPE MASK gt gt CAN MSG TYPE BIT NO pIDTabElement id amp OxOOff lt lt 24 j 3 RXIDC 1 RXIDC 3 j i Else break while j lt 3 Kinetis Quick Reference User Guide Rev 0 11 2010
29. In this example both ADC s will be scheduled but only the results from ADC1 connected to the onboard potentiometer on channel 20 will be used to report the control input For this demonstration the PDB timers are set to intervals long enough to easily observe the timing on an onboard LED after which a message summarizing the readings is presented The messages will be filtered such that if no significant change in the potentiometer is made no report will be issued 18 1 2 Features The ADC features demonstrated by the adc_demo example code include e Simple calibration of the ADC A simple driver for the ADC which facilitates using both ADCs and their calibration with minimal software is included in the adc_demo example code Prior to taking the first measurement during the initialization of the demo project the ADC will be calibrated The use of the driver of the ADC will simplify this While the ADC can be used prior to calibration for conversions the calibration of the ADC enables it to meet its specifications Averaging by 1 4 8 16 or 32 The ADC s ability to average up to thirty two conversion values prior to ending the conversion process and generating a result will be demonstrated This feature reduces CPU load it also reduces the effect of a noise spike on any readings It is a simple arithmetic averaging of thirty two or less if so configured ADC conversions These conversions are taken upon the PDB triggering th
30. MASK printf outSRS Pin Reset wakeup from Normal Stop n if MC PMCTRL amp MC PMCTRL LPLLSM MASK 2 printf outSRS Pin Reset wakeup from Very Low PowerStop VLPS n if MC PMCTRL amp MC PMCTRL LPLLSM MASK 3 printf outSRS Pin Reset wakeup from Low Leakage Stop LLS n The I O states and the oscillator setup are held if the wakeup event is from VLLS1 VLLS2 or VLLS3 The user is required to clear this hold by writing to the ACKISO bit in the LLWU CS register Prior to releasing the hold the user must re initialize the I O to the pre low power mode entry state so that unwanted transitions on the I O do not occur when the hold is released if LLWU CS amp LLWU CS ACKISO MASK 1 RE INITIALIZE MODULES and PORT OUTPUTS HERE LLWU CS LLWU CS ACKISO MASK The RTC may be powered by a separate power source and therefore would not need to re initialized A simple check of the state of the RTC registers to see if they are already enabled would work Kinetis Quick Reference User Guide Rev 0 11 2010 60 Freescale Semiconductor EEA Chapter 5 Power Management Controller PMC MODECTL 5 4 Module operation in low power modes Table 5 1 Module operation in low power modes EzPort Disabled Disabled Disabled Disabled Disabled Disabled SDHC Wakeup FF FF Wakeup Static OFF GPIO Wakeup FF FF Wakeup St
31. MDIO MIIO RXD 1 0 RMIIO RXD 1 0 MIIO RXDV RMIIO CRC DV MIIO RXER RMIIO RXER MIIO TXEN RMII TXEN MIIO TXD 1 0 RMIIO TXD 1 0 __ __ Kinetis MII RMII interface 9 signals MDC Senal MDIO Management RX Differential Rx RXD 3 2 RX To RXD 1 0 Magnetics RXDV CRSDV RJ45 TX TX RXCLK RXERR TXCLK TXEN TXD 3 2 TXD 1 0 CRS COL Differential Tx MIU RM II Interface XO XI VDD GND 5SOMHz osc RSTIN pin Figure 12 4 RMII mode connection example 1 The RMIIO RCR DV is connected to the CRS CRSDV Hardware designs need to be taken into consideration depending on the specific PHY used Kinetis Quick Reference User Guide Rev 0 11 2010 118 Freescale Semiconductor Chapter 12 ENET Module MII0_MDC RMII0O_MDC J _ MDC Serial MIIO MDIO RMIIO MDIO gt MDIO _J Management Differential RX RXD 3 2 Rx RX To MIO RXD 1 0J RMIIO RXD 1 0 lt 4 RXD 1 0 Magnetics RXDV RJ45 RXCLK Marcos TX MIIO RXER RMIIO RXER R 4 RXERR TX TXCLK MIVRMII n Interface MIIO_TXEN RMII_TXEN gt TXEN ACT gt TXD 3 2 To LINK LL MIO TXD 1 0J RMIIO TXD 1 0 4 T XD 1 0 LEDs SPED b MIIO RXDV RMIIO CRC vd CRS CRSDV COL Y INT RST XO XI VDD GND Kinetis MI RMII interface 9 signals N C N C RSTIN 50MHz pin osc Figure 12 5 RMII mode connection example 2 NOTE The indicates special precautions that must be t
32. UP EUR RU eut 175 Kinetis Quick Reference User Guide Rev 0 11 2010 12 Freescale Semiconductor Chapter 1 General System Setup Software Considerations 1 1 Overview This chapter provides a quick look at some of the general characteristics of the Kinetis family of MCUs This is a brief introduction of the operation of the devices and typical software initialization For more information see the device specific reference manual and data sheet 1 2 Code execution The Kinetis family features embedded Flash and SRAM memory for data storage and program execution Additionally external memory can be accessed over the FlexBus external bus interface Code can also be executed over the FlexBus For maximum performance executing from internal memory is recommended 1 3 Reset and booting When the processor exits reset it fetches the initial stack pointer SP from vector table offset 0 and the program counter PC from vector table offset 4 The initial vector table must be located in the flash memory at the base address Ox0000_0000 However the vector table can be relocated to SRAM after the boot up sequence if desired Kinetis devices only support booting from internal flash Any secondary boot must first go through an initialization sequence in flash After fetching the stack pointer and program counter the processor branches to the PC address and begins executing instructions For more information see the Reset and Boot chap
33. User Guide Rev 0 11 2010 18 Freescale Semiconductor Chapter 2 General System Setup Hardware Considerations 2 1 Overview This chapter will outline the best practices for hardware design when using the Kinetis MCUs The designer must consider numerous aspects when creating the system so that performance cost and quality meet the end user expectations Performance usually implies high speed digital signalling but it also applies to accurate sampling of analog signals Cost is influenced by component selection of which the PCB may be the most expensive element Quality involves manufacturability reliability and conformance to industry or governmental standards The Freescale Tower Systems are great for evaluating the operation and performance of the many features of Freescale MCUs However evaluation systems are not ideal examples for implementation of robust system design techniques This document will mention some of the hardware techniques found on the Freescale Tower Systems and will give recommendations that are more appropriate to conventional systems that are not required to implement all of the feature options 2 2 Floorplan The organization of the printed circuit board PCB depends on many factors Typically there are connectors mechanical components high speed signals low speed signals switches and power domains among others that need to be considered While placement of connectors and some mechanical compone
34. VBAT supply is not present then accesses to the RTC registers may not occur and could result in a core lockup type reset in the MCU 5 1 2 2 Configuration examples LVD and LVW initialization code is given below Notice the comments describing the chosen settings You should select the statement options for your application The NVIC vector flag may be set and should be cleared The Interrupt is enabled in the NVIC in this initialization void LVD Init void setup LVD Low Voltage Detect Voltage Select Selects the LVD trip point voltage VLVD 00 Low trip point selected VLVD VLVDL 01 High trip point selected VLVD VLVDH 10 Reserved 11 Reserved x Choose one of the following statements PMC LVDSC1 PMC LVDSC1 LVDRE MASK Enable LVD Reset PMC_LVDSC1 amp PMC LVDSC1 LVDRE MASK Disable LVD Reset Choose one of the following statements PMC_LVDSC1 PMC_LVDSC1_LVDV_MASK amp 0x01 High Trip point 2 48V PMC_LVDSC1 amp PMC LVDSC1 LVDV MASK amp 0x00 Low Trip point 1 54 V Choose one of the following statements PMC LVDSC2 PMC LVDSC2 LVWACK MASK PMC LVDSC2 LVWV 0 0b00 low trip point LVWV PMC LVDSC2 PMC LVDSC2 LVWACK MASK PMC LVDSC2 LVWV 1 0b01 midl trip point LVWV PMC LVDSC2 PMC LVDSC2 LVWACK MASK PMC LVDSC2 LVWV 2 0b01000010 mid2 trip point LVWV PMC LVDSC2 PMC LVDSC2 LVWACK MASK PMC LVDSC2 LVWV 3 0b01
35. a damaged PCB trace the decision to continue with an internal only clocking mode can be made with an appropriate indication to the user or a central monitoring station 4 3 1 Transitioning to PLL engaged external mode PLL engaged external mode uses an external clock from either the crystal oscillator or an externally generated square wave as the reference for the on chip PLL An on chip divider allows an external clock to provide the reference clock to the PLL within the required range of 2 4 MHz The PLL provides the most accurate clock source for frequencies greater than can be generated by an external source In this example an 8 MHz crystal is used to generate a 96 MHz system clock The system clock dividers are set to allow the maximum system performance with this clock source The PLL frequency can be divided down to provide the USB clock of 48 MHz The MCG is configured to minimize PLL jitter maximum PLL frequency with the minimum multiplication factor 4 3 1 1 Code example and explanation If the internal load capacitors are being used they should be selected before enabling the oscillator Application specific 16pF and 8pF selected in this example OSC CR OSC CR SC16P MASK OSC CR SC8P MASK Enabling the oscillator for 8 MHz crystal RANGE 1 should be set to match the frequency of the crystal being used HGO 1 high gain is selected provides better noise immunity but does draw higher current EREFS 1 en
36. and explanatloti ae eer eoi Fei aar RE ARE E ES 36 dud Relo atime ihe vector TAD 6 ve ceu tren ek ARS RURHHFER WIR HRNERIPEAYURE PAR MINER EUER nara MN R EIS PAYER EEA 38 So Ree x cae sna explomibiuiu qe unc db redit Nd one ai obi NE a bc bares ub dbi eie Sexta 38 LUN USNS NULL EE Do SELLO Om E 39 2253 Sdecxuple did H Te E e EOE lesa been paupe cab ARAA 39 Chapter 4 Clocking System A Ooo met 41 LM ino c 41 Kinetis Quick Reference User Guide Rev 0 11 2010 4 Freescale Semiconductor Section Number Title Page AD COTATI TOT GRATE c 43 S31 Tramiionmete PUL engaged external mode se arro tod epa Ple nib eaaet uds dp o ted pas bul PME ura d Sd cod 44 XLI Xodesumiple ana gH AU us vocent aae ed exvbh a E cata Da ae o e EC ME FERAE REL Ife bud 44 4 3 2 Transitioning between PLL engaged external mode and bypassed low power internal mode 45 432 1 Codeexample and CxplandllOn esi rab pito dae eea ea aai 45 43 4 Conlieunus the ELL with the ETC oscillator 35 3 velot el guae cutcaicqnsi eie cal cuna apte epa REN MPa S a IRR TR AqE aand 46 4 33 1 Codeexample and GxplanitOD uae eii one tubis edat de rideo t dpeiubvo rid MF equ E DRpcqu ak tape ic Debate Edu did 47 AA Ching system device hardware Trpkembsb e p qousiducitoimi dU Ip qrIULdpipide dote IHE iane 47 4 Layout guidelines for general routing and placement aar anies diar andorrana
37. asm WFI Kinetis Quick Reference User Guide Rev 0 11 2010 56 Freescale Semiconductor SSS a Ne Se ee ee ee s Chapter 5 Power Management Coniroller PMC MODECTL This statement can be placed anywhere in the code and once execute the MCU will enter the selected low power mode It takes approximately 1 microsecond to enter the low power mode 5 2 2 3 Entering wait mode If you want to use WAIT mode then the SLEEPDEEP bit needs to be cleared before executing the WFI instruction SCB SCR Ke SCB SCR SLEEPDEEP MASK 5 2 2 4 Exiting low power modes Each of the power modes has a specific list of exit methods In general an enabled interrupt from a pin an enabled module trigger or a reset will exit the low power modes and return to RUN or VLPR mode These exit methods are discussed in Section 3 on the LLWU Recovery from VLLSx is through the wakeup reset event The MCU will wake from VLLSx by means of reset an enabled pin or an enabled module See table 3 12 LLWU inputs in the LLWU configuration section for a list of the sources The wakeup flow from VLLSI 2 and 3 is through reset The wakeup bit in the SRS registers is set indicating that the MCU is recovering from a low power mode Code execution begins but the I O are held in the pre low power mode entry state and the oscillator is disabled even if EREFSTEN had been set before entering VLLSx The user is required to clear this hold by writing to the ACKISO bit in th
38. be filtered and displayed as POT 16 bit resolution The conversion results in this example are 16 bit unsigned Differential or single ended Single ended mode is illustrated in this example 18 2 Configuration example In this case the ADC is configured simply to read and average singled ended inputs The ADCO inputs are not connected to anything of interest for this demo but are just demonstrated to function ADC1 both when using the A registers and when using the B registers is configured for channel 20 which matches with the onboard potentiometer This means that of the four conversions scheduled two are for ADCI And both of the ones for ADC1 are on channel 20 which is K2 which is the POT The ADCs are configured to be triggered by the PDB and the PDB is configured to output four triggers each PDB cycle ADCO is activated in this case but also not connected to the POT It is also triggered by the PDB however its readings do not contribute to the digital filter resulting in the fifth output of the demonstration program POT reading 18 2 1 PDB triggered single ended ADC conversions There are several steps taken in the course of the execution of this demo involving setting up the peripherals These steps are further detailed with code from the adc_demo project and explained in the sections that follow numbered after the manner of the steps 1 Turn on clocks to the ADC and PDB module using the SIM module 2
39. block diagram 7 2 2 Trigger mode The DMA Mux supports three different options for triggering DMA transfer requests Disabled Mode No request signal is routed to the channel and the channel is disabled This is the reset state of a channel in DMA Mux Disabled mode can also be used to suspend an eDMA channel while it is reconfigured or not required e Normal Mode A DMA request is routed directly to the specified eDMA channel Periodic Trigger Mode This mode is only available on eDMA channel 0 3 In this mode a PIT request is working as a strobe for the channel s DMA request source which means the DMA source may only request a DMA transfer periodically The transfer may be started only when both the DMA request source and the period Kinetis Quick Reference User Guide Rev 0 11 2010 72 Freescale Semiconductor Chapter 7 Enhanced Direct Memory Access eDMA Controller trigger are active This provides a means to gate or throttle transfer requests using the PIT This is normally used for periodically polling the peripheral source status to control the transfer schedule or for periodical transferring Figure 7 4 shows the relationship between the PIT periodic trigger peripheral transfer source request and the transfer activation PIT trigger Perphe ral Request Channel Acted Figure 7 4 PIT gated transfer activation The hardware provides ten always enabled request sources that can be
40. calau pie OG EIC p naea ual u tuni eO eE CP MU UE 48 LOSS ooo er 49 Chapter 5 Power Management Controller PMC MODECTL 2 Usine te power mussserment conmo E ores ariin ved eo pee tn od vede Lbs to rea ee o Coades ER eto pesa pas REAN dece teils 51 SIL DE eec bepudpdaitiqu tla ei craecapce cid Fudubspespate iti pqpc MG ana died md o E m busee e oda dua da tpe cdbdd 51 ILLT Taies Tar lt aE EE AE 51 512 Usm ihe low voltage detection Syste T 51 R E mm 51 24 22 nma exemples as ivcteaciayianiandotaiaetaolandniaiaansesapacedpawilelantantpactantayiandoianstaplaniucdeauneramontpsaiaobaies 52 24 23 Interrapt odeszample and expl amio iian eid aso cu dU bui blgi dU eibe didus up I dida 53 21 21 Haidware implementato ise aec k ine et PUER PO PUPA ee pe ee ore drin Up DD IP ERE RUD HAS UR 33 sa Usmg Me modecontolli e rr esee A UI E a e RE PR er ERES RR ctl itae E ence n EE qus ocu eR apis 54 SV NES eui e 54 Dela INGO e 54 Deedee cir M REE 39 50 RT ia Ne SEDES Lii c eii S9 342 1 MC oodeexample and Gxplonatlofin uui eei accepi catebenb clmasbdneaskuddpibeanetaun pains d us todos apa peu Rei dB ein 56 5 222 Entering low leakage stop LLS mode iui eie eie nt eto rib k taped puo iiaiai 56 VE NM or Dp ri Nn EI c a7 noue xiu Dow Dawer MO E eao O aotqalonieedpialaeanlaucaniounmuacuates s7 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 5
41. contacts approaching may cause more than one button press event to be logged or detected In capacitive touch sensors as the finger approaches the electrode capacitance varies the same as with mechanical buttons Variations in capacitance due to finger approaching or moving away may falsely trigger more than one touch Debouncing code can be read in the QRUG application code Figure 17 6 shows a flow diagram that explains the debouncing algorithm Figure 17 6 Debounce algorithm flowchart Initialize Counter touch threshold Clear Touch flag debounce counter ext electrode Yes Set Valid lear Touch fl Touch flag Clear Touch flag The interrupt subroutine is also in charge of checking if the ValidTouch flag was enabled after debouncing for each of the four electrodes and toggling the appropriate LED The DBOUNCE_COUNTS macro can be found in the TSI h file This value Kinetis Quick Reference User Guide Rev 0 11 2010 164 Freescale Semiconductor E M M 1 Chapter 17 Touch Sense Input TSI Module defines how many scans with the capacitance above the touch threshold are needed for a touch to be considered valid This value can be modified to suit the specific needs of different applications and electrode sizes 17 5 TSI hardware implementation The critical external component for the TSI is the electrode Electrodes are flat conductive areas that can be etched into a PCB or drawn with conductive inks
42. following figure shows the connection needed from the MAC NET pins to a generic Ethernet PHY in MII mode In MII mode Rx and Tx are synchronous to MIIO RXCLK and MIIO TXCLK respectively There is no additional requirement from the MAC NET to synch from the PHY to the MII RMII interface The PHY data sheet must be followed for all electrical requirements Kinetis Quick Reference User Guide Rev 0 11 2010 116 Freescale Semiconductor Chapter 12 ENET Module MIIO MDC RMIIO MDC MDC Serial ys MIIO MDIO RMIIO MDIO MDIO f Management Differential RX MIIO_RXD 3 2 RXD 3 2 Rx RX To MIIO RXD 1 0 RMIIO RXD 1 0 RXD 1 0 Magnetics MIIO_RXDV RMIIO_CRC_DV RXDV CRSDV RJ45 RXCLK Differential MIIO RXCLK Tx 73 MIO RXER RMIIO RXER RXERR TX MIO TXCLK TXCLK MII RMII MIIO_TXEN RMII_TXEN TXEN es ACT MIO TXD 3 2 TXD 3 2 T J INK MIO TXD 1 0 RMIIO TXD 1 0 TXD 1 0 LEDs SPEED MIO CRS CRS L COL INT RST XO XI VDD GND Kinetis MII RMII interface 17 signals N C N C RSTIN 25MHz pin osc Figure 12 3 MII connection NOTE The indicates special precautions that must be taken for a each specific Ethernet PHY manufacturer The CRSDV function may be located in either pin NOTE The TXER signal is not required for this example this is why there are 17 signals and not 18 12 5 RMII mode The reduced media independent interface RMII is a co
43. from the debug tool The Samtec part numbers for these connectors are e FTSH 110 01 L DV K 20 pin keyed connector e FTSH 105 01 L DV K 10 pin keyed connector Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 33 Other module hardware considerations FTSH 110 01 L DV 20 pin connector no key FTSH 105 01 L DV 10 pin connector no key This interface is useful during the development phase of a project The header may not need to be populated in the production phase of the project but the PCB pads should be kept available for future debugging purposes Kinetis Quick Reference User Guide Rev 0 11 2010 34 Freescale Semiconductor Chapter 3 Nested Vector Interrupt Controller NVIC 3 1 Overview This chapter shows how the NVIC is integrated into the Kinetis MCUs and how to configure it and set up module interrupts It also demonstrates the steps to set the interrupts for the desired peripheral and how to locate the vector table from flash to RAM 3 1 1 Introduction The NVIC is a standard module on the ARM Cortex M series This module is closely integrated with the core and provides a very low latency for entering an interrupt service routine ISR 12 cycles and exiting an ISR 12 cycles The NVIC provides 16 different interrupt priorities Priority 0 is the highest and the lowest is15 This can be used to control which interrupt must be serviced For example on a motor control app
44. macros The CAN bit rate is 83 33k by default Kinetis Quick Reference User Guide Rev 0 11 2010 142 Freescale Semiconductor gu LLL LLLLLLLLLLLLOLLLLLLLL LLLLLLLL a aw Chapter 15 FlexCAN Module UARTS is used as the serial port to interface to HyperTerminal and CANI is used to interface to the CAN bus The HyperTerminal communication setup is Baud rate 115200 Data 8 bit Parity None e Stop 1 bit Flow control none The example codes for SCI2CAN are available from the Freescale Web site www freescale com 15 2 1 FlexCAN initialization Enable the clock to the FlexCAN module before accessing its registers The following steps are performed before initializing the FlexCAN module 1 Initialize MCG and OSC to enable PLL and ERCLK 2 Initialize the clock gating in SIM to enable clocks to the FlexCAN module s and the corresponding ports whose pins are to function as FlexCAN pins 3 Configure the corresponding port pins for FlexCAN through port control 15 2 1 1 Code example and explanation The following code snippet shows how to enable ERCLK clock Must enable ERCLK OSC CR OSC CR ERCLKEN MASK Clock gating code for all ports and FlexCAN Enable clocks to all ports for pin muxing configuration later SIM SCGC5 SIM SCGC5 PORTA MASK SIM SCGC5 PORTB MASK SIM SCGC5 PORTC MASK SIM SCGC5 PORTD MASK SIM SCGC5 PORTE MASK if isCANO SIM SCGC6 SIM SCGC6 FLEXCANO MASK else
45. of commands continued blink Turn on and off the blink Enable alter cmd on off alt norm nate mode blinkrate Read and set blink rate val 0 6 ladj LCD load adjustment val 0 3 Iclk Change LCD clock prescaler lt val gt 0 7 resulting frequen cy must be in 28 58 Hz range pinmux Select MUX O analog and 7 Port PAD lt val gt 0 7 enable PowerMode Select power mode operation val 0 Run 1 wait 2 stop ClockSource set LCD clock source val O System Osc 1 Def RTC 2 ALT Int 32kHz 3 Int 2MHz powersel LCD power supply selection mode VLL1 VIREG HREFO VLL1 VIREG HREF1 VLL3 VDD VLL3 EXT CP VLL3 EXT BR VLL2 VDD help Display the available commands and lt gt their syntax Fault detection example To enable the Fault detection type in the following commands 1 faultDetect setref 2 faultDetect enable 3 To generate a fault in any LCD pin use a wire jumper from ground to the LCD pin 4 When a fault is detected it reports into the terminal Alternate example To enable the alternate function type in the following commands 1 printalt 1234 2 print 1789 3 blink on 4 blink alt Kinetis Quick Reference User Guide Rev 0 11 2010 156 Freescale Semiconductor Chapter 17 Touch Sense Input TSI Module 17 1 Overview The Touch Sensing Input TSI module is designed to interface the MCU with capacitive touch sensing electrodes to easily imp
46. on plastic or crystal With the GPIO measurement method an external pullup resistor is needed In the case of the TSI the electrode charge is driven by the current sources therefore there is no need for an external pull up resistor In certain applications where conducted emissions or ESD is a concern external protective components can be added The idea is to use only a transient voltage suppression TVS diode designed for ESD suppression and a low value 100 470 Q resistor as protection for current that might flow into the MCU Series resistor recommended for overcurrent protection Electrode TVS diode for ESD protection Figure 17 7 For further information on designing electrodes and in depth considerations on hardware and electrode design search for application notes Designing Touch Sensing Electrodes document AN3863 at www freescale com touchsensing Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 165 TSI hardware implementation 17 5 1 PCB Routing and Placement The following list includes the most important things to consider when designing touch sensing electrodes for the TSI 1 Trace width Keep the trace width as thin as possible 5 7 mil traces are recommended The wider the traces the more base capacitance 2 Clearance Leave a minimum clearance of 10 mils At the trace connection to the MCU the pitch is lower than 10 mils therefore use bottleneck mode 3 Keep tr
47. only device mode This application can be self powered using an external power supply or bus powered powered from the 5 V coming from the host In both cases the USB regulator must be enabled to supply the USB transceiver Also the ID line is not needed in this scenario Figure 14 9 Device only diagram Dual Role Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 133 E Hardware implementation This mode is used when the application can be connected to a PC or is able to handle external USB devices such as fingerprint readers mice USB flash drives and so on The application running on the MCU will be configured in device mode not applying 5 V to the VBUS line until the ID signals become low This indicates that a host mode reconfiguration is needed and 5 V is then applied to the VBUS signal using the external IC power distribution IC oF circuit Figure 14 10 Dual role diagram 14 6 2 Components and placement suggestions e The MCU does not include a signal for supplying the 5 V VBUS power for the USB An external power management chip or discrete logic for enabling VBUS is required for the host operation e The power distribution circuit must have over current detection capability to be compliant with the USB standard The 33 Q series termination resistors are recommended for the FS and LS USB transceiver These series termination resistors must be placed as close as possible to t
48. r Figure 14 7 Host mode initialization flow 14 5 3 Voltage regulator initialization The USB regulator is enabled by default therefore no initialization is required unless the regulator was previously disabled by the software after the last POR 14 6 Hardware implementation 14 6 1 Connection diagram The USB 2 0 requests the D and D signals VBUS 5 V power line ground and in some cases the ID pin This ID pin is included in the OTG specification and is used when one device can act as a host or as a device depending on which plug is connected into the board connector The mini A plug which indicates that this part is a host has the ID pin grounded while the ID in the mini B plug is floating indicating that this part will act as a device Kinetis Quick Reference User Guide Rev 0 11 2010 132 Freescale Semiconductor Chapter 14 Universal Serial Bus OTG Module Host Only If the application supports only host mode it is not necessary to include the ID line in the hardware However because it is a host the hardware must provide 5 V with enough current to supply the device side when plugged This voltage is typically provided by an external IC controlled by the MCU power distribution IC ex circtut USB DM USB DP Figure 14 8 Host only diagram Device Only In many cases the application just needs to communicate with an application running on a PC In this case the application running on the MCU supports
49. the EEPROM data size code being used is 0x32 which selects a size of subsystem A subsystem B 2 KB The FlexNVM partition code use is 0x05 representing the size of our data partition as 128 KB and the size of the EEPROM backup memory as 128 KB The system created has 128KB of program data flash and two 2KB EEPROM subsystems each backed up by 64KB of EEPROM backup memory Example Code Write the FCCOB registers FTFL FCCOBO FTFL FCCOBO CCOBn 0x80 FTFL FCCOB1 FTFL FCCOB2 FTFL FCCOB3 Selects the PGMPART command pr 0x00 0x00 0x00 FTFL FCCOBA 0x32 Subsystem A and B are both 2 KB FTFL FCCOB5 0x05 Data flash size 128 KB EEPROM backup size 128 KB FTFL FSTAT FTFL FSTAT CCIF MASK Launch command sequence while FTFL FSTAT amp FTFL FSTAT CCIF MASK Wait for command completion 8 1 3 Endurance While different partitions of the FlexNVM are available the intention is that a single choice for the FlexNVM Partition Code and EEPROM Data Set Size will be used throughout the entire lifetime of a given application The FlexNVM partition choices affect the endurance and data retention characteristics of the device Kinetis Quick Reference User Guide Rev 0 11 2010 82 Freescale Semiconductor E ee ee Chapter 8 Using the FlexMemory The bytes not assigned to data flash via the FlexNVM Partition Code are used by the FTFL to obtain an effective endurance increase for the EEPROM data The built i
50. the file crtO s The address of the start of this code is placed in the vector table offset 4 initial program counter so that it is executed first when the processor starts up This is accomplished by labeling this section exporting the label and placing the label in the vector table The vector table can be found in vectors h In this example the label used is __ startup 1 4 1 1 Initialize general purpose registers As a general rule it is recommended to initialize the processor general purpose registers RO R12 to zero This is done with the move instruction Kinetis Quick Reference User Guide Rev 0 11 2010 14 Freescale Semiconductor LE Sl Chapter 1 General System Setup Software Considerations MOV r0 0 Initialize the GPRs MOV r1 0 MOV r2 0 MOV r3 0 MOV r4 0 MOV r5 0 MOV r6 0 MOV r7 0 MOV r8 0 MOV r9 0 MOV r10 0 MOV r11 0 MOV r12 0 1 4 1 1 1 Unmask interrupts at ARM core CPSIE T Unmask interrupts 1 4 1 1 2 Branch to start of C initialization code import start BL start call the C code 1 4 2 Startup routines These routines are C source code found in the files start c and sysinit c This code provides general system initialization that may be adapted depending on the application 1 4 2 1 Disable watchdog For code development and debugging it is best to disable the watchdog This requires unlocking the watchdog first Keep in mind that there are timing requirements for the executi
51. the potentiometer on the A side and the B side ping pong That reading is filtered for an aggregate of ADC1 readings exponentially filtered result1 thus the filtered POT output is available for display K K K K k K K A k k K A k k k A k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k kk k kkk f void adcl_isr void if ADC1_SC1A amp ADC_SC1_COCO_MASK ADC SC1_COCO MASK check which of the two conversions just triggered PIN2_HIGH do this asap resultlA ADC1_RA this will clear the COCO bit that is also the interrupt flag This is the exponential filter portion for ADCIA Begin exponential filter code for Potentiometer setting for demonstration of filter effect exponentially filtered_resultl result1A exponentially filtered resultl 2 Spikes are attenuated 6dB 12dB 24dB and so on until they die out End exponential filter code add f sample divide by f 1 f is 1 for this case These cycle flags are used to keep track of which results are available at the program level cycle flags ADC1A DONE mark this step done else if ADC1_SC1B amp ADC SC1 COCO MASK ADC SC1 COCO MASK PIN2 LOW result1B ADC1 RB This is the exponential filter portion for ADCIB Begin exponential filter code for Potentiometer setting for demonstration of filter effect exponentially filtered resultl1 result1
52. through an example For example consider the case of a battery operated human interface device that requires a real time clock timebase It will wake up every second update the time of day and check the conditions of several sensors Then it will take action based upon the state and when requested perform high levels of computation to control the operation of a device After reviewing the power modes table in Module operation in low power modes you should be able to identify which of the modules are functioning in each of the low power modes At this point in this example notice that the RTC the segment LCD the TSI and the comparator are among a few modules that are fully functional in several of the lowest power modules In this example system the MCU would spend most of the time in one of the lowest power modes waking up every second to update the time of day variables and update the display plus other house keeping tasks Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 55 al Using the mode controller The MCU could also wakeup from a user input This could be hitting a button a touch of a capacitive sensor the rise or fall of an analog signal from a sensor feeding the comparator To enable these sources please refer to the LLWU section 3 for configuration details The example codes for MC are available from the Freescale Web site www freescale com 5 2 2 1 MC code example and explanation
53. to consider the source impedance and sample time rather than a simple cutoff frequency This topic cannot be discussed in detail here but the general concept is that fast sample times will require smaller capacitor values and source impedances than slow sample times Higher resolution inputs may require smaller capacitor values and source impedances than lower resolution inputs Kinetis Quick Reference User Guide Rev 0 11 2010 28 Freescale Semiconductor EE Chapter 2 General System Setup Hardware Considerations In general capacitor values can range from 10pF for high speed conversions to luF for low speed conversions Series resistors can range from a few hundred Ohms to 10k O 2 4 PCB layer stack up The Kinetis MCUs are high speed integrated circuits Care must be taken in the PCB design to ensure that fast signal transitions rise fall times and continuous frequencies do not cause RF emissions Likewise transient energy that enters the system needs to be suppressed before it can affect the system operation compatibility The guidance from high speed PCB designers is to have all signals routed within one dielectric core or prepreg of a return path which usually is a ground plane This allows return currents to predictably flow back to the source without affecting other circuits which is the primary cause of radiated emissions in electronic systems This approach requires full planes within the PCB layer stack and partial planes
54. used in periodic trigger mode These permit transfers to be initiated based only on the PIT This is shown in Figure 7 5 PIT trigger Perpherial Request fa ways mb led Channel Ac lived Figure 7 5 PIT only transfer activation 7 2 3 Multiple transfer requests Only one channel can actively perform a transfer To manage multiple pending transfer requests the eDMA controller offers channel prioritization Fixed priority or round robin priority can be selected In the fixed priority scheme each channel is assigned a priority level When multiple requests are pending the channel with the highest priority level performs its transfer first By default fixed priority arbitration is implemented with each channel being assigned a priority level equal to its channel number Higher priority channels can preempt lower priority channels Preemption occurs when a channel is performing a transfer while a Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 73 EE ee Transfer process major and minor transfer loop transfer request is asserted to a channel of a higher priority The lower priority channel halts its transfer on completion of the current read write operation and allows the channel of higher priority to work In round robin mode the eDMA cycles through the channels from the highest to the lowest checking for
55. vector table Some applications need the vector table to be located in RAM For example in an RTOS implementation the vector table needs to be in RAM this allows the Kernel to install ISRs by modifying the vector table during runtime The NVIC provides a simple way to reallocate the vector table for this purpose the user needs to set up the Vector Table Offset Register VTOR with the address offset for the new position Use the bit TBLBASE 29 to indicate the table is either on RAM with 1 or flash with O and the TBLOFF 28 7 to indicate the address offset for the table The Cortex M4 assumes the RAM starts at 0x20000000 and expects the vector table to be stored in that address if the VTOR TBLBASE 29 bit 1s set Because the Kinetis MCU family RAM starts at Ox 1fff0000 this bit must be cleared If the vector table is planned to be stored in RAM you must the table copy from the flash to RAM Also note that in some low power modes a portion of the RAM will not be powered which can lead to a vector table corruption In this case locate the vector table in the flash prior to entering a low power mode 3 2 2 1 Code example and explanation The vector table is usually in flash after reset This indicates that moving the table from flash to RAM is the most common action To achieve this two steps must be performed 1 Copy from flash to RAM the entire vector table The linker command file labels are useful in this step This is what the code look
56. 000011 high trip point LVWV ack to clear initial flags PMC LVDSC1 PMC LVDSC1 LVDACK MASK clear detect flag if present PMC LVDSC2 PMC LVDSC2 LVWACK MASK clear warning flag if present LVWV if LVDV high range selected Low trip point selected VLVW VLVW1 2 62 Mid 1 trip point selected VLVW VLVW2 2 72 Mid 2 trip point selected VLVW VLVW3 2 82 High trip point selected VLVW VLV4 2 92 LVWV if LVDV low range selected Low trip point selected VLVW VLVW1 1 74 Kinetis Quick Reference User Guide Rev 0 11 2010 52 Freescale Semiconductor yyy er ee ee si Chapter 5 Power Management Controller PMC MODECTL Mid 1 trip point selected VLVW VLVW2 1 84 Mid 2 trip point selected VLVW VLVW3 1 94 High trip point selected VLVW VLV4 2 04 NVICICPRO NVICISERO 1 lt lt 20 Clear any pending interrupts on LVD 1 lt lt 20 Enable interrupts from LVD module 5 1 2 3 Interrupt code example and explanation The LVD circuitry can be programmed to cause an interrupt You should create a service routine to clear the flags and react appropriately An example of such an interrupt service routine is given Notice the NVIC module references This clearing is redundant if the module clearing is done correctly void pmc_lvd_isr void printf rPMC_LVD ISR entered if PMC LVDSC2 amp PMC LVDSC2 LVWF MASK PMC LVDSC2 PMC LVDSC2 LVWACK MASK if PMC L
57. 1 Start transmit with specified tx code pFlexCANReg gt MB iTxMBNo CS pFlexCANReg MB iTxMBNo CS amp FLEXCAN MB CS CODE MASK FLEXCAN MB CS CODE txCode write activate code FLEXCAN MB CS LENGTH iNoBytes 15 2 4 Read message Before reading the message content it is necessary to lock the Rx MB After reading the message content unlock the Rx MB Polling or interrupt method can be used to check an Rx MB to see whether it has received a message 15 2 4 4 Code example and explanation Here is a code example for checking the IFLAGI MB and reading the message from the Rx MB if pFlexCANReg gt IFLAG1 amp 1 iMB Read the Message content information clear flag pFlexCANReg gt IFLAG1 1 iMB This code is used to read the message content Lock the MB code FLEXCAN get code pFlexCANReg MB iMB CS length FLEXCAN get length pFlexCANReg MB iMB CS format pFlexCANReg gt MB iMB CS amp FLEXCAN MB CS IDE 1 0 id pFlexCANReg gt MB iMB ID amp FLEXCAN MB ID EXT MASK if format standard ID id gt gt FLEXCAN MB ID STD BIT NO else id CAN MSG IDE MASK flag extended ID format pFlexCANReg gt MB iMB CS amp FLEXCAN MB CS RTR 1 0 if format xid CAN MSG TYPE MASK flag Remote Frame type Read message bytes wno length 1 gt gt 2 bno length 1 if wno gt 0 uint32 pBytes pFlexCANReg gt MB iMB WORD
58. 13 USB Device Charger Detection USBDCD Module K OVIE Enn gabe ut Mri I DN pad e de aii IR URDU CIMA A UI dubii eii LB LM Id 121 IESU E 121 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor Section Number Title Page cm B TSR P 121 15 1 3 Battery charger SSCA enu eire A aR Cro da ede tl Rv ELT ls ODER Id edel Fui Ie dre sli EYE dial 122 12 2 Muigule t anie BERE accio eei eei a ede OQ RR cba n Hr EE etd d a eR E EN REA 122 LX MOS Ge eee EG ois eas ROI apnd sera PL ebd ERR PER HHHH 122 13 3 DCD hardware uiplementotlofi asii aeae depu E du bm sn be EU e E E Bs ES Esin e T 124 Chapter 14 Universal Serial Bus OTG Module Er Tio T e AE AA EAA 127 ENS I o T 127 LE MES Oper aot MaRS usu odds eU evi PAY AT EN I N AEAT e ra EF UR E PELO EP EIKEI EM RR HERO EO a prd odd 127 Ls Wolaserbeulstor EE HO Mies io Lauree i rebel scans bl utere buco cp pH UE E EXE Taa nrar Tiga NM dA 128 po Ne A T E EA ea ceca ncaa aces AE E A Ie N EE COMPE E CaS YE evi DEEN d HERD igus tae 130 IN MESI ICE ean sre NR dT 130 1132 USB aa SD PEDE ap a cata bans a La du eda ie REA I gases pose MER cH cate a cab dd bx Ule dabieeaasebuaaglandauned 130 1433 Volare reculit TE T obere cuida tie ordi pcqia s CubQu e a A itta dues buda 132 Ib Heniwateamplernufalbcl ceca ed d p lapide e ooo Ria Tand E Talan aaa
59. 2 porte isr Replace ISR NVICICPR2 1 27 Clear pending interrputs on Port E NVICISER2 1 27 Enable interrupts from Port E Then there is a need for an interrupt service routine for the LLWU and one for the port enabled as a wakeup source 5 3 2 4 Wakeup sequence The wakeup sequence is not obvious for some of the modes For most of the wait and stop modes code execution follows a predictable flow For LLS mode which requires the LLWU the LLWU vector is fetched and taken right after the wakeup event If the wakeup source s interrupt flag is not cleared by the LLWU interrupt handler then the next interrupt vector for the wakeup source is taken and the flag in the port or module can be cleared Code execution then continues with the instruction following the WFI instruction that sent the MCU into the low power mode For VLLS1 VLLS2 or VLLS3 the exit is always through the reset vector and then through the interrupt vector of the LLWU There is a WAKEUP bit in the SRS register that allows the user to tell if the reset was due to an LLWU wakeup event An example of wakeup test code is shown here if MC SRSL amp MC SRSL WAKEUP MASK printf outSRS Pin Reset wakeup from low power modes Wn The state of PMCTRL LPLLSM prior to clearing due to update of PMPROT indicates which power mode was exited and should be used by initialization software for proper power mode recovery if MC PMCTRL amp MC PMCTRL LPLLSM
60. 82 GPIO DDRQS 0x08 CSO as output MCF5282 GPIO PORTQS 0x08 Drive CSO HIGH set up wrap register for a single 8 bit transfer MCF5282 QSPI QWR MCF5282 OQSPI QWR CSIV Enable QSPI Pins MCF5282 GPIO POSPAR Ox7F Configure as GPIO pins to monitor RSTOUT pins and assert RCON MCF5282 GPIO PQSPAR 0x0 GPIO function MCF5282 GPIO DDRQS 0x28 CS0 and CS2 as output MCF5282 GPIO PORTOS 0x28 Drive RCON HIGH amp RSTIN HIGH MCF5282 GPIO PORTOS 0x08 Drive RCON HIGH amp RSTIN LOW while data in amp 0x10 wait till RSTOUT LOW data in MCF5282 GPIO PORTOSP MCF5282 GPIO PORTOS 0x20 Drive RCON LOW amp RSTIN HIGH while data in amp 0x10 wait till RSTOUT HIGH data in MCF5282 GPIO PORTOSP Exiting reset and entering EZPORT mode MCF5282 GPIO PORTQS 0x28 Drive RCON HIGH again Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 89 Using the EzPort module 9 1 2 2 Write enable and disable Before issuing a write command SP SE BE WRFCCOB or WRFLEXRAM in the Ezport module first enable the WEN bit in the status register with the WREN command After those commands are completed the WEN bit will automatically clear so next time you issue another write command the WREN command should be issued again Example code ezp wren cmd ezp write byte EZPORT WREN while MCF5282 OSPI OIR amp MCF5282 QSPI QIR SPIF
61. A trigger Each channel of the Kinetis eDMA module can be triggered to start DMA transfer of multiple sources from peripherals or software The eDMA module integrates the DMA Mux to route a different trigger source to the 16 channels With the DMA Mux up to 63 events occurring within other peripheral modules can activate an eDMA transfer In many modules event flags can be asserted as either eDMA or Interrupt requests These sources can be selected through DMAMUX CHCFGn SOURCE registers But different devices may have different peripheral source configurations Refer to the device specific reference manual for details Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 71 SE LLLLLLUAGUALuL LIANLLIULULUIAA LLAZCOUULULEX1 LL LU4LLLLZZZZLZEE eDMA trigger 7 2 1 DMA multiplexer The DMA channel Mux helps to configure the eDMA source 52 peripheral slots and 10 always on slots can be routed to 16 channels The first four channels additionally provide periodic trigger functionality And each channel router can be assigned to one of the 52 possible peripheral DMA slots or to one of the 10 always on slots The logic structure of the DMA Mux is illustrated in Figure 7 3 OLI L Lid TIE Source 0 Disable Source 1 RSV h Source 2 channel 1 channel 2 Source 53 channel 3 channel 4 always enabled 1 A channel 5 always enabled 10 eDMA channel 15 Figure 7 3 DMA Mux
62. A4 configMAC ADDR5 H Enable the ENET clock SIM SCGC2 SIM SCGC2 ENET MASK FSL allow concurrent access to MPU controller Example ENET uDMA to SRAM otherwise bus error MPU CESR 0 prvInitialiseENETBuffers Set the Reset bit and clear the Enable bit ENET ECR ENET ECR RESET MASK Wait at least 8 clock cycles for usData 0 usData lt 10 usData asm NOP FSL start MII interface mii init 0 periph clk khz 1000 MHz enet interrupt routine Set irq priority 76 6 enable irq 76 ENET xmit interrupt enet interrupt routine Set irq priority 77 6 enable irq 77 ENET rx interrupt enet interrupt routine Set irq priority 78 6 enable irq 78 ENET error and misc interrupts Make sure the external interface signals are enabled PORTB PCRO PORT PCR MUX PORT PCR MUX PORTB PCR1 Hif configUSE PORTA PCR14 PORTA PCR5 PORTA PCR12 PORTA PCR13 PORTA PCR15 PORTA PCR16 PORTA PCR17 MII MODE PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX 4 GPIO RMIIO MDIO MIIO MDIO 4 GPIO RMIIO MDC MIIO MDC 4 RMIIO CRS DV MIIO RXDV 4 RMIIO RXER MIIO RXER 4 RMIIO RXD1 MIIO RXD1 4 RMIIO RXDO MIIO RXDO 4 RMIIO TXEN MIIO TXEN 4 RMIIO TXDO MIIO TXDO 4 RMIIO TXD1 MIIO TXD1 Kinetis Quick Reference User Guide Rev 0 11 2010 110
63. AN is out of freeze mode MCR FRZ_ACK 0 15 2 2 Receive process FlexCAN requires three steps to configure an MB as an Rx MB to initiate a receive process 15 2 2 1 Code example and explanation The receive process to prepare a Rx MB is Deactivate the rx MB for cpu write pFlexCANReg MB iMB CS LEXCAN MB CS CODE FLEXCAN MB CODE RX INACTIVE Write ID id2 id amp CAN MSG IDE MASK CAN MSG TYPE MASK if id amp CAN MSG IDE MASK pFlexCANReg gt MB iMB ID id2 else pFlexCANReg gt MB iMB ID id2 FLEXCAN MB ID STD BIT NO Activate the MB for rx pFlexCANReg MB iMB CS FLEXCAN MB CS CODE FLEXCAN MB CODE RX EMPTY 15 2 3 Transmit process FlexCAN requires four steps to configure an MB as a Tx MB to initiate a transmit process 15 2 3 1 Code example and explanation The transmit process to prepare and start a Tx MB is Follow 4 steps for Transmit Process pFlexCANReg MB iTxMBNo CS FLEXCAN MB CS CODE FLEXCAN MB CODE TX INACTIVE write inactive code wno FLEXCAN MB CS IDE BIT NO bno lt lt FLEXCAN MB CS RTR BIT NO pFlexCANReg gt MB iTXMBNo ID prio lt lt FLEXCAN MB ID PRIO BIT NO msgID amp CAN MSG IDE MASK CAN MSG TYPE MASK lt lt i pFlexCANReg gt MB iTxMBNo WORDO word 0 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 145 Configuration examples pFlexCANReg gt MB iTxMBNo WORD1 word
64. Analog to Digital Converter ADC Conversions 18 1 Overview This chapter will demonstrate how to use the PDB module to schedule and perform ADC conversions of the analog voltage available from the on board demonstration potentiometer The application will sense the potentiometer control and report it over the serial port The code example shows how to Make a low level driver for the ADC Configure the ADC for averaging a single ended voltage conversion Use the bus clock to clock the ADC Use a simple exponential filter on the averaged results Have the ADC conversions scheduled at time intervals determined by the PDB module Calibration of the ADC is also illustrated 18 1 1 Introduction Timing of ADC conversions relative to system events is a key to applications such as motor control and metering requiring timing of ADC conversions for the best time to get a noise reduced reading When the Kinetis MCU is acting as a controller it will output control changes from time to time Scheduling ADC conversions around these changes which may make transient disturbances in the system is key Scheduling the ADC conversions at a time after the transient effects of the last control change has been made can enable smooth operation of control loops The PDB allows simple scheduling of one or both of the ADC peripherals conversions Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 167 JAE Overview
65. B exponentially filtered result1 2 Spikes are attenuated 6dB 12dB 18dB and so on until they die out End exponential filter code add f sample divide by f 1 f is 1 for this case Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 173 PCB design recommendations cycle flags ADC1B DONE return 18 2 2 ADC device hardware implementation The ADC input pins are generally configured with a small inexpensive RC filter The R value is typically 100 Ohms and the C value is chosen to assure adequate roll off of frequencies above the Nyquist frequency which is the sampling frequency divided by two The advantage of a high sampling rate made possible by the Kinetis ADC PDB combination is that smaller RC values may be used for the anti aliasing filter 18 2 3 PDB device hardware implementation The PDB itself can be triggered by hardware There are two ball locations that are available for serving as external triggers for the PDB No special considerations for these but it is advised to use only one not both of the two ball locations for the hardware trigger of the PDB 18 3 PCB design recommendations 18 3 1 Layout guidelines 18 3 1 1 General routing and placement Use the following general routing and placement guidelines when laying out a new design These guidelines will help to minimize signal quality problems The ADC validation efforts focused on providing very sta
66. CHOC1 EN 0x02 PDB CHOC1 TOS 0x02 ADCO DLYA ADCO DLYB pretrigger 0 and 1 enabled and delayed PDB CH1C1 EN 0x01 PDB CH1C1 TOS 0x01 PDB CH1C1 EN 0x02 PDB CH1C1 TOS 0x02 ADC1 DLYA ADC1 DLYB DB SC CONT MASK DB SC PDBEN MASK DB SC PDBIE MASK DB SC PRESCALER 0x5 DB SC TRGSEL O0xf PDB SC MULT 2 clock PDB SC LDOK MASK this time Continuous rather than one shot mode PDB enabled PDB Interrupt Enable Slow down the period of the PDB for testing Trigger source is Software Trigger to be invoked in Multiplication factor 20 for the prescale divider for Need to ok the loading or it will not load certain the software trigger PDB SC SWTRIG MASK is not 18 2 1 4 Determine ADC configuration Set up the initial ADC default configuration This configuration is set into a structure where it can be reused as required prior to and after calibration for either ADC Master Adc Config CONFIG1 Master Adc Config Master Adc Config Master Adc Config Master Adc Config Master Adc Config CONFIG2 STATUS3 PGA COMPARE1 0x1234u COMPARE2 0x5678u STATUS2 ADTRG HW CAL OFF ADCO SINGLE AVGE ENABLED ADC SC3 AVGS AVGS 32 ADLPC NORMAL ADC CFG1 ADIV ADIV 4 ADLSMP LONG ADC CFG1 MODE MODE 16 ADC CFG1 ADICLK ADICLK BUS MUXSEL ADCA ADACKEN DISABLED ADHSC HISPEED ADC CFG2 ADLSTS ADLSTS 20 T can be anything can be anythi
67. E Flash 2 EEESPLIT EEESIZE EEESPLIT EEESIZE Record_Efficiency Endurance_Factor Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 83 Using the FlexNVM Endurance_subsystem 64KB 2 5 4KB 5 4KB 5 10 000 Endurance_subsystem 60KB 2KB 5000 Endurance_subsystem 30 5000 Endurance_subsystem 150000 Kinetis Quick Reference User Guide Rev 0 11 2010 84 Freescale Semiconductor Chapter 9 EzPort Module 9 1 Using the EzPort module 9 1 1 Overview This section demonstrates how to use the Ezport module for in system programming ISP of Kinetis on chip flash memory 9 1 1 1 Introduction The Ezport module provides a serial programming interface that allows reading erasing and programming Kinetis on chip flash memory in a compatible format with many stand alone flash memory chips Kinetis has two functional modes single chip mode default and Ezport mode for ISP programming The mode entered depends on both the EZPCS state during reset and the Ezport disable bit in FOPT register as shown in Table 1 Table 9 1 Mode selection during reset External conditions during reset Mode entered EZPCS 1 Single chip mode EZPCS 0 amp amp FOPT EZPORT_DIS 0 Single chip mode EZPCS 0 amp amp FOPT EZPORT_DIS 1 Ezport mode 9 1 1 2 Features The Ezport module has these features Implements a subset of SPI format supporting either of the following
68. ER DMA Request CITER 1 Figure 7 6 Major and minor transfer loops 7 4 Configuration steps To configure the eDMA the following initialization steps must be followed L Write the eDMA control register only necessary if the configuration of another than the default is required Configure channel priority registers in the DCHPRIn if necessary Enable error interrupts using either the DMAEEI or DMASEEI register if necessary Write the transfer control descriptors for channels that will be used Configure the appropriate peripheral module and configure the eDMA MUX to route the activation signal to the appropriate channel All transfer attributes for a channel are defined in the unique TCD for the channel Each 32 bit TCD is stored in the eDMA controller module Only the DONE ACTIVE and STATUS fields are initialized at reset All other TCD fields are undefined at reset and must be initialized by the software before the channel is activated Failure to do this results in unpredictable behavior Refer to the device specific reference manual for the TCD detail description Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 75 Ee Example PIT gated DMA requests 7 5 Example PIT gated DMA requests In this example the eDMA is used to supply the analog to digital converter with a command word and move the result of AD to a location in the internal SRAM The AD command word stores al
69. Enable clock gates Both the TSI and the PORTA clock gates are enabled PORTA clock gate is enabled because TSI channel 5 is shared with PORTA 4 This pin does not have the TSI as a primary function It is necessary to change the pin function to Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 161 EE TSI configuration the TSI with the multiplexing bits in the PORTA pin control register PCR All other TSI pins are enabled by default 2 Configure the general control and status register GENCS Configure the number of scans prescaler which is a multiplier for the number of scans Additionally it is possible to enable the continuous scan mode STM bit as well as TSI interrupts error detection low power mode and whether the end of scan or out of range interrupts are requested When using low power modes it is also important to define what low power reference clock is used LPCLKS and the scanning interval for low power mode LPSCNITV 3 Configure the scan control register SCANC Allows you to define the current that charges the electrodes and the internal reference EXTCHRG and REFCHRG as well as the delta voltage DELVOL that is applied to both The other critical configuration for SCANC is the scanning period which is dependent on the active mode clock AMCLKCS the clock prescaler AMPSC and the clock modulo SMOD An internal counter counts the number of reference clock cycles as they are out
70. L22 Wre enable and disable ess divae dx PD nasal sth edad pay dec p CH dli ku e ER 90 SLS Sector erase T TET 90 124 Write and ead POCO ree TTT 9 9o Wie andread PSSESSNL a ae a die QR ea A a D te GAP cbe cuc n Ple A LAM dd 92 Chapter 10 Flexbus Module ON M Usiig the Fliexbus MOUIE t 93 WLI OVE eG 93 USING I M 93 LUNO Tg cS 93 ORLAT Signal aieeceprds pa e ie SU FE Hpeen io Pekeb Lese s EENES EXE Een vs SENEESE 93 101 1 2 2 Addpess end data bus multiplexing sonit seann iniiae aai 94 LL23 Modes R Cortos iudss ie E E EAE 95 MILA MEL Ne le o I 96 10 1 1 25 Date Byte Alignment and Physical ConpnectDons cisicocsocesssecoisorsecosavtanianansytsoeseodeabuevanes 96 LINES ME i i qr ere E 97 TOLLA BRS T a 97 IOLL ME CEU E SIE cnni icena RAT R A EA E E 98 10 1 1 3 1 Code example and explanalloti iuee reete bene oet e ken ex rU cec e rU o vod Ud KE npe qrUge US 98 INN Hardware implementato E 99 IOL PCG design recomiendan casos Gase phe be xe RE Pto dirus Darei E ae 100 jp UU SILIO CNSR C 100 Chapter 11 Universal Asynchronous Receiver and Transmitter UART Module Wig A NE P N amm ce messienmueaiaats 101 E PMO A E magia eae naa 101 Kinetis Quick Reference User Guide Rev 0 11 2010 8 Freescale Semiconductor Section Number Title Page IBN Son ae aL nw 102 MUR VART Suen TU 102 MM UAR TIONES E aa ceeetpceade NG
71. LONG amp xENETRxDescriptors O Point to the start of the circular Tx buffer descriptor queue ENET TDSR unsigned portLONG xENETTxDescriptors Clear all ENET interrupt events ENET EIR unsigned portLONG 1 Enable interrupts ENET EIMR ENET EIR TXF MASK ENET EIMR RXF MASK ENET EIMR RXB MASK ENET EIMR UN MASK ENET EIMR RL MASK ENET EIMR LC MASK ENET EIMR BART MASK ENET EIMR BABR MASK ENET EIMR EBERR MASK Create the task that handles the MAC ENET RX RTOS TCP IP stack dependent Enable the MAC itself ENET ECR ENET ECR ETHEREN MASK Indicate that there have been empty receive buffers produced ENET RDAR ENET RDAR RDAR MASK static void prvInitialiseENETBuffers void unsigned portBASE TYPE ux unsigned char pcBufPointer pcBufPointer KL xENETTxDescriptors unaligned 0 while unsigned long pcBufPointer amp OxOfUL 0 pceBufPointer xENETTxDescriptors NBUF pcBufPointer pcBufPointer KL xENETRxDescriptors unaligned 0 while unsigned long pcBufPointer amp OxOfUL 0 pceBufPointer Kinetis Quick Reference User Guide Rev 0 11 2010 112 Freescale Semiconductor UE Chapter 12 ENET Module xENETRxDescriptors NBUF pcBufPointer Setup the buffers and descriptors pcBufPointer amp ucENETTxBuffers O while unsigned long pcBufPointer amp OxOfUL
72. M_ACK 0 Wait until FlexCAN goes into freeze mode MCR FRZ_ACK 1 Initialize other MCR bits as needed a Enable the individual filtering per MB and reception queue features by setting MCR IRMQ bit Enable the warning interrupts by setting the MCR WRN_EN bit Disable self reception by setting the MCR SRX DIS bit Enable the RxFIFO by setting MCR RFEN bit Enable the abort mechanism by setting the MCR AEN bit Enable the local priority feature by setting the MCR LPRIO_EN bit 7 Configure baud rate and initialize CTRL1 amp CTRL2 bits as needed a Determine the bit timing parameters PROPSEG PSEGI PSEG2 RJW b Determine the bit rate by programming the PRESDIV field c Determine the internal arbitration mode LBUF bit QN tA 4 C2 WN 00 0m7 8 Initialize the message buffers MB by executing transmit process for Tx MBs and receive process for Rx MBs 9 Initialize the ID filter table if Rx FIFO was enabled 10 Initialize the Rx Individual Mask Registers RXIMRn if individual Rx masking and queue is enabled MCR IRMQ 1 Kinetis Quick Reference User Guide Rev 0 11 2010 144 Freescale Semiconductor Chapter 15 FlexCAN Module 11 Enable the corresponding interrupts by setting required interrupt mask bits in IMASKn register for all MB interrupts CTRLn register for Bus off amp Error interrupts and MCR register for wakeup interrupt 12 Negate the MCR HALT bit 13 Wait till FlexC
73. O swap 4bytes pBytes bno 4 pMBData uint8 amp pFlexCANReg gt MB iMB WORD1 3 Kinetis Quick Reference User Guide Rev 0 11 2010 146 Freescale Semiconductor en ee Chapter 15 FlexCAN Module else pMBData uint8 amp pFlexCANReg MB iMB WORD0 3 for i 0 i lt bno i pBytes i wno lt lt 2 pMBData Read time stamp timeStamp pFlexCANReg gt MB iMB CS amp FLEXCAN MB CS TIMESTAMP MASK Unlock the MB code pFlexCANReg gt TIMER 15 2 5 Configuration of Rx FIFO ID filter table elements The Rx FIFO ID tables or ID filter table elements are used as message acceptance filters whose ID fields function as acceptance ID code It is necessary to configure the Rx FIFO ID filter table elements in freeze mode Kinetis supports up to 40 ID tables therefore CTRL2 RFEN 4 at maximum There are three types of ID table structure formats Forma 31 30 app I 16 wer rrr Te L l l LA l l LI LII RXIDA A RIR IDE Standard 29 19 Extended 29 1 i RXIDB 0 RXIDB 1 B RIR IDE RTR IDE Standard 29 19 Extended 29 16 Standard 13 3 Extended 13 0 4 4 1 RXIDC 0 RXIDC 1 RXIDC 2 RXIDC 3 Std Ext 31 24 Std Ext 7 0 Std Ext 23 16 Std Ext 15 8 n 15 2 5 1 Code example and explanation Example code for configuring ID table in Format A if bISExtID Format A with extended
74. PCR MUX 5 fb oe b PORTD PCR15 PORT PCR MUX 5 fb rw b PORTE PCR7 PORT PCR MUX 5 fb cs0 b PORTE PCR6 PORT PCR MUX 5 fb ale 8 bit write vuint8 MRAM START ADDRESS n OxAC 8 bit read rdata8 vuint8 MRAM START ADDRESS n 16 bit write vuint16 MRAM START ADDRESS n 0x1234 16 bit read rdatal6 vuintl6 amp MRAM START ADDRESS n 32 bit write vuint32 MRAM START ADDRESS n 0x87654321 32 bit read rdata32 vuint32 amp MRAM START ADDRESS n n offset n offset n offset n n n offset offset offset Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 99 PCB design recommendations 10 1 1 4 Hardware implementation Eight data lines FB_D 7 0 and twenty four address lines FB_A 23 0 from the FlexBus module are connected to the MRAM memory in an non multiplexed mode B AD 19 0 FB AD 31 24 B CSU E FB_WE _ gt B_OE _ gt FB ALE Figure 10 5 FlexBus device external connections 10 1 2 PCB design recommendations 10 1 2 1 Layout guidelines Due to the critical timing required while driving external memories there are a number of considerations that must be taken into account during PCB layout Each group of signals traces must have identical loading and similar routing in order to maintai
75. R ch amp OxOOOOFFFF return 0 12 4 MII mode The media independent interface MII is a configuration mode that requires 18 signals to communicate to a generic PHY The MII operates at 25 MHz The synchronization signals are part of the MII external signals provided by the Ethernet PHY Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 115 J MII mode 12 4 1 Code example and explanation The following example code shows the registers needed to configure the MAC NET controller in MII mode PORTA PCR14 PORT PCR MUX 4 RMIIO CRS DV MIIO RXDV PORTA PCR5 PORT PCR MUX 4 RMIIO RXER MIIO RXER PORTA PCR12 PORT PCR MUX 4 RMIIO RXD1 MIIO RXD1 PORTA PCR13 PORT PCR MUX 4 RMIIO RXDO MIIO RXDO PORTA PCR15 PORT PCR MUX 4 RMIIO TXEN MIIO TXEN PORTA PCR16 PORT PCR MUX 4 RMIIO TXDO MIIO TXDO PORTA PCR17 PORT PCR MUX 4 RMIIO TXD1 MIIO TXD1 PORTA PCR11 PORT PCR MUX 4 MIIO RXCLK PORTA PCR25 PORT PCR MUX 4 MIIO TXCLK PORTA PCR9 PORT PCR MUX 4 MIIO RXD3 PORTA PCR10 PORT PCR MUX 4 MIIO RXD2 PORTA PCR28 PORT PCR MUX 4 MIIO TXER PORTA PCR24 PORT PCR MUX 4 MIIO TXD2 PORTA PCR26 PORT PCR MUX 4 MIIO TXD3 PORTA PCR27 PORT PCR MUX 4 MIIO CRS PORTA PCR29 PORT PCR MUX 4 MIIO COL ENET RCR ENET RCR MAX FL configENET RX BUFFER SIZE ENET RCR MII MODE MASK ENET RCR CRCFWD MASK 12 4 1 1 Hardware implementation The
76. SBR Ox1F UART RDH REG uartch UART BDL REG uartch temp UART BDH SBR ubd amp OxlF00 gt gt 8 uint8 ubd amp UART BDL SBR MASK Determine if a fractional divider is needed to get closer to the baud rate brfa sysclk 32000 baud 16 ubd 32 Save off the current value of the UARTx C4 register except for the BRFA temp UART C4 REG uartch amp UART C4 BRFA Ox1F UART C4 REG uartch temp UART C4 BRFA brfa Enable receiver and transmitter UART C2 REG uartch UART C2 TE MASK UART C2 RE MASK The initialization above can be simplified to the following steps L 2 Disable the transmitter and receiver This step is included to make sure that the Enable the UART pins by configuring the appropriate PORTx_PCRn registers not shown in the code example Enable the clock to the UART module UART is not active while it is being configured This step is not needed if the uart init function is always called while the UART is already in a disabled state the UART is disabled after reset by default Configure the UART control registers for the desired format For 8 N 1 operation no UART registers actually need to be configured the default register settings configure the UART for 8 N 1 operation Calculate the baud rate dividers This includes calculating the 13 bit whole number baud rate divider the SBR field stored in the UARTx BDH and UARTx BDL registers
77. SER2 1 lt lt 22 Enable interrupts from LCD interrupt SLCD clock gate on SIM SCGC3 SIM SCGC3 SLCD MASK Disable LCD LCD GCR amp LCD GCR LCDEN MASK Configure LCD Control Register LCD GCR LCD GCR RVEN MASK LCD GCR RVTRIM 8 0 15 LCD GCR CPSEL MASK LCD GCR HREFSEL MASK LCD GCR LADJ 3 0 3 mBIT18 LCD GCR VSUPPLY 1 0 3 LCD GCR LCDIEN MASK LCD GCR FDCIEN MASK LCD GCR ALTDIV 0 0 3 LCD GCR LCDWAIT MASK LCD GCR LCDSTP MASK LCD GCR LCDEN MASK LCD GCR SOURCE MASK LCD GCR LCLK 3 0 3 LCD GCR DUTY 7 J 0 3 1 Enable LCD pins 0 32 LCD PENH 0x00000001 LCD PENL OxFFFFFFFF Enable LCD pins used as Backplanes 0 7 LCD BPENH 0x00000000 LCD BPENL 0x000000FF Configure backplane phase LCD WF3TOO 0x08040201 LCD WF7TO4 0x80402010 Fill information on what segments are going to be turned on Front Plane information LCD WF11TO8 OxFFFFFFFF LCD WF15TO12 OxFFFFFFFF Complete information of all Front planes Enable LCD module LCD GCR LCD GCR LCDEN MASK 16 7 Demonstration code The demo code allows the user to experiment with the SLCD module in real time write your own messages control contrast blinking vertical scroll experiment with the new LCD segment feature fault detection select the clock source for the module work on LCD low power modes change the frequency of operation and so on Kinetis Quick Reference User Gui
78. Software configuration First install the latest P amp E Micro Kinetis Tower Toolkit as described in the Quick Start Guide It can be found online or on the DVD that came with your Tower board This will install the necessary drivers for downloading software to the Kinetis tower board via OSJTAG the virtual serial port drivers and the P amp E terminal program You will also need to install IAR for ARM 6 10 or later It supports OSJTAG which is firmware located on your Kinetis tower board that enables you to flash and debug code with only a mini B USB cable A 3 Hardware configuration You will need to put together your tower kit for examples using Ethernet FlexCAN or USB The other examples can be ran with the Kinetis microcontroller module in stand alone mode To put together the tower system plug in the primary side of each tower board most modules will mark this side with a white stripe into the primary elevator which has the white connectors Then attach the other elevator board onto the other side of the modules The TWR ELEV box will also have instructions for putting together the tower Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 177 eaa Terminal configuration Finally connect a USB cable to the mini USB port on the Kinetis tower module This will be J16 on TWR K40X256 and J13 on TWR K60N512 When you plug in the USB cable to your board you should see some LED s on all the tower boards t
79. T printf Connected to a Standard Host if u8Error amp OxOF CHARGING HOST printf Connected to a Charging Host if u8Error amp OxOF DEDICATED CHARGER printf Connected to a Dedicated Charger The function that returns the charger type result is UINT8 DCD GetChargerType void UINT8 u8ChargerType u8ChargerType UINT8 USBDCD STATUS amp USBDCD STATUS SEQ RES MASK gt gt 16 u8ChargerType UINT8 USBDCD STATUS amp USBDCD STATUS FLAGS MASK gt gt 16 return u8ChargerType The DCD interrupt service routine Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 125 Example code void DCD ISR void USBDCD CONTROL USBDCD CONTROL IACK MASK ackowledge if USBDCD STATUS amp Ox000C0000 0x00080000 FLAG SET USBOTG CONTROL DPPULLUPNONOTG SHIFT USBOTG CONTROL enable pullup if USBDCD STATUS K 0x00400000 USBDCD STATUS amp 0x00300000 FLAG SET DCD Flag gu8InterruptFlags charger detection completed Kinetis Quick Reference User Guide Rev 0 11 2010 126 Freescale Semiconductor Chapter 14 Universal Serial Bus OTG Module 14 1 Introduction The Universal Serial Bus USB is a serial bus standard for communicating between a host controller and different types of devices USB has become the standard connection method for PCs PDAs and video games and more recently has been used on power cords This is because USB can con
80. T7 SIM SOPT7 ADCITRGSEL 0 same for both ADCs 18 2 1 3 Configure Peripheral Delay Block PDB Configure the Peripheral Delay Block PDB enable PDB pdb counter clock busclock 20 continuous triggers sw trigger and use prescaler too PDB SC PDB SC CONT MASK Continuous rather than one shot mode PDB SC PDBEN MASK PDB enabled PDB SC PDBIE MASK PDB Interrupt Enable PDB SC PRESCALER 0x5 Slow down the period of the PDB for testing PDB SC_TRGSEL 0xf Trigger source is Software Trigger to be invoked in this file PDB SC MULT 2 Multiplication factor 20 for the prescale divider for the counter clock the software trigger PDB SC SWTRIG MASK is not triggered at this time PDB IDLY 0x0000 need to trigger interrupt every counter reset which happens when modulus reached PDB MOD Oxffff largest period possible with the selections above so slow you can See each conversion channel 0 pretrigger 0 and 1 enabled and delayed PDB CHOC1 PDB CHOC1 EN 0x01 Kinetis Quick Reference User Guide Rev 0 11 2010 170 Freescale Semiconductor SSS ae ee a re ee eS a ae eee Chapter 18 Using Peripheral Delay Block PDB to Schedule Analog to Digital Converter ADC Conversions PDB CHODLYO PDB CHODLY1 channel 1 PDB CH1C1 PDB CHIDLYO PDB CHIDLY1 PDB SC P P P P P this file the counter registers triggered at PDB CHOC1 TOS 0x01 PDB
81. TX Register OxDDDDEEE Figure 7 1 DMA operational overview The Kinetis family features an enhanced Direct Memory Access eDMA controller for data movement The eDMA controller of the Kinetis family contains a 16 bit data buffer as temporary storage see Figure 7 1 Because Kinetis is a crossbar based architecture the CPU is the primary bus master hooked on the MO and M1 master port The eDMA is connected to the M2 master port of the crossbar switch Therefore the CPU and eDMA can access different slave ports simultaneously With this multi master architecture the system can make the maximum usage of the eDMA feature Figure 7 2 shows the basic architecture of the Kinetis family A specialized device may have differences refer to the device specific reference manual for details Kinetis Quick Reference User Guide Rev 0 11 2010 70 Freescale Semiconductor Chapter 7 Enhanced Direct Memory Access eDMA Controller M3 M4 M5 Crossbar switch Other Slave SRAM Figure 7 2 Crossbar switch configuration The crossbar switch forms the heart of this multi master architecture It links each master to the required slave device If both masters attempt joint access to the same slave an arbitration scheme commences eliminating the bus contention Both fixed priority and round robin arbitration schemes are available If both masters attempt to access different slaves an arbitration scheme works for the judgement 7 2 eDM
82. VDSC1 amp PMC LVDSC1 LVDF MASK PMC LVDSC1 PMC LVDSC1 LVDACK MASK NVICICPRO 1 20 Clear any pending interrupts on LVD 5 1 2 4 Hardware implementation RESET PIN The reset pin is driven out if the internal circuitry detects a reset This is true for all resets including a reset that causes a recovery from the VLLSx modes Since these could be warm starts customers who do want not their external circuitry reset do not want to connect external circuitry to the MC reset pin VDD The Vdd supply pins can be driven between 1 71 V and 3 6 V DC VBAT The VBAT supply pins can be driven independently from VDD but should be powered up to at least VBATmin Since there is no equivalent LVD circuitry for the VBAT supply the VBAT minimum is the POR release point POR max 1 5 V External bypass capacitors should be supplied XTAL32 and EXTAL32 Connected to a secondary watch crystal for supplying clock to the RTC module No load capacitors or bias resistor is required as these are supplied internally Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 53 Using the mode controller 5 2 Using the mode controller 5 2 1 Overview This section will demonstrate how to use the Mode Controller MC The MC is responsible for controlling the entry and exit from all of the run wait and stop modes of the MCU This module works in conjunction with the PMC and the LLWU to wakeup the MCU and move betw
83. VLPR or wait mode the MCG must be set in a low power low frequency mode with MCGCLKOUT 2 MHz This mode is provided by means of selecting the fast IRC when the MCG is set in BLPI mode This example shows how to move to this clock mode from PLL engaged external mode before entering VLPR and then returns to that mode after VLPR is exited In VLPR mode the system clock dividers cannot be changed These dividers should be configured when the MCG is in BLPI mode before the MCU power mode is changed to VLPR 4 3 2 1 Code example and explanation Moving from PEE to BLPI first move from PEE to PBE MOG C1 MCG C1 CLKS 2 select external reference clock as MCG OUT Wait for clock status bits to update indicating clock has switched while MCG S amp MCG S CLKST MASK gt gt MCG S CLKST SHIFT 0x2 now move to FBE mode make sure the FRDIV is configured to keep the FLL reference within spec MCG C1 amp MCG C1 FRDIV MASK clear FRDIV field MOG Ci MCG C1 FRDIV 3 set FLL ref divider to 256 MCG C6 amp MCG C6 PLLS MASK clear PLLS to select the FLL while MCG S amp MCG S PLLST MASK Wait for PLLST status bit to clear to Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 45 Configuration examples indicate switch to FLL output now move to FBI mode MCG C2 MOG C2 IRCS MASK set the IRCS bit to select the fast IRC set CLKS to 1 to select the in
84. a pending request When a channel with a pending request is reached it is allowed to perform its transfer After the transfer has been completed the eDMA continues to cycle through the channels looking for the next pending request 7 3 Transfer process major and minor transfer loop Each channel requires a 32 byte transfer control descriptor TCD for defining the desired data movement operation The channel descriptors are stored in the eDMA local memory in sequential order Each time a channel is activated and executes n bytes are transferred from the source to the destination This is referred to as a minor transfer loop A major transfer loop consists of a number of minor transfer loops and this number is specified within the TCD As iterations of the minor loop are completed the current iteration CITER TCD field is decremented When the current iteration field has been exhausted the channel has completed a major transfer loop Figure 7 6 shows the relationship between major and minor loops In this example a channel is configured so that a major loop consists of three iterations of a minor loop The minor loop is configured as a transfer of 4 bytes Kinetis Quick Reference User Guide Rev 0 11 2010 74 Freescale Semiconductor Chapter 7 Enhanced Direct Memory Access eDMA Controller Source Data Transferred DMA Request Pytes n 4 Minor Loop channel activated CITER DMA Request Time Major Loop CIT
85. able the external oscillator LP 0 low power mode not selected not actually part of osc setup IRCS 0 slow internal ref clock selected not actually part of osc setup MCG C2 MCG C2 RANGE 1 MCG C2 HGO MASK MCG C2 EREFS MASK Select ext oscillator reference divider and clear IREFS to start ext osc CLKS 2 select the external clock source FRDIV 3 set the FLL ref divider to keep the ref clock in range even if FLL is not being used 8 MHz 256 31 25 kHz ITREFS 0 select the external clock IRCLKEN 0 disable IRCLK can enable it if desired IREFSTEN 0 disable IRC in stop mode can keep it enabled in stop if desired MCG C1 MCG C1 CLKS 2 MCG C1 FRDIV 3 wait for oscillator to initialize while MCG S amp MOG S OSCINIT MASK wait for Reference clock to switch to external reference while MCG S amp MCG S IREFST MASK Wait for MCGOUT to switch over to the external reference clock while MCG S amp MCG S CLKST MASK gt gt MCG S CLKST SHIFT 0x2 Now configure the PLL and move to PBE mode set the PRDIV field to generate a 4MHz reference clock 8MHz 2 MCG C5 MCG C5 PRDIV 1 PRDIV 1 selects a divide by 2 Kinetis Quick Reference User Guide Rev 0 11 2010 44 Freescale Semiconductor p M R1 Chapter 4 Clocking System set the VDIV field to 0 which is x24 giving 4 x 24
86. ace length as short as possible As traces becomes longer the baseline capacitance increases and is also more susceptible to coupled noise 4 Electrode traces must be routed in a different layer from the one containing the electrodes 5 Components and traces must not be placed directly underneath the electrodes area Good results can be obtained if the number of components behind the electrodes is minimized and running as few traces as possible It is always important to consider ground planes A ground plane below and around the electrodes adds noise suppression and a reference ground for the electrodes The problem is that a continuous ground plane below the electrodes also increases the base capacitance causing the touch delta to be reduced To work around this issue an x hatch ground plane is recommended as in Figure 17 8 The x hatch pattern helps with filtering out noise Because the area is smaller it will not increase the base capacitance as much as a continuous plane and thus does not affect sensitivity as much Figure 17 8 Recommended x hatch ground plane pattern X hatch pattern on BOTTOM side underneath electrodes Electrodes placed on Top layer Filled ground plane in Top and bottom for analog and digital circuitry including proximity sensing wiring Kinetis Quick Reference User Guide Rev 0 11 2010 166 Freescale Semiconductor Chapter 18 Using Peripheral Delay Block PDB to Schedule
87. addr int data int timeout Clear the MII interrupt bit ENET EIR ch ENET EIR MII MASK Initiatate the MII Management write RNET MMFR ch 0 ENET MMFR ST 0x01 ENET MMFR OP 0x01 ENET MMFR PA phy addr ENET MMFR RA reg addr ENET MMFR TA 0x02 RNET MMFR DATA data Kinetis Quick Reference User Guide Rev 0 11 2010 114 Freescale Semiconductor p eel Chapter 12 ENET Module Poll for the MII interrupt interrupt should be masked for timeout 0 timeout lt MII TIMEOUT timeout if ENET EIR ch amp ENET EIR MII MASK break if timeout MII TIMEOUT return 1 Clear the MII interrupt bit ENET EIR ch ENET RIR MII MASK return 0 BRK KR kk k k k RK k k k k k k k k k k k k k k k k k k Sk Sk k J int mii read int ch int phy addr int reg_addr int data int timeout Clear the MII interrupt bit ENET EIR ch ENET EIR MII MASK Initiatate the MII Management read ENET MMFR ch 0 ENET MMFR ST 0x01 ENET MMFR OP 0x2 ENET MMFR PA phy addr ENET MMFR RA reg addr ENET MMFR TA 0x02 Poll for the MII interrupt interrupt should be masked for timeout 0 timeout lt MII TIMEOUT timeout if ENET EIR ch amp ENET EIR MII MASK break if timeout MII TIMEOUT return 1 Clear the MII interrupt bit ENET EIR ch ENET EIR MII MASK data ENET MMF
88. age Regulator The USB transceiver power line comes directly from the VOUT33 voltage regulator output Therefore the regulator must be enabled to make sure that the pull up is present when needed 13 3 DCD hardware implementation The basic connection to use the DCD module is the differential lines routed to the USB connector with the proper coupling resistors and an I O signal sensing the VBUS pin Remember that the Kinetis family has 5 V tolerant pins meaning that there is no need to add a level shifter or resistor divider to sense the VBUS line USB Connector VBUS Sense Port DCD USB 2 0 Full speed Figure 13 1 DCD hardware diagram Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 123 EPA Example code 13 4 Example code The DCD example code sends a message to a terminal showing what type of host is attached to the USB module To be able to test the three different types of hosts it is necessary to have a special tool Because the standard is new only a few companies have support for this The tool that Freescale uses is the Allion USB battery Charging Test feature Using this tool and a regular PC is enough to emulate any host and test the DCD module For more information about the Allion USB battery Charging Test feature go to http www allion com TestTool USB_Charging pdf The code waits until the USB cable is attached sending 5 V to PTBO After the software dete
89. aken for a each specific Ethernet PHY manufacturer The CRSDV function may be located in either pin The hardware considerations from the PHY to the Ethernet Magnetics or the RJ45 connector are supplied from the PHY manufacturer 12 6 PCB Design Recommendations ENET interface signals function at 25 or 50 MHz Design guidelines must be followed 12 6 1 Layout Guidelines Each vendor implementation guide must be closely followed The quality of the Ethernet connection is many times dependent on board routing magnetics quality and the configured mode of operation for the PHY 12 6 1 1 General Routing and Placement Use the following general routing and placement guidelines when laying out a new design for the ENET Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 119 PCB Design Recommendations Series termination guidelines must be placed as close as possible to the origin of the signal This must be followed by PHY and ENET outputs When working in RMII mode a 50 MHz external reference must be connected to the EXTAL pin Then the MII RMII interface is able to communicate with the PHY which uses the same clock If your PHY clock presents an output delay compared to the input clock this delay must be properly matched frequency and phase to the EXTAL pin or data corruption occurs Some PHYs output a 50 MHz clock which must be used for the MCU EXTAL pin Follow your PHY specifications and c
90. al port To run this demo it is necessary to have a 48 MHz frequency out of the USB clock After the board is connected the PC requests a driver Point to the Freescale CDC Driver kinetis inf file to install the device on your computer In the Device Manager window a Freescale CDC device will be found after the enumeration process is completed loxi Ele Action dew Help e m d amp um x X Ng Network adapters B PCMCIA adapters 2 Ports COM amp LPT X Communications Port COMI Freescale CDC Device COM4 1 i al Der JY RIM Virtual Serial Port v2 COM6 f Processors XQ Smart card readers C Sound video and game controllers System devices Universal Serial Bus controllers hd Figure 14 13 Windows device manager Then open HyperTerminal pointing to the COMx device in this case COM4 with 8 bit size 1 stop bit no flow control 9600 baudrate and begin typing in the terminal The software running in the MCU returns the same characters Kinetis Quick Reference User Guide Rev 0 11 2010 136 Freescale Semiconductor Chapter 14 Universal Serial Bus OTG Module iojxi De Edt yow Cal Transfer thp Dis 213 ca Freescale Kinetis family _ D Connected 0 00 13 ANSIW 9600 8 N 1 NUM Figure 14 14 HyperTerminal window 14 7 2 Host code Host operation is more complex than the device in terms of software stack and task handling However it is less time dependen
91. approximately 1 kHz that is available in all run and low power modes 4 3 Configuration examples The MCG can be configured in one of several modes to provide a flexible means of providing clocks to the system for a wide range of applications Some of the more commonly used modes are described in the following configuration examples After exiting reset or recovering from a very low leakage state the MCG will be in FLL engaged internal FEI mode with MCGCLKOUT at 20 97 MHz assuming a factory trimmed slow IRC frequency of 32 768 kHz If a different MCG mode is required the MCG can be transitioned to that mode under software control Although not included in the sample code you should include a timeout mechanism when checking the status bits within the MCG After making changes to clock selection bits enabling the oscillator or the PLL the appropriate status bits should be verified before continuing If for some reason the bit being checked does not update the while loop will never exit unless a timeout mechanism is used A timeout counter should be started before checking the status bits This counter must then be stopped and reset after the loop exits If a timeout is generated a decision can be made about what to do depending on the status bits that failed to update For example if the oscillator does not Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 43 Configuration examples start due to
92. arge pump clock LADJ 1 0 Configure LCD power supply VSUPPLYT 1 0 Configure LCD frame frequency interrupt LCDIEN bit Configure LCD behavior in low power mode LCDWAIT and LCDSTP bits Configure LCD duty cycle DUTY 2 0 Select and configure LCD frame frequency LCLK 2 0 6 Enable pins to be used LCD PENH LCD PENL 7 Enable LCD pins to be used as BackPlanes LCD BPENH LCD BPENL 8 Configure the phase of the backplanes LCD WHY TOY used as backplanes 9 Configre the AR register 10 Enable the LCD module This is the code snippet for the SLCD intialization Code Snippet SLCD Initialization enable clock gate for Ports SIM_SCGC5 SIM SCGC5 LPTIMER MASK SIM SCGC5 REGFILE MASK SIM SCGC5 TSI MASK SIM SCGC5 PORTA MASK SIM SCGC5 PORTB MASK SIM SCGC5 PORTC MASK SIM SCGC5 PORTD MASK SIM SCGC5 PORTE MASK Master General Purpose Control Register Set mux to LCD analog operation After RESET these register are configured as 0 but indicated here for reference PORTB PCRO PORT PCR MUX 0 LCD PO PORTB PCR1 PORT PCR MUX 0 LCD P1 PORTB PCR2 PORT PCR MUX 0 LCD P2 Complete for all used pins Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 153 Demonstration code Configure NVIC for SLCD interrupt SLCD interrupt vector 102 NVICICPR2 1 lt lt 22 Clear any pending interrupts on LCD NVICI
93. ase D LT EE UE 20 20 POL FOUDUS COISSIN OS Lorie iecit i Purse ee es pivi asen catis hou eedpertp RM Con eS MELKEO bre ERU EEEE PUMP espe RE MO EOS 21 Zal Fowersuppiy TOUNO caier aa E AE EA EOR AA E aA anie 21 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor Section Number Title Page 234 Powersupply decoupling and TENNE uoc tre ttem dien ese a ox RER A eee anne 21 PACK MEL rio P 23 Sos ETC QscUl BEIGE acute N E acea ka RUD o GERONA E E rU RT iu 23 Peo gee UC SAO e 24 P Y cic aM Paste sla Sea egiaa cata eres nn aaecccdcab e moe af eco RESET Pand INVII T P acd R T A OB TTT 28 Lao AOE s term 28 BAR AEP SU Ah eiecti dini ibis eisbes quac dt ashe ap tuaie de ahaidienbav ido bando Md M cal u nepaataatmnvaniolammunin apa ui dui capluR iuncta 29 2 5 E module hardware consideram cupido edo abe Hi IE PHI SH HA bd dc le Mp Saab tania abl Up OUR Uode d dptui du ib opone uidi diia 31 ee 3 7 secs E 31 2532 Wal scqektedos TIODH IS aeu dr Recte de R UR Puteo RE pen eni Ree 32 P Derug RETA c E 32 Chapter 3 Nested Vector Interrupt Controller NVIC LN S S a P tanabeniasantabiidusdads 33 dl 70 5 In 33 ENSE T ren 33 LEO WE ii s 36 321 Configuring the NVC sarn 36 3 1 1 Code example
94. atic pins OFF Pins Latched Latched FlexBus Static FF FF Static Static OFF CRC Static FF FF Static Static OFF RNGB Static FF Static Static Static OFF CMT Static FF FF Static Static OFF NVIC Static FF FF Static Static OFF Mode Controller FF FF FF FF FF FF LLWU Static Static Static Static FF FF Regulator ON Low Pwr Low Pwr Low Pwr Low Pwr Low Pwr LVD ON Disabled Disabled Disabled Disabled Disabled LPO KHz ON ON ON ON ON ON Sys OSC ERCLK optional ERCLK lt 4MHz ERCLK lt 4MHz ERCLK lt 4MHz Limited to low Limited to low range range MCG Static IRCLK 2MHz IRC 2MHz IRC Static no clock Static no clock OFF optional PLL possible CORE CLK OFF 2MHz max OFF OFF OFF OFF Sys CLK OFF 2MHz max 2MHz max OFF OFF OFF Bus CLK OFF 2MHz max 2MHz max OFF OFF OFF FLASH Powered 1MHz max no Low Power Low Power OFF OFF pgm erase Portion of Powered Powered Powered Powered Powered Powered in SRAM U VLLS3 amp 2 Remaining Powered Powered Powered Powered Powered Powered in SRAM_U and VLLS3 amp 2 SRAML FlexMemory Powered Powered Powered Powered Powered Powered in VLLS3 Sys Reg File Powered Powered Powered Powered Powered Powered VBAT Reg File VBAT Powered VBAT Powered VBAT Powered MODULES VBAT Powered VBAT Powered DMA Static FF FF Static Static OFF UART Static WU 125 kbps 125 kbps Static WU Static OFF Table continues on the next page Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Se
95. ating correctly and stored in the memory While the product is operating the capacitance can be compared periodically to verify if there s an open connection short circuit or a substantial change in the reference capacitance that indicates a fault Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 149 Power supply 16 2 Power supply Table 16 1 shows power supply modes and suggests the use according to the environment and contrast control required Table 16 1 SLCD power supply options LCD Nominal Voltage Contrast Control Configu ration LCD Power Supply mode Noisy En viron ment Advantages Disadvantages ates VLL3 and VLL1 0 VLL1 to VIREG Volt Not rec Most rec VLLx voltages are fixed Not recommend for age internal regulator ommen ommen over a width range of noisy applications VIREG 1 0 V ded ded VDD input voltage The HREFSEL 0 Charge regulator voltage can pump generates VLL2 be trimmed RVTRIM and VLL3 for software contrast control 1 VLL1 to VIREG HREF 5V Not rec Most rec VLLx voltages are fixed Not recommend for SEL 1 VIREG 1 67V ommen ommen over a width range of noisy applications Charge pump gener ded ded VDD input voltage The ates VLL2 and VLL3 regulator voltage can be trimmed RVTRIM for software contrast control 2 VLL3 to VDD internal 3V Most rec Not rec This configuration can Contrast Co
96. aximum of 1 8 A A dedicated charging port is required to short the D line to the D line In other words the amount of current that the device is able to draw to charge the system batteries depends on the type of downstream port it is connected to 13 2 Module Configuration 13 2 1 Module dependencies The DCD module depends on other modules to operate correctly Clock Source Kinetis Quick Reference User Guide Rev 0 11 2010 122 Freescale Semiconductor E Chapter 13 USB Device Charger Detection USBDCD Module The DCD module needs a 48 Mhz clock This clock is the same as that applied to the USB module but the DCD has its own clock gating bit in the SIM SCGC6 register Make sure that the USBDCD bit is set to enable the clock source to the DCD module I O Signal The DCD module needs to know when the USB connector is plugged in This can be made using an I O signal measuring the status of the VBUS line of the USB connector When the VBUS line becomes high the software must call the start sequence routine of the DCD module see I O section for more details of the pin configuration USB Module The host detection sequence ends after the pullup resistor is enabled in the D signal Only the USB module can enable this pullup The USB module needs to be pre initialized to enable the pullup when needed and start the USB enumeration process if required only if detection results on a standard host or charging host type Volt
97. being used Kinetis Quick Reference User Guide Rev 0 11 2010 46 Freescale Semiconductor LS Chapter 4 Clocking System 4 3 3 1 Code example and explanation Using the RTC OSC as Ref Clk Configure and enable the RTC OSC select the load caps application dependent and the oscillator enable bit note that other bits in this register may need to be set depending on the intended use of the RTC RTC CR RTC CR SC16P MASK RTC CR SC8P MASK RTC CR OSCE MASK time delay ms 1000 wait for the RTC oscillator to initialize select the RTC oscillator as the MCG reference clock SIM SOPT2 SIM SOPT2 MCGCLKSEL MASK ensure MCG C2 is in the reset state key item is RANGE 0 to select the correct FRDIV factor MCG C2 0x0 Select the Reference Divider and clear IREFS to select the osc CLKS 0 select the FLL as the clock source for MCGOUTCLK FRDIV 0 set the FLL ref divider to divide by 1 IREFS 0 select the external clock IRCLKEN 0 disable IRCLK can enable if desired IREFSTEN 0 disable IRC in stop mode can keep it enabled in stop if desired MCG C1 0x0 wait for Reference clock to switch to external reference while MCG S amp MCG S IREFST MASK Wait for clock status bits to update while MCG S amp MCG S CLKST MASK gt gt MCG S CLKST SHIFT 0x0 Can select the FLL operating range freq by means of the DRS and DMX32 bits Must first ensure the system
98. ble voltage reference planes and ground planes 1 Use high quality RC components for the anti aliasing filter Place this RC filter as close to the ADC input pins as possible where it can remove the most noise 2 Provide very stable analog ground and voltage planes both for analog power and voltage references if full accuracy of the ADC is required 3 Provide very stable analog ground and voltage planes both for analog power and voltage references if full accuracy of the ADC is required Kinetis Quick Reference User Guide Rev 0 11 2010 174 Freescale Semiconductor Chapter 18 Using Peripheral Delay Block PDB to Schedule Analog to Digital Converter ADC Conversions 18 3 2 ESD EMI considerations The RC filter used for anti aliasing is all that is required to enhance ESD protection EMI interference is also dealt with by the same inexpensive filter Minimizing loop area for any RF ranged signals is also essential Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 175 Layout guidelines Kinetis Quick Reference User Guide Rev 0 11 2010 176 Freescale Semiconductor Appendix A How to Load QRUG Examples A 1 Overview This chapter describes how to load and run the sample code described in other sections of the Kinetis Quick Reference User Guide It walks through the procedures used to make sure your Tower system is connected properly and explains how to load the example projects A 2
99. cillator While the RTC oscillator can also be used as a source for the MCG module it is limited to 32 kHz The high speed oscillator that can be used to source the MCG module is very versatile The component choices for this oscillator are detailed in the device specific reference manual The placement of this crystal or resonator is described here The EXTAL and XTAL pins are located on the outside pad ring of the BGA package and on corner pins of the QFP package This allows room for placement and routing of the crystal or resonator on the top layer close to the MCU The feedback resistor and load capacitors if needed can be placed on the top layer as well See Figure 2 3 Figure 2 4 and Figure 2 5 Note that the low power modes of this oscillator do not require a feedback resistor and may not require external load capacitors Check the device specific reference manual for details This makes it as simple as possible since only one component has to be placed and routed Low power oscillators are more susceptible to interference by system generated noise so the guidelines for crystal routing are important The crystal or resonator should be located close to the MCU No signals of any kind should be routed on the layer directly below the crystal A ground plane on the layer directly below the crystal is recommended A guard ring should be placed around the crystal and its load components to protect it from crosstalk from adjacent signals o
100. clock dividers are set to keep the core and bus clocks within spec core FLL 48 MHz bus FLL 48 MHz flexbus PLL 48 MHz flash PLL 2 24 MHz SIM CLKDIV1 SIM CLKDIV1_OUTDIV1 0 SIM CLKDIV1 OUTDIV2 0 SIM CLKDIVi OUTDIV3 0 SIM CLKDIV1 OUTDIVA4 1 In this example DMX32 is set and DRS is set to 1 48 MHz from a 32 768 kHz crystal MCG C4 MCG C4 DMX32 MASK MCG C4 DRST DRS 1 4 4 Clocking system device hardware implementation It is possible to provide all the system level clocks from internal sources However if the PLL is to be used or an accurate reference clock is required an external clock must be provided This can be from an externally generated clock source that provides a square wave clock or it can be from an internal oscillator using an external crystal or resonator There are two independent on chip crystal oscillators one for the RTC and one to provide a reference for the main system clocks The RTC clock source comes only from the dedicated RTC oscillator In many cases the RTC oscillator will require only an external 32 kHz crystal The oscillator feedback resistor is integrated within the device along with selectable internal load capacitors Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 47 a Layout guidelines for general routing and placement The main system oscillator can be configured in various ways depending on the crystal frequency an
101. control register to control the digital filter enable for external pins and an acknowledge bit to allow certain peripherals and pads to release their held low leakage state 5 3 2 1 Module wakeup To configure a module to wakeup the MCU from one of the low power modes requires a study in the control and function of each of the modules capable of waking the MCU Since the RTC can be on in all low power mode we can configure the RTC to wake up Kinetis Quick Reference User Guide Rev 0 11 2010 58 Freescale Semiconductor E MM Chapter 5 Power Management Controller PHC MODECTL the system when its interrupt flag is set To do this we need to enable the RTC module to cause an interrupt and then allow that interrupt to cause a wakeup To enable the RTC to cause a wakeup the corresponding module wakeup bits must be set LLWU ME LLWU ME WUMES MASK enable the RTC to wake up from low power modes Other modules have to be enabled in the same way The table in Mode transition requirements identifies the wakeup enable bit that must be set for each module by the number of the bit 5 3 2 2 Pin wakeup To configure a pin to wakeup the MCU from the low power modes requires a study of the port configuration register controls and the GPIO functionality The PCR registers select the multiplex selection the pull enable function and the interrupt edge selection If we want to initialize the first wakeup pin PTE1 as an LLWU wak
102. cts the rising edge in the VBUS signal starts the DCD detection sequence and waits until the sequence is completed or the module sends an error notification The next three windows show the result of each host type COM1 115200baud Tera Term YT 5 xi com1 115200baud Tera Term WT joj xj Ele Edit Setup Control Window Help Ele Edt Setup Contro Window Help Software Reset Software Reset rev B M es P flash 128 kBytes of RAM Full size P flash 128 kBytes of RAN Debug Pins ON EE MIU MC eee USB DCD Module Testing w USB DCD Module Testing s Connected to a Dedicated Charger Connected to a Charging Hosti COM1 115200baud Tera Term T 5 x Ele Edk Setup Control Window Help Software Reset rev 6 Full size P flash 128 kBytes of RAM Debug Pins ON wee USB DCD Module Testing wee Connected to a Standard Hosti Figure 13 2 DCD demo results Software Explanation The software is simple This section will explain in detail how to set the clocks USB and I O pins to run the DCD example 1 First configure one I O pin as input In this example PTBO is used for the VBUS detection FLAG SET SIM SCGC5 PORTB SHIFT SIM SCGC5 Enable clock for PTB PORTB PCRO 0 PORT PCR MUX 1 configure PTBO as I O pin Kinetis Quick Reference User Guide Rev 0 11 2010 124 Freescale Semiconductor Chapter 13 USB Device Charger Detection USBDCD Module 2 Next enable the USB and the DCD cloc
103. d UART transmit function The parameters passed in to this function are the UART channel that will be used to transmit uartch and the character to be sent ch void uart putchar UART MemMapPtr channel char ch Wait until space is available in the FIFO while UART S1 REG channel amp UART S1 TDRE MASK Send the character UART D REG channel uint8 ch 11 3 4 UART configuration for interrupts or DMA requests The examples included here poll UART status flags to determine when receive data is available or when transmit data can be written into the FIFO This approach is the most CPU intensive but it is often the most practical approach when handling small messages As message sizes increase it might be useful to use interrupts or the DMA to decrease the Kinetis Quick Reference User Guide Rev 0 11 2010 104 Freescale Semiconductor SSS ee ee ene Chapter 11 Universal Asynchronous Receiver and Transmitter UART Module CPU loading However the overhead required to set up the interrupts or DMA should be taken into account If the additional overhead outweighs the reduction in CPU loading then polling is the best approach Using the UART interrupts to signal the CPU that data can be read from or written to the UART will help to decrease the CPU loading The UART has a number of status and error interrupt flags that can be used but for typical receive and transmit operations the receive data register full flag
104. d mode being used Refer to the device specific reference manual for details The main oscillator also has programmable internal load capacitors When the main oscillator is configured for low power an integrated oscillator feedback resistor is provided The internal crystal load capacitors in both oscillators are selectable in software to provide up to 30 pF in 2 pF increments for each of the EXTAL and XTAL pins This provides an effective series capacitive load of up to 15 pF The parasitic capacitance of the PCB should also be included in the calculation of the total crystal load The combination of these two values will often mean that no external load capacitors are required If either of the main oscillator pins are not being used they may be left unconnected in their default reset configuration or may be used as general purpose outputs not inputs 4 5 Layout guidelines for general routing and placement Use the following general routing and placement guidelines when laying out a new design These guidelines will help to minimize electromagnetic compatibility EMC problems To minimize parasitic elements surface mount components should be used where possible All components should be placed as close to the MCU as possible f external load capacitors are required they should use a common ground connection shared in the center If the crystal or resonator has a ground connection it should be connected to the common ground o
105. de Rev 0 11 2010 154 Freescale Semiconductor Chapter 16 Segment LCD Controller The demonstration code is prepared for the TWR K40 TWRPI SLCD and the communication board f eescale 9p J Figure 16 2 Tower system with TWR K40x256 and the TWRPI_SLCD The segment LCD included in the TWRPI SLCD has 3 7 segment characters 7 special symbols and uses 4 backplanes and 7 frontplanes To use this demo the TWR must be connected to a serial port with a terminal program configured to 115200 n 8 1 Commands are ASCII characters The following table shows the commands and syntax Table 16 3 List of commands value print Print a message in the LCD message msgmode Select the message mode user coun cmd user counter time per ter time temperature and percentage centage vScroll Enable vertical scroll val O Normal N scroll down N Scroll up N 1 5 Not functional with a 7 Seg Panel symbol Turn on and off x symbol lt val gt 1 FSL 2 3 4 5 AM 6 PM cmd on off segtest Send a predefined pattern to the LCD lt gt faultDetect Enable and disable LCD fault detection cmd enable disable setref status measureall trim Read and set the regulator voltage trim val 0 15 Table continues on the next page Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 155 Demonstration code Table 16 3 List
106. e pr MEO DUM c css cc cacao cis en aare E ERE A NERA ON E EA E A E AE SN R anc rlettes T2 To Exumple PH zaled DMA INES E ierann pep eu edpli bu kot reg tec Deci DRE oM LIS E DULL cpi i UR d pir ee ud 76 Jal Cono 0 RTL ES TL SLT 76 Foe o TE T Le A AE simae ka E E da E E E N E E peto aedes 76 Chapter 8 Using the FlexMemory el Tome ERENS M eer ce 79 SLL VENIE 5c ss sas ata cne E anda sane roams aha pnnss Beebe aap A Seeds aeenetiedaases 79 SM MEME CoD A A E E AE E E 79 5 PRCA onioni E RR NR AIEI ERRAR ER ATR NARE 79 12 E T ETT 80 BIG o ocn n ex e E E A E E A Hus pU pile ERE be 80 SLALI dCodesxuniple and explant OMe iEn eoa AAEE a DIR SEE EM Re ema d 80 alkas EEPROM NOKTE CU RR TE E 80 S22 Code Exemple add Beep ae Oseane e uade R AE bai AA 81 Skea Combination e A db aos etat e talcs sui Lire ese cabin cs put 81 SIG CoHesxinapbs and 2 odopieti doctior diuo due ede locu IU MMbe pd Ri diia boe duro d Redi 82 Sla a T 82 Chapter 9 EzPort Module ON Tibia mee Pee eS t e a e aAA 85 DA EER M E E 85 PANEM M ME o o Uu 85 e BA E l0 eT C 85 ALLT Command a DpOOD odisea else a as fatua din i tau equi bua tup Dad 86 ILLT CO O a 86 LLI Coman lupo T 87 lka cui truc 88 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 7 Section Number Title Page C MEE iurc examples RM O 88 SULA Hardware contato MM nasal iar 88 L
107. e ADC The ADC s interrupts The interrupt feature of the ADC is also used in the example In the Interrupt Service Routine ISR for ADC1 a digital filter is placed It filters the two inputs from ADC both see next section connected to the POT on every PDB cycle This very fast and simple exponential filter is included in the interrupt service routines of ADC for illustration of how to smooth readings with minimal MCU cycle count It is implemented in only two lines of C code with no looping This filter is optional and can be used with or without the averaging feature of the ADC itself In the example both are used for increased smoothness of result Hardware triggering of the ADC with the PDB Kinetis Quick Reference User Guide Rev 0 11 2010 168 Freescale Semiconductor EES Chapter 18 Using Peripheral Delay Block PDB to Schedule Analog to Digital Converter ADC Conversions The ADC module works with the PDB to trigger the ADC s conversions The ADC trigger to convert is based on configuration choices In this case the ADC will be configured to be triggered only by the PDB The PDB will be triggered by the application software using an instruction to start its timed sequence of conversions Once it does this it will trigger each conversion in sequence based on its configurable timers It will repeat each time its counter wraps starting another cycle of conversions of both ADCO and ADC1 Only the readings from ADCI will
108. e LLWU_CS register Prior to releasing the hold the user must re initialize the I O to the pre low power mode entry state so that unwanted transitions on the I O do not occur when the hold is released The oscillator cannot be re enabled before the ACKISO bit is cleared and must be reconfigured after the acknowledge write has been done Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 57 Using the low leakage wakeup unit 5 3 Using the low leakage wakeup unit 5 3 1 Overview This section will demonstrate how to use the Low Leakage Wakeup Unit LLWU The LLWU is responsible for selecting and enabling the sources of exit from all of the low power modes of the MCU This module works in conjunction with the PMC and the MCU to wake the MCU up 5 3 1 1 Mode transitions There are particular requirements for exiting form each of the 10 power modes Please see Mode transition requirements for a table of the transition requirements for each of the modes of operation 5 3 1 2 Wakeup sources There are a possible 16 pin sources and up to 7 modules available as sources of wakeup Please see Source of wakeup pins and modules for a table of external pin wakeup and module wakeup sources 5 3 2 Configuration examples There are five 8 bit wakeup source enable registers for the pin and module source selection Three 8 bit wakeup flag registers to indicate which wakeup source was triggered and one 8 bit status and
109. e and explanation The following list is a sequence of steps needed to correctly configure the ENET interface Enable ENET clock and disable the MPU Configure buffer descriptions BD in little endian Reset MAC controller Configure pins MII or RMII mode Clear and unmask ENET xmit rx and error interrupts Set interrupt level and priority Take network speed and duplex from PHY then configure ENET accordingly Configure MAC address with hash support Point MAC ENET to xmit and Rx BD Configure maximum packet size Start MAC ENET controller 10 Set ENET ready to receive MO 0 4 G Lh E LAA LA Example code Buffer Descriptor Format ifdef ENHANCED BD typedef struct uinti6 t status control and status uinti6 t length transfer length uint8 t data buffer address uint32 t ebd status Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 109 Configuration examples uinti6 t length proto type uinti6 t payload checksum uint32 t bdu uint32 t timestamp uint32 t reserverd wordl uint32 t reserverd_word2 NBUF delse typedef struct control and status transfer length buffer address uinti6 t status uinti6 t length uint8 t data NBUF endif ENHANCED BD Static void enet init int usData const unsigned portCHAR ucMACAddress 6 configMAC ADDRO configMAC ADDR1 configMAC ADDR2 configMAC ADDR3 configMAC ADDR
110. e entire transmit or receive DMA movement is complete the DMA can interrupt the core to notify it of the completion In this approach the CPU has no loading associated with the actual data movement All of the CPU loading is the result of the initial configuration of both the UART and DMA modules and then any processing of data that is required to prepare it for transmission or interpret it after reception 11 4 UART RS 232 hardware implementation The diagram below shows a block diagram of the hardware connections for an RS 232 implementation The diagram shows the optional hardware flow control signals but only the RX and TX data connections are required Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 105 Zz E UART RS 232 hardware implementation UART RS 232 Xcvr Connector RS232 TXD UARTn T S IUS UARTn_RX RS232_RXD UARTn RTS BE BPN Seo IS VIRO zs R523 1S Figure 11 1 UART RS 232 hardware connections block diagram Kinetis Quick Reference User Guide Rev 0 11 2010 106 Freescale Semiconductor Chapter 12 ENET Module 12 1 Overview The following chapter demonstrates how to use the media access controller MAC called ENET to connect to a generic external Ethernet physical transceiver also called PHY The following examples show how they connect to each other hardware and the registers software that link up to a network 12 1 1 I
111. e on chip reference oscillators the on chip crystal resonator oscillator an externally generated square wave clock the FLL or the PLL MCGFLLCLK this is the output of the FLL and is available any time the FLL is enabled Kinetis Quick Reference User Guide Rev 0 11 2010 42 Freescale Semiconductor SSS ee eee Chapter 4 Clocking System MCGPLLCLK this is the output of the PLL and is available any time the PLL is enabled MCGIRCLK this is the output of the selected IRC The selected IRC will be enabled whenever this clock is selected MCGFFCLK this is either the slow IRC or the external clock source divided by the FLL external reference divider FRDIV This clock is available in all modes except FLL bypassed internal FBI and bypassed low power internal BLPI when the slow IRC is selected The source of this clock is selected by the value of the internal reference select bit IREFS In addition to the clocks provided by the MCG there are three other system level clock sources available for use by various peripheral modules OSCERCLK this is the clock provided by the system oscillator and is the output of the oscillator or the external square wave clock source ERCLK32K this is the output of the RTC oscillator or the system oscillator if it is set to provide a 32 kHz clock in low power mode e LPO this is the output of the low power oscillator It is an on chip very low power oscillator with an output of
112. eading In this way the whole flash memory could be read with one single command 9 1 1 3 1 Command format As shown in each command the Ezport module recognizes should start with a command byte that is mandatory and be followed by an optional address byte dummy byte or data byte This is shown below The bracketed items are optional Command address dummy byte read or write data byte Kinetis Quick Reference User Guide Rev 0 11 2010 86 Freescale Semiconductor E Chapter 9 EzPort Module For example some commands like WREN and WRDI need to send only the command byte while the other commands may have optional items The dummy byte is used to differentiate normal speed and fast speed read operations For fast speed operations the external master should shift in one dummy byte before valid data is shifted out FAST_READ and FAST_RDFCCOB commands are examples that need to send the dummy byte 9 1 1 3 2 Command timing Figure 9 1 and Figure 9 2 are the command timing for the READ and FAST READ commands Here it assumes CPOL 1 and CPHA 1 EZPCS zro INA AN U d command 24bitaddress z 1 ani 1 EZPQ High Z 1 Data 1 Data 2 0000000 Figure 9 1 READ command timing Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 87 Using the EzPort module EZBOS Wo M M command 24bitaddress EZPD 2 TG Li EZPQ Hig
113. ed for PIT gated channel activation Channel 1 is configured to perform this transfer Channel 0 is used to transfer the AD result to RAM This transfer is activated when the AD result ready flag is asserted The default channel arbitration gives channel 1 priority over channel 0 This configuration ensures that the AD receives a command word every 1 ms It could however cause results to be overwritten in the result register before they have been moved by the eDMA as the channel reading the results does not have priority The setup can be changed to ensure every result is captured to give the channel reading the results higher priority The DMA MUX configuration for channels 0 and 1 is Configure DMAMux for Channel 0 DMAMUX CHCONFIGO 0 DMAMUX ENABLE Enable routing of DMA request DMAMUX SOURCE 40 Channel Activation Source AD A Result Configure DMAMux for Channel 1 DMAMUX_CHCONFIG1 0 DMAMUX ENABLE Enable routing of DMA request DMAMUX TRIG Trigger Mode Periodic DMAMUX SOURCE 54 Channel Activation Source AD A Command Channel 1 is configured to use a periodic trigger PIT1 The PIT1 module must be enabled and configured for the desired time interval The command data of the AD module must be prepared according to the definition of the AD command register before starting the DMA transfer enable PIT1 Each channel in this example transfers data to or from the static addr
114. een power modes 5 2 1 1 Introduction There are 10 power modes They are described below Run Default Operation of the MCU out of Reset On chip voltage regulator is On full capability 2 Wait ARM core enters Sleep Mode NVIC remains sensitive to interrupts Peripherals Continue to be clocked 3 Stop ARM core enters DeepSleep Mode NVIC is disabled WIC is used to wake up from interrupt peripheral clocks are stopped 4 Very Low Power Run VLPR On chip voltage regulator is in a mode that supplies only enough power to run the MCU in a reduced frequency Core and Bus frequency limited to 2MHz 5 Very Low Power Wait VLPW ARM core enters Sleep Mode NVIC remains sensitive to interrupts FCLK ON On chip voltage regulator is in a mode that supplies only enough power to run the MCU at a reduced frequency 6 Very Low Power Stop VLPS ARM core enters DeepSleep Mode NVIC is disabled FCLK OFF WIC is used to wake up from interrupt peripheral clocks are stopped On chip voltage regulator is in a mode that supplies only enough power to run the MCU at a reduced frequency all SRAM is operating content retained and I O states held 7 Low leakage stop LLS ARM core enters DeepSleep Mode NVIC is disabled LLWU is used to wake up peripheral clocks are stopped all SRAM is operating content retained and I O states held most of peripheral are in state retention mode cannot operate 8 Very low leakage st
115. eference User Guide Rev 0 11 2010 Freescale Semiconductor 77 T Example PIT gated DMA requests EDMAC TCDO W7 0 EDMAC BITER 0x1 Beginning Iteration Count 1 CITER EDMAC BWC 0x0 Bandwidth control 0 gt No eDMA stalls EDMAC MAJOR LINKCH 0x0 Ignored no channel linking Configure DMA Channel 1 TCD EDMAC TCD1 WO EDMAC SADDR uint32 amp command Source Addr address of command var EDMAC TCDi W1 0 EDMAC SMOD 0xO Source Modulo feature disabled EDMAC SSIZE 0x2 Source Size 0x2 32 bit transfers EDMAC DMOD 0xO Destination Modulo feature disabled EDMAC DSIZE 0x2 Destination Size 0x2 32 bit transfers EDMAC SOFF 0x0 Source addr offset 0x0 do not increment EDMAC TCD1 W2 EDMAC NBYTES 0x4 Transfer 4 bytes per channel activation EDMAC TCD1 W3 EDMAC SLAST 0x0 Do not adjust SADDR upon channel completion EDMAC TCD1 NA EDMAC DADDR 0x4003B000 Dest Addr ATD Command Word Register EDMAC_TCD1_W5 0 EDMAC_CITER_E LINK Do not set ELINK bit no channel linking EDMAC CITER Ox1 Current Iter Count gt 1 NBYTES transfer EDMAC DOFF 0x0 Destination addr offset 0x0 no increment EDMAC TCD1 W6 EDMAC DLAST 0x0 Do not adjust DADDR upon channel completion EDMAC TCD1 W7 0 EDMAC BITER E LINK Do not set ELINK bit no channel linking EDMAC BITER 0x1 Beginnin
116. emory enabled devices FlexNVM is configured as program data flash and the Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 79 EE ae Using the FlexNVM FlexRAM is configured as a general purpose RAM Security is disabled and because the flash is in an erased state the program flash data flash and EEPROM protections are disabled so the regions can be programmed or erased 8 1 2 Configuration examples The user can configure FlexMemory enabled devices as either FlexNVM as data flash and FlexRAM as traditional RAM FlexNVM as EEPROM flash records to support the built in EEPROM feature and FIexRAM as EEPROM Oracombination of both 8 1 2 1 Basic data flash In this particular configuration the FlexNVM can be used as non volatile flash memory that can execute program code or store data The FlexRAM can be used as traditional RAM This is the default configuration prior to execution of the Program Partition Command 8 1 2 1 1 Code example and explanation This is the default configuration for devices with FlexMemory There is no need for partitioning the device in this implementation 8 1 2 2 EEPROM flash records In this particular configuration the FlexNVM is used exclusively for EEPROM backup space To configure the part the user must use the Flash Common Command Object FCCOB registers to pass the Program Partition Command and associated parameters to the memory controller in the FTFL
117. enses 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 claims 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 complaint 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 2010 Freescale Semiconductor k freescale semiconductor
118. er run mode VLPR Also an example is provided of how to configure the frequency locked loop FLL as the main system clock source using the RTC oscillator as the reference clock 4 2 Features The clocking system is summarized in Figure 4 1 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 41 Features MCG E Die rus Fast IRC Slow IRC some peripherals Clock options for Core system clocks Bus clock FlexBus clock Flash clock o pep 2 o on p 2 EXTAL X T o 8a BS XTAL x o RTC oscillator NA EXTAL32 x OSC logic i XTAL32 X Real time clock CG Clock gate Figure 4 1 Clock distribution diagram The system level clocks are provided by the MCG The MCG consists of Two individually trimable internal reference clocks IRC a slow IRC with a frequency of 32 kHz and a fast IRC with a frequency of 4 MHz with a fixed divide by 2 Frequency locked loop FLL using the slow IRC or an external source as the reference clock Phase locked loop PLL using an external source as the reference clock Auto trim machine ATM to allow both of the IRCs to be trimmed to a custom frequency using an externally generated reference clock The clocks provided by the MCG are summarized as follows MCGOUTCLK this is the main system clock used to generate the core bus and memory clocks It can be generated from one of th
119. ess 32 bit wide command or result register respectively Therefore it is necessary to restore the address pointers in the TCD when the major or minor transfer loop is complete This example has no table of data to transfer making only a single minor loop necessary to complete a major loop The source and destination addresses are therefore restored on completion of the major loop The TCD configuration for channels 0 and 1 is Configure DMA Channel 0 TCD EDMAC TCDO WO EDMAC SADDR 0x4003B010 Source Address AD Result Register EDMAC TCDO W1 0 EDMAC SMOD 0xO Source Modulo feature disabled EDMAC SSIZE 0x2 Source Size Ox2 32 bit transfers EDMAC DMOD 0xO Destination Modulo feature disabled EDMAC DSIZE 0x2 Destination Size Ox2 32 bit transfers EDMAC SOFF 0x0 Source addr offset 0x0 do not increment EDMAC TCDO W2 EDMAC NBYTES 0x4 Transfer 4 bytes per channel activation EDMAC TCDO W3 EDMAC SLAST 0x0 Do not adjust SADDR upon channel completion EDMAC TCDO W4 EDMAC DADDR Ox1FFF9000 Destination Address 0x500 Ext RAM EDMAC TCDO W5 0 EDMAC CITER E LINK Do not set ELINK bit no channel linking EDMAC CITER 0Ox1 Current Iter Count gt 1 NBYTES transfer EDMAC DOFF 0x0 Destination addr offset 0x0 no increment EDMAC TCDO W6 EDMAC DLAST 0x0 Do not adjust DADDR upon channel completion Kinetis Quick R
120. etis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 91 E Using the EzPort module Poll SR until WIP goes low while sr amp EP SR WIP EP SR WIP Sr ezp rdsr cmd 9 1 2 5 Write and read FlexRAM The WRFLEXRAM command allows you to write four bytes of data to the FlexRAM If the FlexRAM is configured for EEPROM configuration the WRFLEXRAM command can effectively be used to create data records in EEPROM flash memory The address of the FlexRAM location should be 32 bit aligned If more than or fewer than four bytes of data is received this command has unexpected results RDFLEXRAM command returns data from FlexRAM It also has a fast speed version command FAST RDFLEXRAM which includes the dummy byte and runs at up to half of internal system clock frequency Example code ezp wren cmd ezp wrflexram cmd address buffer Loop till command has completed sr EP SR WIP Poll SR until WIP goes low while sr amp EP SR WIP EP SR WIP Sr ezp rdsr cmd Kinetis Quick Reference User Guide Rev 0 11 2010 92 Freescale Semiconductor Chapter 10 Flexbus Module 10 1 Using the Flexbus module 10 1 1 Overview A multi function external bus interface called the FlexBus interface controller is provided with a basic functionality of interfacing to slave only devices It can be directly connected to the following asynchronous or synchronous devices with little or no additional circu
121. eup enabled pin we need to 1 Initialize the PCR for PTEI 2 Make sure the pin is an input 3 Enable PTE as a valid wakeup source in the LLWU The code for this is below This would need to be done for each of the pins you want to enable as wakeup sources PORTE PCR1 PORT PCR ISF MASK clear Flag if there PORT PCR MUX 01 GPIO PORT PCR IRQC OxOA falling edge enable PORT PCR PE MASK Pull enable PORT PCR PS MASK pull up enable GPIOE POER amp OxFFFFFFFD set Port El as input LLWU PE1 LLWU PE1 WUPEO 0x02 defining PORT El as a wakeup source for LLWU 5 3 2 3 LLWU port and module interrupts In the low power modes the ARM core is off the NVIC is off some of the time and the WIC is kept alive allowing an interrupt from the pin or module to propagate to the mode controller to indicate a wakeup request To enable the LLWU interrupt we would replace the default vector in the interrupt vector table with the appropriate LLWU interrupt handler with the following sequence Enable LLWU Interrupt in NVIC VECTOR RAM 37 uint32 11wu handle Replace ISR NVICICPRO 1 21 Clear any pending interrupts on LLWU NVICISERO 1 21 Enable interrupts from LLWU module Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 59 Using the low leakage wakeup unit For our example we allow the processing of the pin PTE we add this initialization code VECTOR RAM 107 uint3
122. evice ready try to move the mouse Figure 14 16 USB mouse successfully enumerated Finally move the mouse or other pointing device or press any button and the status will be displayed in the terminal screen Kinetis Quick Reference User Guide Rev 0 11 2010 138 Freescale Semiconductor Chapter 14 Universal Serial Bus OTG Module VW COM1 115200baud Tera Term VT B x File Edit Setup Control Window Help Mouse device ready try to move the mouse Left Click Right Click Right Click Figure 14 17 Mouse events Code explanation For USB host support the application needs to schedule BUS space for all the available devices on the USB bus The code is a little complex to explain in this document but this example code is based on the Freescale USB stack with Personal Healthcare Device Class PHDC support Documentation and API information is available on the Freescale website the stack is free and is MQX Freescale Real time operating system compatible For more information regarding this demo please visit www freescale com medicalusb Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 139 Example code Kinetis Quick Reference User Guide Rev 0 11 2010 140 Freescale Semiconductor Chapter 15 FlexCAN Module 15 1 Overview This chapter will describe how to execute a quick start of the FlexCAN module for Kinetis MCUs 15 1 1 Introduction The CAN protocol wa
123. example shows how to locate the vector table from the flash to RAM 3 2 1 Configuring the NVIC Configuring the NVIC for the specific module involves writing three registers NVICSERx NVIC Set Enable Register NVICCPRx NVIC Clear Pending Register and NVICIPxx NVIC Interrupt Priority After the NVIC is configured and the desired peripheral has its interrupts enabled the NVIC serves any pending request from that module by going to the module s ISR 3 2 1 1 Code example and explanation This example shows how to set up the NVIC for a specific module In this case the LPTMR is used The steps to configure the NVIC for this module are Kinetis Quick Reference User Guide Rev 0 11 2010 36 Freescale Semiconductor Sy es eS eS a el Chapter 3 Nested Vector Interrupt Controller NVIC 1 Identify the vector number and the IRQ number of the module from the vector table in the device specific reference manual in the section Interrupt Channel Assignments For the LPTMR the vector is 101 Table 3 2 LPTMR vector Address Vector IRQ Source Module Source Descrip tion 0x0000 018C 99 83 TSI Single interrupt Source 0x0000 0190 100 84 MCG 0x0000 0194 101 85 LPTMR 2 Determine which NVICSERx register contains the IRQ Each NVICSERx register contains 32 IRQs Therefore the NVICSERO can enable from IRQ 0 to IRQ 31 the NVICSER1 from IRQ 32 to IRQ 63 and NVICSER2 from IRQ 64 to IRQ 95 For this example
124. f the load capacitors Where possible keep high speed IO signals as far from the EXTAL and XTAL signals as possible do not route signals under oscillator components on same layer or layer below select the functions of pins close to EXTAL and XTAL to have minimal switching to reduce injected noise Kinetis Quick Reference User Guide Rev 0 11 2010 48 Freescale Semiconductor EES Chapter 4 Clocking System 4 6 References The following list of application notes associated with crystal oscillators are available on the Freescale website at www freescale com They discuss common oscillator characteristics potential problems and troubleshooting guidelines AN1706 Microcontroller Oscillator Circuit Design Considerations e AN1783 Determining MCU Oscillator Start Up Parameters AN2606 Practical Considerations for Working With Low Frequency Oscillators AN3208 Crystal Oscillator Troubleshooting Guide Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 49 References Kinetis Quick Reference User Guide Rev 0 11 2010 50 Freescale Semiconductor Chapter 5 Power Management Controller PMC MODECTL 5 1 Using the power management controller 5 1 1 Overview This section will demonstrate how to use the Power Management Controller PMC module to protect the MCU from unexpected low Vpp events References to other protection options will also be made 5 1 1 1 Introduction This chapte
125. g Iteration Count 1 CITER EDMAC BWC OxO Bandwidth control 0 gt No eDMA stalls EDMAC MAJOR LINKCH 0x0 Ignored no channel linking Using these configurations produces the required eDMA functionality for this example Refer to the full source code for this example in the ZIP file Kinetis Quick Reference User Guide Rev 0 11 2010 78 Freescale Semiconductor Chapter 8 Using the FlexMemory 8 1 Using the FlexNVM 8 1 1 Overview This quick start guide demonstrates how to configure devices that offer the FlexMemory 8 1 1 1 Introduction The flash memory module FTFL includes several accessible memory regions depending on the device configuration Program flash Non volatile flash memory that can store program code and data e FlexNVM Non volatile flash memory that can store program code store data and backup EEPROM data FlexRAM Byte writeable RAM memory that can be used as traditional RAM or as high endurance EEPROM storage Program flash only devices have two blocks of flash with 2 KB sectors and offer swap capability FlexMemory enabled devices have one block of program flash with 2 KB sectors one block of FlexNVM with 2 KB sectors and one block of FlexRAM but do not offer swap capability 8 1 1 2 Features By default there is no need for the user to configure the FTFL The configuration default allows for the flash memory controller FMC to accelerate flash transfers For FlexM
126. gion is valid Enable MPU function MPU CESR 0x00000001 Kinetis Quick Reference User Guide Rev 0 11 2010 68 Freescale Semiconductor Chapter 7 Enhanced Direct Memory Access eDMA Controller 7 1 Overview This chapter is a compilation of code examples and quick reference materials that have been created to help you speed up the development of your applications with the eDMA module of the Kinetis family Consult the device specific reference manual for specific part information This chapter demonstrates how to configure and use the eDMA module to create data movement between different memory and peripheral spaces without the CPU s intervention 7 1 1 Introduction The DMA controller provides the ability to move data from one memory mapped location to another After it is configured and initiated the DMA controller operates in parallel to the core performing data transfers that would otherwise have been handled by the CPU This results in reduced CPU loading and a corresponding increase in system performance Figure 7 1 illustrates the functionality provided by a DMA controller Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 69 Overview Source a g RAM Ox11112222 0x33334 444 Ox55556666 DMA controller Ox 77 7 788898 Ox CKJOQOA AA A Ox COCOA AA A OxBBBBCCC DMA Transfer reauest DMA D MA write source data to the destination Destination e g SPI
127. h Z i aand U EZPCS em UVTI M Du mmy EZPD TOYS KAKKO i EZPO uc Figure 9 2 FAST READ command timing 9 1 1 4 Status register The Ezport module provides a status register to reflect some reset out flash status and also write progress flags The FS FLEXRAM and BEDIS bits reflect flash security FIexRAM configurations and whether bulk erase is supported under secure mode respectively The status register can be read with the RDSR command to check reset out status and whether a write command has completed Table 9 3 Ezport status register 7 6 5 4 3 2 FS WEF FLEXRAM BEDIS WEN WIP cus o 9 1 2 Configuration examples Kinetis Quick Reference User Guide Rev 0 11 2010 88 Freescale Semiconductor EA Chapter 9 EzPort Module 9 1 2 1 Hardware connections Any SPI master could be used to connect to the Ezport module for flash programming Either QSPI or DSPI module on existing Coldfire devices could be used in this case Figure 9 3 shows the connection between the QSPI module on MCF5282 and Kinetis Here QSPI_CS1 and QSPI_CS2 are used as GPIO to control the timing between manual reset of Kinetis and sampling of EZPCS QSPI DIN Kinetis OSPI DOUT OSPI CLK Figure 9 3 Connection between MCF5282 and Kinetis Example code for set to ezp mode Configure as GPIO pins to monitor RSTOUT pins and assert RCON MCF5282 GPIO PQSPAR 0x0 GPIO function MCF52
128. h describes the network Communication between the MAC NET and the PHY is made by 2 signals Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 113 ag E F PHY management interface e One clock generated from the ENET interface for the PHY Clock cannot be greater than 2 5MHz and is controlled by register ENET_MSCR MII_SPEED divider which uses peripheral clock as reference One bidirectional signals which sends receives data to from the PHY 12 3 1 Code example and explanation The following example code starts the PHY management interface that starts the auto negotiation process from the PHY to the network Example code void enet start mii void PORTB PCRO PORTB PCR1 PORT PCR MUX 4 GPIO RMIIO MDIO MIIO MDIO PORT PCR MUX 4 GPIO RMIIO MDC MIIO MDC FSL start MII interface mii init 0 periph clk khz 1000 MHz Can we talk to the PHY do vTaskDelay netifLINK DELAY usData Oxffff mii read 0 configPHY ADDRESS PHY PHYIDR1 amp usData while usData Oxffff Start auto negotiate mii write 0 configPHY ADDRESS PHY BMCR PHY BMCR AN RESTART PHY BMCR AN ENABLE void mii init int ch int sys clk mhz ENET MSCR ch 0 ifdef TSIEVB TSI EVB requires a longer hold time than default 10 ns ENET MSCR HOLDTIME 2 endif ENET MSCR MII SPEED 2 sys clk mhz 5 41 int mii write int ch int phy addr int reg
129. he transceiver to maximize the eye diagram for the data lines Kinetis Quick Reference User Guide Rev 0 11 2010 134 Freescale Semiconductor a E Chapter 14 Universal Serial Bus OTG Module Power Gatribution chip or cir a ENB d VBUS FLAG x Optional ESO cras SB DM La al o 33 VE8_0P a D Optenal Place resmtors close ferrite bead 1o the processor 8 WO Figure 14 11 Components and placement 14 6 3 Layout recommendations Route the USB D and D signals as parallel 90 O differential pairs e Match the trace lengths as closely as possible Matching within 150 mils is a good guideline Try to maintain short trace lengths not longer than 15 cm Avoid placing USB differential pairs near signals such as clocks periodic signals and I O connectors that might cause interference Minimize vias and corners Route differential pairs on a signal layer next to the ground plane Avoid signal stubs Processor pins USB DEM a S p me B a Ey eae 33 shm D resistor Maintain 90 ohm differential spacing for both traces Figure 14 12 USB layout recommendations Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 135 Example code 14 7 Example code 14 7 1 Device code This demo is a simple echo terminal using the communication device class The USB is recognized as a standard COM port that can be used for the HyperTerminal or any program that uses a seri
130. in isolation is described in more detail in Freescale application note AN2764 Improving the Transient Immunity Performance of Microcontroller Based Applications The basic concept is to isolate or place a low pass filter between power domains The AC power domain should be physically isolated from the DC domains Physical separation or decoupling filters Figure 2 1 should be used to separate different DC functional blocks power domains when necessary Note that the Tower System boards have multiple decoupling filters to separate digital and analog domains Also note that decoupling may not be needed in many applications physical separation of domains may be sufficient AUN Y Y a Vpp C 0 V Dp L AAA DD Iso UNFILTERED FILTERED DC INPUT DC INPUT Vss O Vss 180 YL h Figure 2 1 Generic decoupling filter Kinetis Quick Reference User Guide Rev 0 11 2010 20 Freescale Semiconductor E Chapter 2 General System Setup Hardware Considerations In general the decoupling network series elements are small inductors or ferrite beads that have a small impedance about 100 O at 100 MHz The capacitors are generally 10nF to 1uF and do not have to be the same value on both sides of the filter select a lower value for the side that has the higher frequency content 2 3 PCB routing considerations This section covers critical power and filtering aspects of PCB layout 2 3 1 Power supply routing Routing of po
131. inates the detection activities of the module and controls an off chip integrated circuit that performs the battery charging The main features of the DCD module are the following USB battery charger specification compliant rev 1 1 Programmable timing parameters Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 121 Module Configuration Uses the same D and D signals as the USB module Enables rechargeable batteries usage Low power operation 13 1 3 Battery charger specification The USB battery charger specification establishes three different types of downstream ports s Standard Downstream Port Refers to a downstream port on a device that complies with the USB 2 0 definition of a host or hub A standard downstream port expects a downstream device to draw less than a 2 5 mA average when disconnected or suspended up to 100 mA maximum when connected and not suspended up to 500 mA maximum if configured and not suspended Charging Downstream Port A charging downstream port is a downstream port on a device that complies with the USB 2 0 definition of a host or a hub It can supply a maximum of 1 5 A to a low full speed port and 900 mA to a high speed port Dedicated Charger A dedicated charging port is a downstream port on a device that outputs power through a USB connector but is not capable of enumerating a downstream device A dedicated charging port is able to supply a m
132. ithout 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 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 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 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 Freescale Semiconductor and its officers employees subsidiaries affiliates and distributors harmless against all claims costs damages and exp
133. itry external ROMs flash memories programmable logic devices or other simple target slave devices 10 1 1 1 Introduction The FlexBus has up to six independent user programmable chip select signals FB CS 5 0 8 bit 16 bit and 32 bit port sizes with configuration for multiplexed or non multiplexed address and data buses Size configurable transfers 8 bit 16 bit 32 bit Programmable burst and burst inhibited address setup time with respect to the assertion of chip select address hold time with respect to the negation of chip select and transfer direction Extended address latch enables option help with glueless connections to synchronous and asynchronous memory devices 10 1 1 2 Features 10 1 1 2 1 Signal descriptions FB_A 31 0 In a non multiplexed configuration this is the address bus Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 93 SS Using the Flexbus module FB AD 31 0 In a non multiplexed mode this is the data bus In a multiplexed mode the FB AD 31 0 bus carries the address and the data The number of byte lanes carrying the data is determined by the port size FB CS 5 0 The chip select signal indicates what device is selected A particular chip select asserts when the transfer address is within the device s address space The next two tables show how the number of chip selects available depend on the pin configuration FB BE BWE 3 0 When driven
134. k gating bits in the SIM SIM Configuration SIM _SCGC4 SIM SCGC4 USBOTG MASK USB Clock Gating SIM SCGC6 SIM SCGC6 USBDCD MASK USB Clock Gating 3 Pre initialize the USB This is required to enable the pullup resistor that is controlled by the USB module USB pre initialization USBOTG USBTRCO USBOTG USBTRCO USBRESET MASK while FLAG CHK USBOTG USBTRCO USBRESET SHIFT USBOTG USBTRCO FLAG SET USBOTG ISTAT USBRST MASK USBOTG ISTAT Enable USB Reset Interrupt FLAG SET USBOTG INTEN USBRSTEN SHIFT USBOTG INTEN USBOTG USBCTRL 0x00 USBOTG USBTRCO 0x40 USBOTG CTL 0x01 4 Configure the DCD clock register USBDCD CLOCK DCD TIME BASE 2 1 5 At this point the application is polling the PTBO pin for VBUS detection but a port interrupt can also be used to avoid polling method Waiting for VBUS if FLAG CHK 0 GPIOB PDIR amp amp FLAG CHK VBUS Flag gu8InterruptFlags USBDCD CONTROL USBDCD CONTROL IE MASK USBDCD CONTROL IACK MASK LAG SET USBDCD CONTROL START SHIFT USBDCD CONTROL LAG SET VBUS Flag gu8InterruptFlags nj nj 6 Finally when the detection sequence is completed the application needs to read the results in the DCD registers and send them to the terminal DCD results if FLAG CHK DCD Flag gu8InterruptFlags u8Error DCD GetChargerType if u8Error amp OxFO0 printf Oooooops DCD Error else if u8Error amp 0x0F STANDARD HOS
135. l ADC1 BASE PTR do the calibration Configure the ADC again to default conditions ADC Config Alt ADC1 BASE PTR amp Master Adc Config 18 2 1 7 Enable ADC and PDB interrupts Enable the ADC and PDB interrupts in NVIC enable irq ADCO irq no ready for this interrupt enable irq ADC1 irq no ready for this interrupt enable irq PDB irq no ready for this interrupt In case previous demo did not end with interrupts enabled enable used ones EnableInterrupts Kinetis Quick Reference User Guide Rev 0 11 2010 172 Freescale Semiconductor SSS ee ee eS eS a ey ae eee Chapter 18 Using Peripheral Delay Block PDB to Schedule Analog to Digital Converter ADC Conversions 18 2 1 8 Software triggering of PDB Software trigger the PDB PDB SC PDB SC SWTRIG MASK kick off the PDB just once The system is now working The PDB is continuously triggering ADC conversions Now to display the results The line above was the SOFTWARE TRIGGER 18 2 1 9 Handle ADC and PDB interrupts Interrupt servicing is simple even the digital filter is only two lines of C code It is placed in both ADCIA and ADCIB portions of the ISR BORK KKK KR KR A k e k A k e k K k k k A A k k k A A k k k A k k k k k k k A k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k k adoi isr void use to signal ADC1 end of conversion In n a Out exponentially filtered potentiometer reading The ADC1 is used to sample
136. l the information that the AD module requires for a conversion so by using the DMA to provide the command words the module can be instructed to perform conversions without any CPU intervention After the result is transferred by the eDMA to internal SRAM the application can make further analysis on the data 7 5 1 Requirements The input to the ADCO must be sampled every 1 ms To achieve this a 32 bit AD command word must be supplied to the ADCO SC A 0x4003B000 every 1 ms when the module is able to accept the command The command word is located in the internal SRAM This example only requires a single command word to be provided to the AD It is stored in a variable labeled command After the AD has completed the conversion the result is moved from the AD result register ADCO RA located at 0x4003B010 to address Ox1FFF9000 in internal SRAM Figure 7 7 illustrates the functionality of this example AD command DMA request gated with 1ms PIT pulse AD result DMA request Figure 7 7 Example 2 overview Kinetis Quick Reference User Guide Rev 0 11 2010 76 Freescale Semiconductor SSS MM Chapter 7 Enhanced Direct Memory Access eDMA Controller 7 5 2 Module configuration To implement this example two eDMA channels are required one to transfer the command word and the other to transfer the result The command transfer request requires a 1 ms PIT trigger and an always on trigger The DMA MUX must be configur
137. lane Layer 2 inner ground plane Layer 3 inner signals and power plane Layer 4 inner signals and ground plane Layer 5 inner power plane Layer 6 bottom signals and ground plane 8 Layer PCB A Layer 1 top MCU signals Layer 2 inner ground plane Layer 3 inner signals Layer 4 inner power plane Layer 5 inner ground plane Layer 6 inner signals Layer 7 inner ground plane Layer 8 bottom signals 8 Layer PCB B Layer 1 top MCU signals and power plane Layer 2 inner ground plane Layer 3 inner signals and power plane Layer 4 inner ground plane Layer 5 inner power plane Layer 6 inner signals and ground plane Layer 7 inner power plane Layer 8 bottom signals and ground plane 8 Layer PCB C Layer 1 top MCU signals and ground plane Layer 2 inner power plane Layer 3 inner ground plane Kinetis Quick Reference User Guide Rev 0 11 2010 30 Freescale Semiconductor E Chapter 2 General System Setup Hardware Considerations Layer 4 inner signals Thick core Layer 5 inner signals Layer 6 inner ground plane Layer 7 inner power plane Layer 8 bottom signals and ground plane 8 Layer PCB D Layer 1 top MCU signals and ground plane Layer 2 inner power plane Layer 3 inner ground plane Layer 4 inner signals and power plane Thick core Layer 5 inner signals and power plane Layer 6 inner ground p
138. lane Layer 7 inner power plane Layer 8 bottom signals and ground plane In general avoid placing one signal layer adjacent to another signal layer 2 5 Other module hardware considerations 2 5 1 VBAT The VBAT input supplies power to the RTC and a 32 byte register file during powerdown and low power modes This pin can be sourced from the VDD supply or from a dedicated back up battery cell A simple battery isolator consists of a dual Schottky array with common cathodes The TWR board example below Figure 2 6 uses the BATS54C device to provide battery back up when the main system power is off A 100nF bypass capacitor placed as near as possible to the MCU is recommended to minimize the effects of supply switching events Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 31 Other module hardware considerations VDD VBAT BAT54C v Figure 2 6 VBAT connection example 2 5 2 Voltage reference module If the output from the Voltage Reference Module is used in tight regulation buffer mode a 100nF capacitor must be connected between the Y REE OUT pin and ground 2 5 3 Debug interface The Kinetis MCUs use the Cortex Debug interfaces for debugging and programming The 19 pin Cortex Debug ETM interface provides connections for JTAG and Serial Wire debugging as well as target power The 9 pin Cortex Debug interface provides connections for JTAG and Serial Wire debugging Figure 2 7 shows the
139. lement advanced user input controls The TSI module includes hardware that is able to drive touch sensing electrodes or capacitors created by flat conductive areas providing robustness above traditional GPIO based RC measurements and logic that automatically scans up to 16 electrodes measures and outputs the results and generates interrupt signals to the CPU 17 2 Introduction Capacitive touch sensing has become one of the de facto input technologies for user input in Human Machine Interfaces HMI It now has a place in all types of markets from industrial control panels to portable consumer devices Though capacitive touch sensing is not the only touch sensing method it is one of the most common and most practical to implement The basic element in capacitive touch sensing is the electrode In this case the electrode is a an area of conductive material with dielectric material on the top usually plastic or glass This is what the user touches This conductive area plus the dielectric material effectively creates a capacitor referenced to the system ground By touching the dielectric on top of the electrode the user effectively changes the electrode capacitance both by adding a second conductive area that is grounded the conductive part of the finger and by increasing the dielectric of the original capacitor The sensor in this case the TSI module uses a capacitive sensing method to measure changes in the electrode capacitance Kine
140. length of the charging time with a reference oscillator To increase the robustness of the measurement the TSI relies on an internal oscillator similar to the one shown above but with an internal capacitor instead of an external electrode The reason to do this as opposed to counting bus clock cycles is that the current sources in the internal oscillator are part of the same silicon as the external electrode oscillator When the output drifts because of temperature or voltage changes both oscillators change making the final touch detection compensated When configuring TSI users must make sure to have the reference oscillator oscillate faster than the external oscillator this causes more reference counts per electrode oscillation More counts or more resolution allow more headroom for touch detection and noise rejection Figure 17 4 shows the relationship between internal and external oscillations with or without touch MANNA AVN Touch Figure 17 4 Internal reference oscillations vs external reference oscillations Notice how the frequency becomes slower when a finger touches the electrode and how more reference oscillations blue fit into one electrode black oscillation 17 3 Features The TSI module includes several features designed to simplify touch sensing as well as add versatility and performance Capacitive touch sensing detection across all low power modes Automatic periodic scan or software triggered single scan
141. lication if a UART and a timer interrupt occur at the same time serving the timer interrupt that moves the motor is more critical than the UART interrupt that just received a character In this case the timer priority must be set higher than the UART 3 1 2 Features On Kinetis MCUs the NVIC provides up to 120 interrupt sources including 16 that are core specific It also implements up to 16 priority levels that are fully programmable The NVIC uses a vector table to manage the interrupts This vector table can be stored in either flash or RAM depending on the application Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 35 SS M Configuration examples Table 3 1 Core exceptions Address Vector IRQ Source module Source description ARM Core System Handler Vectors 0x0000_0000 0 ARM core Initial stack pointer 1 ARM core Initial program Counter 2 ARM core NMI 3 ARM core Hard fault 4 ARM core Memory manage fault 5 ARM core Bus fault 6 ARM core Usage fault 11 ARM core SVCall 12 mE ARM core Debug monitor 14 ARM core Pendable request for system service 15 ARM core System tick timer 3 2 Configuration examples The NVIC is easy to configure Two examples are shown in this section The first example shows how to configure the NVIC for a module The low power timer LPTMR is used as the base for this example The second
142. low these outputs indicate the data latched or driven onto a specific lane of the data bus FB OE The output enable signal is sent to the interfacing memory to enable a read transfer FB OE is asserted only during a read access when a chip select matches the current address decode FB R W The processor drives this signal to indicate the current bus operation 1 during read bus cycles and 0 during write bus cycles FB ALE The assertion of this signal indicates that the device has started a bus transaction and the address and attributes are valid FB TSIZ 1 0 These signals along with FB TBST indicate the data transfer size of the current bus operation FB_TBST Transfer burst indicates that a burst transfer is in progress and driven by the device FB TA This input signal indicates that the external data transfer is complete When the processor recognizes FB TA during a read cycle it latches the data and then terminates the bus cycle FB CLK FlexBus clock the system provides a dedicated clock source to the FlexBus module s external FB CLK Its clock frequency is derived from a divider SIM CLKDIVI OUTDIV3 of the MCGOUTCLK 10 1 1 2 2 Address and data bus multiplexing Figure 10 1 shows the supported combinations of address and data bus widths The bus sends the address at the first stage light blue and the data at the second stage green Kinetis Quick Reference User Guide Rev 0 11 2010
143. miconductor Module operation in low power modes Table 5 1 Module operation in low power modes continued Se a a cera SPI Static 1Mbps 1Mbps Static Static 12C Static address 100 kbps 100 kbps Static address Static OFF WU WU CAN Wakeup FF FF Wakeup Static OFF 125 Static FF FF Static Static OFF Segment LCD FF FF FF FF FF RTC clk FF RTC clk TSI Wakeup FF FF Wakeup Wakeup One Wakeup One pin pin FTM Static FF FF Static Static OFF PIT Static FF FF Static Static OFF PDB Static FF FF Static Static OFF LPT FF FF FF FF FF FF Watchdog FF FF FF FF Static OFF EWM Static FF Static Static Static OFF 16 bit ADC ADC internal FF FF ADC internal Static OFF Clk Clk CAN Wakeup FF FF Wakeup Static OFF CMP HS or LS FF FF HS or LS LS LS 6 bit DAC Static FF FF Static Static Static VREF FF FF FF FF Static OFF OPAMP FF FF FF FF Static OFF TRIAMP FF FF FF FF Static OFF 12 bit DAC Static FF FF Static Static Static USB FS LS Static Static Static Static Static OFF USB DCD Static FF FF Static Static OFF USB DCD Static FF FF Static Static OFF USB Regulator Optional Optional Optional Optional Optional Optional Ethernet Wakeup Static Static Static Static OFF RTC Ext OSC2 FF FF FF FF FF FF CMP HS or LS FF FF HS or LS LS LS 6 bit DAC Static FF FF Static Static Static VREF FF FF FF FF Static OFF Kinetis Quick Reference User Guide Rev 0 11 2010 F
144. module The FCCOB requirements for execution of this command are below Table 8 1 Program partition command FCCOB requirements FCCOB Number FCCOB Contents 7 0 0 0x80 PGMART 1 Not used 2 Not used Table continues on the next page Kinetis Quick Reference User Guide Rev 0 11 2010 80 Freescale Semiconductor SSeS ee Chapter 8 Using the FlexMemory Table 8 1 Program partition command FCCOB requirements continued FCCOB Number FCCOB Contents 7 0 3 Not used 4 EEPROM data size code 5 FlexNVM partition code 8 1 2 2 1 Code Example and Explanation The following example uses a device with 256KB of FlexNVM and 4KB of FlexRAM This example assumes the part is erased and that the flash memory clock gate control is enabled in the system integration module SIM The default state in the SIM is flash memory clock enabled For a complete list of EEPROM data size codes and FlexNVM Partition codes please see the device specific reference manual In this example the FlexNVM is configured to use all 256KB of available memory as EEPROM backup memory The available 4KB of FlexRAM are configured as EEPROM When configuring the FlexRAM for EEPROM 2 subsystems are created and any FlexRAM not configured as EEPROM is unusable The EEPROM data size code being used is 0x32 which selects a size of subsystem A subsystem B 2 KB The FlexNVM partition code used is 0x08 representing the size of o
145. n EEPROM record management system raises the number of program erase cycles that can be attained prior to device wear out by cycling the EEPROM data through a larger EEPROM NVM storage space The endurance factor of a subsystem can be calculated for a partitioned device using the formula Endurance_Subsystem E Flash 2 EEESPLIT EEESIZE EEESPLIT EEESIZE Record_Efficiency Endurance_Factor Where Endurance_Subsystem Maximum writes to EERAM for a given subsystem E Flash allocated EEPROM backup for each subsystem min 16KB max 128KB EEESPLIT Split factor for subsystem A B 0 5 0 5 or 0 25 0 75 or 0 125 0 875 EEESIZE allocated RAM for EEE min 32B max 4KB Record_Efficiency 0 5 for 16 bit and 32 bit writes 0 25 for 8 bit writes Endurance_Factor 10000 native cycles Example 1 A Kinetis device configured as in example 2 with 2 subsystems of 2KB of EERAM backed up by 128 KB of E Flash provides 310K cycles with 16 bit or 32 bit writes for each subsystem Endurance subsystem E Flash 2 EEESPLIT EEESIZE EEESPLIT EEBESIZE Record Efficiency Endurance Factor Endurance subsystem 128K 2 5 4KB 5 4KB 5 10 000 Endurance subsystem 124KB 2KB 5000 Endurance_subsystem 62 5000 Endurance_subsystem 310 000 Example 2 A Kinetis device configured as in example 3 with a subsystem of 2KB of EE backed up by 64 KB of E Flash provides 150K cycles with 16 bit or 32 bit writes Endurance subsystem
146. n access protection and virtual memory This MMU implementation will be costly for the overall system it will have a large memory footprint higher power consumption paging segmentation and larger die size for Kinetis MCUs Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 67 Configuration examples The MPU module is designed for less complex memory management without TLB paging dynamic allocation and virtual memory It provides lower power consumption and no paging segmentation therefore an MPU is better suited for MCUs 6 1 4 Configuration examples 6 1 4 1 Region descriptors setup Example code define TCML BASE 0x20000000 Upper SRAM bitband region define TCML SIZE 0x00010000 MPU Configuration MPU RGDO WORD2 0 Disable RGDO Set RGD1 MPU RGD1 WORDO 0 Start address MPU_RGD1 WORD1 TCML BASE TCML SIZE End Address MPU RGD1 WORD2 0x0061F7DF No magic s Bus master 3 SM all access List what the Bus masters are in addition to s Bus master 2 SM all access Bus master 2 UM all access Bus master 1 SM all access Bus master 1 UM all access Bus master 0 SM all access Bus master 0 UM all access MPU RGD1 WORD3 0x00000001 region is valid OCOORRNN Set RGD2 MPU RGD2 WORDO TCML BASE TCML SIZE 0x40 MPU RGD2 WORD1 OxFFFFFFFF End Address MPU RGD2 WORD2 0x0061F7DF MPU RGD2 WORD3 0x00000001 re
147. n the mounting layer This guard ring can originate from the VSS pin adjacent to the crystal pins Note that the guard ring and load capacitors is connected to the ground plane in Figure 2 4 and Figure 2 5 Kinetis Quick Reference User Guide Rev 0 11 2010 24 Freescale Semiconductor Chapter 2 General System Setup Hardware Considerations R2 XTAL Figure 2 3 Typical crystal circuit Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 25 PCB routing considerations e aea Figure 2 4 Potential crystal layout for BGA Kinetis Quick Reference User Guide Rev 0 11 2010 26 Freescale Semiconductor Chapter 2 General System Setup Hardware Considerations Figure 2 5 Potential crystal layout for LQFP 2 3 4 General filtering General purpose I O pins should have adequate isolation and filtering from transients Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 27 PCB routing considerations 2 3 4 1 RESET b and NMI b Critical input pins like RESET b and NMI b should have 100nF capacitors close to the MCU for transient protection Each pin has a weak internal pullup but an external 4 7kO to 10kO pullup is recommended As with power pin filtering it is recommended to minimize the ground loop for the capacitor and the VDD loop for the pullup resistor for these pins The RESET b pin also has a configurable digital filter to reject potential n
148. n timing and signal integrity Control and clock signals are routed point to point Components could and should be placed as close as possible to the MCU To avoid crosstalk keep address and command signals separate that is a different routing layer from the data and data strobes Kinetis Quick Reference User Guide Rev 0 11 2010 100 Freescale Semiconductor Chapter 11 Universal Asynchronous Receiver and Transmitter UART Module 11 1 Overview The UART module on the Kinetis family devices supports asynchronous full duplex serial communications with peripheral devices or other CPUs The UART module has three main modes of operation UART IrDA and ISO 7816 mode The following sections will discuss the features and use of the UART in UART mode In particular the use of the UART as an RS 232 serial communication port will be described For full details on the UART module including all of its features and modes of operation please refer to the device specific reference manual 11 2 Features The feature set available on UARTS can vary from UART to UART Basic UART functionality is available on all UARTs but the clock source for the module and the transmit and receive FIFO sizes can vary The table below lists the UART features that vary based on UART module instantiation Table 11 1 UART instantiations on Kinetis UART instance ISO 7816 supported FlFOs Module clock UARTO Yes 8 entry TxFIFO 8 ent
149. nce User Guide Rev 0 11 2010 178 Freescale Semiconductor 3 4 6 7 Appendix A How to Load QRUG Examples The workspace that opens up contains a Hello World project for both TWR K40X256 and TWR K60N512 There are many different RAM and flash combinations available in the Kinetis family which this project supports However for the processor on your tower board you should choose one of the targets below to maximize the memory space that the linker makes available for your chip TWR K40X256 RAM_64KB FLASH_256KB_PFLASH_256KB_DFLASH TWR K60N512 e RAM I28KB FLASH 512KB PFLASH Select the project and configuration you would like to run by choosing the project from the drop down box that is circled in red You may also right click on a project and select Set as Active To start select the flash target appropriate for your board as listed in the previous step Workspace hello world k4Q tower FLASH_256KB_PFLASH_256KB_DFLASH Sle i Files E amp hello world Cj hello world KRU tower FLASH 512KB PF 7 Cj hello world k4 tower FLASH 256k 7 Make Rebuild All Clean Add K Remove Source Code Control gt File Properties Set as Active The selected project will appear in bold font To ensure a fresh start clean the project first by right clicking on the project name and selecting Clean Kinetis Quick Reference User Guide Rev 0 11 2010
150. nd has completed sr EP SR WIP Poll SR until WIP goes low while sr amp EP SR WIP EP SR WIP Sr ezp rdsr cmd 9 1 2 4 Write and read FCCOB registers The flash command object registers consist of a group of 12 registers each 1 byte wide These are used for sending command codes and data to the memory controller FCCOB number Command parameter contents 0 FCMD code which defines the FTFL command 1 38 Flash address 23 0 4 B Data byte 0 7 The WRFCCOB command allows you to write to the flash common command object registers via the Ezport module and execute any command allowed by flash After receiving 12 bytes of data Ezport writes the data to FCCOB registers and then automatically launches the command within flash While the FAST RDFCCOB command allows user to read the contents of flash common command object registers NOTE If more than or fewer than 12 bytes of data are received by the WRFCCOB command the result will be unexpected Also because in Ezport mode the flash is in an NVM special mode commands that can be executed under secure mode are restricted Example code ezp wren cmd fccob 0 0x06 program longword command fccob 1 0x00 flash address is 0x00040c fccob 2 0x04 fccob 3 0x0c fccob 4 Oxff program data is Oxfffffffe fccob 5 Oxff fccob 6 Oxff fccob 7 Oxfe ezp wrfccob cmd fccob Loop until command has completed sr EP SR WIP Kin
151. nect printers keyboards mice game devices communication devices storage devices and custom devices USB 2 0 full speed allows 12 Mbps communication between the host controller and the device 14 2 Features USB Full Speed 2 0 compliant 12 Mbps Dual role operation 16 double buffered bidirectional endpoints e On chip USB full speed PHY Integration with device charger detection DCD module e 120 mA on chip regulator for MCU and external components 14 3 USB operation modes Device Mode The USB is configured to respond to external host requests In this mode the MCU has no control of the USB bus AII the transfers are started by the Host controller that is also providing the VBUS voltage The DCD was designed to run together with this USB mode First the DCD detects the host type and after the USB takes the control of the D and D signals Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 127 Voltage regulator operation modes Device k w Figure 14 1 USB device mode Host Mode In this mode the module works as the USB master having the entire control of the USB bus The Serial interface engine takes care of the timing and the frames The software stack takes care of the transfer management of the bus The host also needs to provide the 5 v VBUS power line to supply the remote devices in case its needed meN m Host Figure 14 2 USB host mode 14 4 Voltage reg
152. nfiguration mode that requires nine signals to communicate to a generic PHY The RMII operates at 50 MHz and requires synchronization between the PHY and the ENET RMII interface clock input EXTAL Depending on the PHY specifications the clock options used by the MCU can be PHY clock input PHY clock output if provided 12 5 1 Code example and explanation The following example code shows the registers needed to configure the MAC NET controller in RMII mode Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 117 RMII mode Example code PORTA PCR14 PORTA PCR5 PORTA PCR12 PORTA PCR13 PORTA PCR15 PORTA PCR16 PORTA PCR17 ENET RCR PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX PORT PCR MUX S ENET_RCR_MAX FL ENET RCR CRCFWD MASK ENET RCR RMII MODE MASK 4 RMIIO CRS DV MIIO RXDV 4 RMIIO RXER MIIO RXER 4 RMIIO RXD1 MIIO RXD1 4 RMIIO RXDO MIIO RXDO 4 RMIIO TXEN MIIO TXEN 4 RMIIO TXDO MIIO TXDO 4 RMIIO_TXD1 MIIO_TXD1 configENET RX BUFFER SIZE ENET RCR MII MODE MASK 12 5 1 1 Hardware implementation The following two figures show the connection needed from the MAC NET pins to any generic Ethernet PHYs in RMII mode The connection from the RMIIO CRS DV is dependent on the PHY implementation In the first figure the RMIIO CRS DV signal is connected to the RXDV CRSDV pin MIIO MDC RMIIO MDC MIIO MDIO RMIIO
153. ng since not using compare feature ACFE DISABLED ACFGT GREATER ACREN ENABLED DMAEN DISABLED ADC SC2 REFSEL REFSEL EXT Master Adc Config Master Adc Config Master Adc Config STATUS1A STATUS1B PGAEN DISABLED PGACHP NOCHOP PGALP NORMAL ADC PGA PGAG PGAG 64 AIEN OFF DIFF SINGLE AIEN OFF DIFF SINGLE ADC SC1 ADCH 31 ADC SC1 ADCH 31 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 171 Configuration example 18 2 1 5 Using ADC driver Configure ADC as it will be used but because ADC_SC1_ADCH is 31 the ADC will be inactive Channel 31 is just disable function There really is no channel 31 ADG Config Alt ADCO BASE PTR amp Master Adc Config config ADC 18 2 1 6 Calibrate ADCs Calibrate the ADCs in the configuration in which they will be used and then restore the desired configuration ADC Cal ADCO BASE PTR do the calibration The structure still has the desired configuration So restore it Why restore it The calibration makes some adjustments to the configuration of the ADC These are now undone config the ADC again to desired conditions ADC Config Alt ADCO BASE PTR amp Master Adc Config Repeat this for both ADC s However we will only use the results from the ADCI wired to the Potentiometer on the Kinetis Tower Card Repeating for ADC1 ADG Config Alt ADC1 BASE PTR amp Master Adc Config config ADC ADC Ca
154. nted Kinetis Quick Reference User Guide Rev 0 11 2010 162 Freescale Semiconductor Eu M Chapter 17 Touch Sense Input TSI Module The most relevant part of initialization is enabling the module after configuration In this application after initial configuration the TSI SelfCalibration is called This function performs a single scan at the beginning of the program to determine a baseline or untouched value for the electrodes In this application the baseline value and the touch value are stored in separate data arrays The touch value is equal to the baseline value of each electrode plus a delta value This delta value must be below the touch value but above the noise level of the untouched electrode By debugging an ideal delta value is determined It is always best to keep this delta value as high as possible but low enough that all touches are detected Notice that the TSI SelfCalibration function performs a single scan and waits for the scan to finish and the values to be updated in the registers The calibration function also disables the TSI module afterwards so that the following code enables the module as needed During application time the TSI is interrupt driven See Figure 17 5 Figure 17 5 Application start up procedure TSI Initialization TSI Self calibration Start continuous scanning Enable TSI module This application is specifically designed to show the small amount of code and CPU reso
155. ntroduction The MAC NET controller is one of the communication interfaces included with the Kinetis family The following block diagram represents how the MAC NET fits in the system to connect to a local area network MII RMII MAC NET Generic ETH PHY Interface Magnetics Russ a Some RJ45 manufacturers offer this in a single component Kinetis MCU Figure 12 1 MAC NET block diagram The MAC NET controller has three main components MAC Controller Controls the buffers and registers Controls the MIT RMII Interface and IEEE15888 controller Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 107 Overview MII RMII Interface Interacts with the ETH PHY It works in two modes MII and RMII s EEE1588 Controller Adds time stamping and enhanced timer support for Ethernet controller The following figure represents how the MAC NET interfaces with internal SoC connections Each component has its own clock MII EXTAL can be any value ENET RCR RMII MODE RMII EXTAL and PHY clk must be MIIO_TXCLK S mii SOMHzZ Mig n di 25MHz EXTA al ATAU ENET_1588_CLKIN PTE26 MAC NET Controller Timer Channels SIM_SOPT2 4 TIMESRC Figure 12 2 MAC NET interfaces The following sections describes some modes of operations and how the module needs to be configured 12 1 2 Features The MAC NET key value add comp
156. ntrol is not connection Charge ommen ommen be suitable for noisy possible pump generates VLL2 ded ded application and VLL 1 3 VLL3 driven externally 3 V Most rec Recom Allows external con This configuration is charge pump ena ommen mended trast control not suitable for 5 V bled Charge pump ded LCD generates VLL2 and VLL1 VDD must be 3V 4 VLL3 driven externally 3 V Most rec Recom Allows external con Requires an external voltage divider ena ommen mended trast control Because power supply and it bled Resistor bias ded the Charge Pump is must be a variable network generates disabled power con Contrast control is re VLL2 and VLL1 VLL3 sumption is reduced quired Not suitable for connected to external 5 V LCD voltage 3 V Charge pump is disabled 5 VLL2 to VDD internal 3 V Not rec VDD voltage must be connection VDD 2 0 ommen in an appropriate range V Charge pump gener ded for a 3 V LCD ates VLL3 and VLL1 6 VLL2 to VDD internal 5 V Not rec VDD voltage must be connection VDD 3 33 ommen in an appropriate range V Charge pump gener ded for a 5 V LCD Kinetis Quick Reference User Guide Rev 0 11 2010 150 Freescale Semiconductor SSS E E E E E ecran Chapter 16 Segment LCD Controller 16 3 Low power modes The SLCD module can function in any low power mode available in the Kinetis family RUN VLPR STOP VLPW VLPS LLS VLLSx NOTE End of frame wakeup is no
157. nts switches relays etc is critical to the end product s form there are some basic recommendations that can significantly affect the electrical performance and electromagnetic compatibility EMC of the PCB assembly Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 19 Floorplan 2 2 4 Connectors The PCB should be organized so that all the connectors are along one edge of the board and away from the MCU The concept here is to prevent placing the MCU in between connectors that can become effective radiators when cables are attached This also keeps the MCU from being in the path of high energy transients that can shoot across the board from one connector to another Connectors may be placed on adjacent edges of the PCB if necessary as long as the MCU is not in a direct path between the connectors Connector locations should allow for placement of filter components Noise must be suppressed at the connector before it can propagate onto the PCB There will be more information on this topic in the input filtering section 2 2 2 Power domains While many systems have only one power supply voltage they typically have clean and noisy sections The definitions of clean and noisy are not important the concept is that noise from one section should not interfere with another In general AC power should be separated from DC power and digital should be separated from analog Power doma
158. oise on this input after power up The configuration bits are located in the SIM SOPT6 register While use of this filter may negate the need for the pullup and capacitor mentioned above it is still recommended to use external filtering in electrically noisy environments 2 3 4 2 General purpose I O General purpose inputs such as low speed inputs timer inputs and signals from off board should have low pass filters series resistor and capacitor to ground to prevent data corruption due to crosstalk or transients The filter capacitor should be placed close to the MCU pin while the resistor can be placed closer to the source Inputs that come from connectors should have low pass filtering at the connector to prevent noise from propagating onto the PCB This requires a robust ground structure around the connector Series resistors for signals that come from off board should be placed as close to the connector as possible A filter cap closer to the MCU input pin may be required if the signal trace length is very long and can pick up noise from other circuits Output pins should not have any significant capacitance placed close to the MCU These signals can have capacitors at the load or connector to minimize radiated emissions if necessary 2 3 4 3 Analog inputs Analog inputs should have low pass filters as well The challenge with analog inputs especially for high resolution analog to digital conversions is that the filter design needs
159. om layers More information is given in the PCB Layer Stack up section below 2 3 2 Power supply decoupling and filtering As mentioned in the power domains section decoupling networks are used to separate domains Bypass capacitors while also called decoupling capacitors are the storage elements that provide the instantaneous energy demanded by the high speed digital circuits Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 21 PCB routing considerations Power supply bypass capacitors must be placed close to the MCU supply pins The basic concept is that the bypass capacitor provides the instantaneous current for every logic transition within the MCU Fortunately each Kinetis MCU has a low voltage internal regulator for the MCU core logic so the abrupt current demands of the internal high speed logic are not as critical However external signals demand energy from the power rails when they transition from one logic level to the other The bypass capacitors provide the local filtering so that the effects of the external pin transitions are not reflected back to the power supply which causes RF emissions The basic rule of placing bypass capacitors as close as possible to the MCU is still appropriate The idea is to minimize the loop created by the capacitor between the VDD and VSS pins The implementation of this rule depends on the number of mounting layers how the supplies are routed and the physical
160. on of the unlock steps The two step unlock sequences must execute within 20 clock cycles of each other Therefore interrupts must be disabled and single step debugging cannot be done during this section disable all interrupts asm CPSID i Write 0xC520 to the unlock register WDOG_UNLOCK 0xC520 Followed by 0xD928 to complete the unlock WDOG_UNLOCK 0xD928 enable all interrupts asm CPSIE i Clear the WDOGEN bit to disable the watchdog WDOG_STCTRLH amp WDOG_STCTRLH_WDOGEN MASK Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 15 Typical system initialization 1 4 2 2 Initialize RAM Depending on the application the next steps may be required First copy the vector table from flash to RAM copy initialized data from flash to RAM clear the zero initialized data section and copy functions from flash to RAM 1 4 2 3 Enable port clocks To configure the I O pin muxing options the port clocks must first be enabled This allows the pin functions to later be changed to the desired function for the application SIM SCGC5 SIM SCGC5 PORTA MASK SIM SCGC5 PORTB MASK SIM SCGC5 PORTC MASK SIM SCGC5 PORTD MASK SIM SCGC5 PORTE MASK 1 4 2 4 Ramp system clock to selected frequency The Multipurpose Clock Generator MCG provides several options for clocking the system Configure the MCG mode reference source and selected frequency output based
161. on the needs of the system 1 4 2 5 Enable pin interrupt In this example pin PTA4 is connected to a push button An interrupt is generated when the button is pressed A GPIO interrupt is used instead of an NMI interrupt because an edge sensitive interrupt is preferred versus a level sensitive interrupt This ensures that one interrupt will occur per button press Interrupts need to be enabled in the ARM core as described in the NVIC chapter Configure the PTA4 pin for its GPIO function PORTA _PCR4 PORT PCR MUX 0x1 GPIO is alt function for this pin Configure the PTA4 pin for rising edge interrupts PORTA PCR4 PORT _PCR_IRQC 0x9 Initialize the NVIC to enable the specified IRQ enable irq 87 NOTE To save space the enable irq function is not shown See the interrupts section for details on how to enable the IRQ Also to save space the interrupt service routine is not shown Kinetis Quick Reference User Guide Rev 0 11 2010 16 Freescale Semiconductor Ea S Chapter 1 General System Setup Software Considerations 1 4 2 6 Enable UART for terminal communication See in this document chapter 11 Universal Asynchronous Receiver and Transmitter UART Module 1 4 2 7 Jump to start of main function for application Jump to main process main Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 17 Typical system initialization Kinetis Quick Reference
162. onents are as follows The MAC NET controller is compatible with the FEC controller present in previous ColdFire MCUs and MPUs and low end PPC like the MPC5553 4 The hardware acceleration block helps software implementation with Pv4 and IPv6 support P TCP UDP and ICMP checksum generation and checking Configurable discard of erroneous frames Configurable Ethernet payload alignment to allow for 32 bit word aligned header and payload processing Kinetis Quick Reference User Guide Rev 0 11 2010 108 Freescale Semiconductor Se Chapter 12 ENET Module Industrial communication can require the use of time synchronization between distributed nodes The MAC NET provides support for the IEEE1588 standard to overcome one of the drawbacks of Ethernet 12 2 Configuration examples When using the MAC NET interface most of the time it runs over an RTOS Regardless of the type of RTOS some generic modes need to be defined and followed before integrating to an existing software The main 4 modes of operations are as follows e Basic Initialization basic steps needed to run the MAC NET PHY Management Interface configuration needed to get set PHY configurations MII media independent interface to the PHY RMII reduced media independent interface to the PHY 12 2 1 Basic MAC ENET initialization for a generic TCP IP stack Basic initialization is needed when configuring the MAC NET controller 12 2 1 1 Code exampl
163. onsiderations for the RMII mode Kinetis Quick Reference User Guide Rev 0 11 2010 120 Freescale Semiconductor Chapter 13 USB Device Charger Detection USBDCD Module 13 1 Overview This chapter intends to show the general configuration sequence and the service routines needed to be able to detect the host type and charger that is connected to the USB module 13 1 1 Introduction The USB battery charger specification defines limits detection control and reporting mechanisms that permit devices to draw current in excess of the USB 2 0 specification for charging or powering up from dedicated chargers hosts and hubs and for charging downstream ports These mechanisms are backward compatible with USB 2 0 compliant hosts and peripherals The USB ports on personal computers are convenient places for portable devices to draw current for charging their batteries This convenience has led to the creation of USB chargers that expose a USB standard A receptacle This allows portable devices to use the same USB cable to charge from either a PC or from a USB charger Freescale Kinetis microprocessors include a device charger detection DCD module capable of identifying if the device is connected to a PC host or to a USB dedicated charger 13 1 2 Features The USBDCD module works with the USB transceiver to detect if the USB device is attached to a charging port either a dedicated charging port or a charging host The system software coord
164. op3 VLLS3 ARM core enters SleepDeep Mode NVIC is disabled LLWU is used to wake up peripheral clocks are stopped all SRAM is operating content retained and I O states held most modules are disabled Kinetis Quick Reference User Guide Rev 0 11 2010 54 Freescale Semiconductor E Chapter 5 Power Management Controller PMC MODECTL 9 Very low leakage stop 2 VLLS2 ARM core enters SleepDeep Mode NVIC is disabled LLWU is used to wake up peripheral clocks are stopped Only portion of SRAM is operating content retained and I O states held most modules are disabled 10 Very low leakage stop 1 VLLS1 Lowest Power Mode ARM core enters SleepDeep Mode NVIC is disabled LLWU is used to wake up peripheral clocks are stopped All SRAM is powered down and I O states held most modules are disabled only two 32byte register file modules retained and I O states held The modules available in each of the power modes is a described in a table Please see Module operation in low power modes for the details of the module operations in the each of the low power modes 5 2 1 2 Features Mode Control controls entry into and exit from each of the power modes 5 2 2 Configuration examples How you decide which modes to use in your solution is an exercise in matching the requirements of your system and selecting which modules are needed during each mode of the operation for your application The best way to explain would be to work
165. or Locations Not Listed Freescale Semiconductor 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 Distribution Center 1 800 441 2447 or 1 303 675 2140 Fax 1 303 675 2150 LDCForFreescaleSemiconductor hibbertgroup com Document Number KQRUG Rev 0 11 2010 Information in this document is provided solely to enable system and sofware implementers to use Freescale Semiconductors 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 w
166. pa conc cuca exc adocned pit dul events utuadacksays Scales gas aiden atti aaReuenlaaiees 103 Uaa VART anisar TOU TT 104 1134 UART configuration for interrupts or DMA requests esent eiiean ninia 104 114 UART RS 222 hordware implementig aina E A aS 105 Chapter 12 ENET Module PARE 2 107 LCS TPO n a E E A E E A E E 107 RE T E E TEE AE E A A E ade 108 P A STEN a L AEE ra E E N God E E A E E E A A E i uppid SM Hi d pavad 109 12 2 1 Basic MAC ENET initialization for a genene TCP IP stack cscscisccssciscesseassossssevarseacseaseassssssiasedseansenasainedese 109 ILI Code cxample and Sx 0 e enine A E 109 12 3 PEY minazeme nt MEn Mec rr a R 113 1231 Codes Sea dnd ep LUA TT 114 R R a A rer rr ee ee 115 InI Gpdsscurmple and Cx T a R psaperan tania ueaeapLanaemimneiaaants 115 BAI ts T ETEL a ime A R Mine apiamaaionEN 116 123 RMN olini 117 1231 Code example Hs RS 1 Te a o ru RH V On pO A tae E S 117 fe HIachwere DaplerngniatDON eo as enn eS HUI R EHE DOSE EPA ESSO E AME HN OR ERE WAE U e t IP M NR R 118 120 PCB Dessin Recommend gd WN aes csi terere Eco E ur elp debis ERR RM EE CR d cbe ia nre dbinnat Saee uoesapir ba da beca esu pue Aes 119 L5 RT Pree HOS uere reiten asp derer N re tq ERE brotes ta pa Put ibiS ues ud umb pH E E dias 119 POLI Gasa Rovine and a ccu M A Era HZ ESTATE ga alaa Tia an E EEO 119 Chapter
167. port FB CSCR AA MASK auto acknowledge FB CSCR ASET Ox1 assert chip select on second clock edge after address is asserted Chapter 10 Flexbus Module FB CSCR WS 0x1 1 wait state may need a wait state depending on the bus speed T Set base address mask for 512K address space FB CSMRO FB_CSMR_BAM 0x7 Set BEO 1 to MRAM FB CSPMCR 0x02200000 Reference clock divided by 3 SIM CLKDIV1 amp SIM CLKDIV1 OUTDIV3 OxF SIM CLKDIV1 SIM CLKDIV1 OUTDIV3 0x3 Configure the pins needed to FlexBus Function Alt 5 this example uses low drive strength settings address Data PORTA PCR7 PORT PCR MUX 5 fb ad 18 PORTA PCR8 PORT PCR MUX 5 fb ad 17 PORTA PCR9 PORT PCR MUX 5 fb ad 16 PORTA PCR10 PORT PCR MUX 5 fb ad 15 PORTA PCR24 PORT PCR MUX 5 fb ad 14 PORTA PCR25 PORT PCR MUX 5 fb ad 13 PORTA PCR26 PORT PCR MUX 5 fb ad 12 PORTA PCR27 PORT PCR MUX 5 fb ad 11 PORTA PCR28 PORT PCR MUX 5 fb ad 10 PORTD PCR10 PORT PCR MUX 5 b ad 9 PORTD PCR11 PORT PCR MUX 5 b ad 8 PORTD PCR12 PORT PCR MUX 5 fb ad 7 PORTD PCR13 PORT PCR MUX 5 fb_ad 6 PORTD PCR14 PORT PCR MUX 5 fb ad 5 PORTE PCR8 PORT PCR MUX 5 fb ad 4 PORTE PCR9 PORT PCR MUX 5 b ad 3 PORTE PCR10 PORT PCR MUX 5 fb ad 2 PORTE PCR11 PORT PCR MUX 5 fb ad 1 PORTE PCR12 PORT PCR MUX 5 fb ad 0 control signals PORTA PCR11 PORT
168. ptions as Reset priority 3 a non maskable interrupt NMI priority 2 and Hard Fault priority 1 BASEPRI can be set only in privilege mode The reset value is 0x00 therefore all interrupts are enabled 3 2 3 1 Code example and explanation To set up BASEPRI a function from your development tools can be used For example in IAR tools the function is called set BASEPRI For disabling lower interrupt priorities set the lowest priority level that the application allows For example priority 5 0 are allowed BASEPRI must take the priority 5 Disable interrupts priorities from 0x06 Ox0F Set BASEPRI 0x50 2 For disabling all priorities to ensure atomic code the BASEPRI must take the maximum priority value available for Kinetis MCUs which is priority 15 Disable all interrupt priorities Set BASEPRI OxF0 Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 39 Configuration examples Kinetis Quick Reference User Guide Rev 0 11 2010 40 Freescale Semiconductor Chapter 4 Clocking System 4 1 Overview This chapter will demonstrate how to configure the Clocking System and the Multipurpose Clock Generator MCG module in various modes that a typical application may require The examples will show how to enable the on chip PLL for high speed operation and how to move backwards and forwards between using the PLL and a low power low speed mode for entering very low pow
169. put from the prescaler to the SMOD value If SMOD is configured as zero the module scans continuously without stopping after an end of scan 4 Configure the pin enable register PEN The 16 lowest bits of this 32 bit register enables each of the electrodes in active mode The low power mode scanning electrode is configured with bits 16 to 19 5 Configure the thresholds THRESHLDXx These registers configure each the low and high 16 bit thresholds for the 16 electrodes The low 16 bits configure the high threshold and the high 16 bits configure the low threshold The high threshold sets the OUTRGE bit when the capacitance measurement goes above that value and the low threshold sets it when the capacitance goes below that value The most common use case is to use these as an alarm for drastic changes to the capacitance or to wake up the module from low power mode 6 Enable the TSI module TSIEN Enabling the module is relinquished to the end of the configuration after everything else is set 17 4 4 Configuration Example The following example uses the four electrodes from the Kinetis Tower board The application detects touches These touches turn on and off the LEDs below the electrodes Baseline is not tracked but measured initially and assumed to be constant Baseline tracking is critical in applications where the environment is susceptible to change Because this example is intended to be simple baseline tracking has not been impleme
170. r is a brief description of the power management features of the Kinetis 32 bit MCU There are three modules covered in this chapter Power Management Controller PMC Mode Controller MC Low Leakage Wakeup Unit LLWU 5 1 2 Using the low voltage detection system 5 1 2 1 Features The LVD features includes the protection of memory contents from brown out conditions and the operation of the MCU below the specified VDD levels The user has full control over the trip voltages of two detection circuits The first is a warning detect circuit and the second is reset detect circuit Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 51 EE Oe EE KR Using the low voltage detection system As voltage falls below the warning level the LVW circuit flags the warning event and can cause an interrupt If the voltage continues to fall the LVD circuit flags the detect event and can either cause a reset or an interrupt The user can choose what action to take in the interrupt service routine If a detect is selected to drive reset the LVD circuit holds the MCU in reset until the supply voltage rises above the detect threshold There are two independent POR circuits for the MCU one for VDD and another for VBAT The POR circuit for the MCU will hold the MCU in reset based upon the VDD voltage The POR circuit for VBAT will reset both the RTC and OSC2 modules but will not reset the MCU If
171. r scanning period is used in low power mode this further reduces power consumption Configuration tips Enable the TSI clock gate before reading or writing TSI registers Initialize with the module disabled TSIEN 0 When a configuration change is needed make sure the module is not scanning SCNIP 0 It is not necessary to disable the module go into software triggered mode and wait for the current scan to finish Clear any pending flags error overrun out of range or end of scan before enabling interrupts The following is a typical TSI initialization Enable c1 SIM SCGC5 SIM SCGC5 PORTA PCR4 ock gates SIM SCGC5 TSI MASK SIM SCGC5 PORTA MASK PORT PCR MUX 0 Enable ALTO for portA4 Configure the number of scans and enable the interrupt H CST GENCS TST SCANC TSI THRESHLD5 TSI THRESHLD7 TSI THRESHLDS8 TSI THRESHLD9 Enable TSI module TSI GENCS TSI GENCS TSIEN MASK Enables TSI TSI GENCS NSCN 10 TSI_GENCS TSIIE MASK TST_GENCS PS 3 TST_SCANC_EXTCHRG 3 TSI_SCANC_REFCHRG 31 TSI SCANC DELVOL 7 TSI SCANC SMOD 0 TSI SCANC AMPSC 0 Enable the channels desired TSI PEN TSI PEN PEN5 MASK TSI PEN PEN7 MASK TSI PEN PEN8 MASK TSI PEN PEN9 MASK uint32 TSI CHAN5 OFFSET uint32 TSI CHAN7 OFFSET uint32 TSI_CHAN8 OFFSET uint32 TSI_CHAN9 OFFSET 1 Steps taken to enable the module
172. reescale Semiconductor SSS ee ee al Chapter 5 Power Management Controller PMC MODECTL 5 5 Mode transition requirements Table 5 2 Mode transition requirements 1 WAIT Execute WAIT This means that sleep now or sleep on exit modes entered with SLEEPDEEP clear Interrupt or Reset Execute STOP This means that sleep now or sleep on exit modes entered with SLEEPDEEP set Interrupt or Reset Interrupt goes to ISR no LLWU VLPR Reduce system bus and core frequency to 2MHz or less Flash access frequency limited to 1 MHz AVLP 1 Set RUNM 10 Note Poll VLPRS bit be fore executing VLPR spe cific code You also could wait 5 us instead of waiting for VLPRS VLPR Set RUNM 00 or Inter rupt with LPWUI 1 or Reset Note Poll REGONS bit before increasing frequen cy VLPR VLPW Execute WAIT VLPW VLPR Interrupt with LPWUI 0 VLPW Interrupt with LPWUI 1 or Reset VLPR VLPS LPLLSM 000 or 010 exe cute STOP VLPS VLPR Interrupt with LPWUI 0 VLPS AVLP 1 LPLLSM 010 exe cute STOP VLPS RUN Interrupt with LPWUI 1 or Reset Table continues on the next page Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor Source of wakeup pins and modules Table 5 2 Mode transition requirements continued 8 RUN LLS Set ALLS in PMPROT LPLLSM
173. ry RxFI Core Clock FO UART1 No 8 entry TxFIFO 8 entry RxFI Core Clock FO UART2 UARTn No No FIFOs double buffered Peripheral Clock operation Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 101 et Configuration example NOTE The table above describes the UART instantiations on the Kinetis family devices available as of the writing of this document As new Kinetis devices become available the UART instantiations could change Please refer to the Chip Configuration chapter of the device specific reference manual to verify the UART instantiation information for your device 11 3 Configuration example The following sections give a software example for using a UART as an RS 232 communication port to an 8 N 1 PC terminal The software is broken up into initialization transmit and receive sections The example uses the UART in a simple polled configuration but a description is provided to discuss how the UART could be used in interrupt mode or in conjunction with the DMA to help decrease CPU loading 11 3 1 UART initialization example The initialization code below can be used to configure the UART for 8 N 1 operation eight data bits no parity and one stop bit with interrupts and hardware flow control disabled The parameters passed in to this function are the UART channel to initialize uartch the module clock frequency for the UART in kHz sysclk and the desired ba
174. s Hash registers ENET IALR ENET IAUR ENET GALR ENET GAUR La O O t H H H Set the Physical Address for the selected ENET enet set address 0 ucMACAddress if configUSE MII MODE Various mode status setup ENET RCR ENET RCR CRCFWD MASK else ENET RCR ENET RCR MAX FL configENET RX BUFFER SIZE ENET RCR MAX FL configENET RX BUFFER SIZE ENET RCR MII MODE MASK ENET RCR MII MODE MASK ENET RCR CRCFWD MASK ENET RCR RMII MODE MASK endif FSL clear rx tx control registers ENET TCR 0 Setup half or full duplex f if usData amp PHY DUPLEX STATUS Full duplex unsigned portLONG ENET RCR DRT MASK ENET TCR ENET TCR FDEN MASK ENET RCR amp Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 111 Configuration examples else half duplex ENET RCR ENET RCR DRT MASK ENET TCR amp unsigned portLONG ENET TCR FDEN MASK Setup speed if usData amp PHY SPEED STATUS 10Mbps ENET RCR ENET RCR RMII 10T MASK if configUSE PROMISCUOUS MODE ERG ENET RCR ENET RCR PROM MASK endif ifdef ENHANCED BD ENET ECR ENET ECR EN1588 MASK else ENET ECR 0 endif Set Rx Buffer Size ENET MRBR unsigned portSHORT configENET RX BUFFER SIZE Point to the start of the circular Rx buffer descriptor queue ENET RDSR unsigned port
175. s like Address for VECTOR TABLE and VECTOR RAM come from the linker file extern uint32 VECTOR TABLE extern uint32 VECTOR RAM Copy the vector table to RAM if VECTOR RAM VECTOR TABLE for n 0 n lt 0x410 n VECTOR RAM n VECTOR TABLE n 2 After the table has been copied set the proper offset for the VTOR register Set the VTOR to be on RAM SCB VTOR VECTOR RAM Kinetis Quick Reference User Guide Rev 0 11 2010 38 Freescale Semiconductor _ E E b6hbpaQ YVDnhh _ _ ee M Chapter 3 Nested Vector Interrupt Controller NVIC It is important to follow the above mentioned steps in the order indicated This ensures there is always a valid vector table 3 2 3 Disabling priorities There are applications with important code where just certain interrupt priorities are allowed to interrupt this is because these interrupts are more critical to the application In other cases all the interrupts need to be disabled to ensure the code is atomic for example a context switch on Operating Systems The Cortex M4 provides the BASEPRI register that allows disabling lower interrupt priorities from any priority you choose or the option of disabling them all The BASEPRI is used as the NVICIPxx register Therefore 16 interrupt priorities can be masked and only the most significant nibble is used Please note that BASEPRI does not disable any of the fixed priority exce
176. s on LCD devices N A N A N A N A N A N A Signals AD 31 0 N A CS 5 0 Muxed Up to 32 N A N A N A N A N A N A N A mode address Up to 32 data lines AD 31 0 Non muxed Upto24 N A N A N A N A N A N A N A mode address AD 23 0 Up to 8 data lines AD 31 24 Up to 16 address AD 15 0 Up to16 data lines AD 31 16 LCD mode Up to 16 N A N A N A N A N A N A N A data lines AD 15 0 or AD 31 16 10 1 1 2 4 Burst cycles The device can be programmed to initiate burst cycles if its transfer size exceeds the port size of the selected destination The initiation of a burst cycle is encoded on the size pins For burst transfers to smaller port sizes FB_TSIZ 1 0 indicates the size of the entire transfer 10 1 1 2 5 Data Byte Alignment and Physical Connections The device aligns data transfers in FlexBus byte lanes with the number of lanes depending on the data port width Figure 10 2 shows the byte lanes that external memory connects to and the sequential transfers of a 32 bit transfer for the supported port sizes when byte lane shift is disabled or enabled Kinetis Quick Reference User Guide Rev 0 11 2010 96 Freescale Semiconductor PET Chapter 10 Flexbus Module Disable Enable Caterral Data Bus J2 b amp Port Momory 32 bit Port Money TICE Byte 2 yte 1 8yte By TL Byte Byte c INNEN ss o RRR dit Port Memory Uv e Eo 1 57 Port Memory E S
177. s primarily but not only designed to be used as a vehicle serial data bus meeting the specific requirements of this field Real time processing Reliable operation in the EMI environment of a vehicle Cost effectiveness Required bandwidth The FlexCAN module is an advanced CAN protocol controller which is fully compliant with the CAN 2 0B specification It also provides Enhanced powerful message filtering mechanism Flexible message storage and transmission scheme Automatic response to remote frames Flexible transmit priority scheme Global timer synchronization Rich error indication Different low power modes Remote wakeup capability It enables real time communication over the CAN bus while minimizing processor intervention Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 141 Configuration examples 15 1 2 Features In the FlexCAN module each Mailbox MB is configurable as Rx or Tx supporting standard and extended messages Configuration of an MB begins the Transmit Process for a Tx MB or Receive Process for an Rx MB The Rx FIFO with six levels of MBs can be enabled when the CPU has slow response time to each received message The ID filter table element can be configured for the Rx FIFO to accept only wanted messages FlexCAN also supports Individual Rx Mask configured per Mailbox or per Rx FIFO ID filter table element With timer SYNC feature enabled global net
178. size of the capacitors e Number of mounting layers PCBs with components mounted on the top side only will have a significant limitation on how close the bypass caps can be located due to the number of components that require space PCBs that have components mounted on both sides of the PCB allow closer placement of the bypass capacitors e Supply routing With the Ball Grid Array BGA package all of the VDD VSS pairs are routed to other layers under the package This allows easier attachment of the VDD and VSS pins to the power and ground planes within those layers The bypass capacitors can be placed in the area below the MCU with connections very close to the power pins See Figure 2 2 Kinetis Quick Reference User Guide Rev 0 11 2010 22 Freescale Semiconductor Chapter 2 General System Setup Hardware Considerations Place bypass caps on bottom layer in center e 9 of via field umm VDD mm VSS Figure 2 2 K60 TWR board top layer BGA pad arrangement e Supply routing For Quad Flat Pack QFP packages the power supply pins may be supplied radially to the MCU using traces rather than from planes While it is adequate to place the bypass capacitors close to the VDD and VSS pins on the traces leading to the MCU it is better to have the ground side of the bypass capacitor tied to the ground plane through a via and short trace close to the VSS pin and the VDD side tied to the power plane through a
179. ssumed the oscillator parameters in MCG C2 have not been changed MOG C1 MCG C1 CLKS 2 MCG C1 FRDIV 3 wait for the oscillator to initialize again while MCG S amp MOG S OSCINIT MASK wait for Reference clock to switch to external reference while MCG S amp MCG S IREFST MASK wait for MCGOUT to switch over to the external reference clock while MCG S amp MCG S CLKST MASK gt gt MCG S CLKST SHIFT Ox2 configure PLL and system clock dividers as FEI to PEE example MCG C5 MCG C5 PRDIV 1 MCG C6 MCG C6 PLLS MASK while MCG S amp MOG S PLLST MASK while MCG S amp MOG S LOCK MASK configure the clock dividers back again before switching to the PLL to ensure the system clock speeds are in spec core PLL 96MHz bus PLL 2 48MHz flexbus PLL 2 48MHz flash PLL 4 24MHz SIM CLKDIV1 SIM CLKDIV1 OUTDIV1 0 SIM CLKDIV1 OUTDIV2 1 SIM CLKDIVi1 OUTDIV3 1 SIM _CLKDIV1_OUTDIV4 3 MCG C1 amp MCG C1 CLKS MASK while MCG S amp MCG S CLKST MASK gt gt MCG S CLKST SHIFT Ox3 4 3 3 Configuring the FLL with the RTC oscillator as a reference The MCG can generate all the system clocks using the FLL with the RTC oscillator being used as the reference for it This has the benefit that an accurate reference clock can be used without the cost of additional external components in an application where the RTC is already
180. stem Reset all EP s iege ed Integration Module Configure EPO System USB clock gating Integration Clear all USB flags Modul Mo Sa Enable USB Interrupt sources Reset USB module software Set BDT base registers Clear all USBISR flags and enable weak pull downs Enable USB Reset interrupt Enable pull up resistor USBISR s USB STACK Waiting for Host connection Figure 14 6 Device mode initialization flow Host Mode Initialization To enable host support one bit needs to be set This enables 1 ms SOF start of frame generation in the USB module When a pullup is detected in the D or D signal the module generates the attached interrupt which indicates that one device is attached to the bus and the enumeration process must start Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 131 Hardware implementation System Send Reset signal NES eR XE Integration r Module Trigger SOF System packets USB clock gating Integration Module Reset USB module software Set BDT base Host registers Scheduler Clear all USBISR flags and enable weak pull downs Enable USB Attach interrupt BSS Ie mode support Waiting for Device Send requests To device nitialization Service routines NRnss 5922222292222222222222229222222222222227 See eee eee ESR ESTES ESSE ESSE SESS
181. t because the application running in the MCU has control of the entire bus This example code basically enumerates an HID USB mouse and sends that information to a terminal using the serial port It also reports all movements and button changes directly in the terminal To run this demo 1 Connect one serial cable between the board and the PC 2 Open a terminal console 8 bit 1 stop bit no flow control 115200 baudrate 3 Make sure that the jumper configuration is appropriate to supply 5 V through the USB port 4 Run the application The application will send a message that it is waiting for an HID USB mouse to be attached Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 137 ee Example code COM1 115200baud Tera Term VT File Edit Setup Control Window Help External Pin Reset 128 kBytes of RAM USB HID Mouse Waiting for USB Mouse to be attached Figure 14 15 Host state before connecting USB mouse After this message appears connect a USB mouse to the connector Automatically a message will appear stating that a single device was connected and the type of device COM1 115200baud Tera Term VT iol xi File Edit Setup Control Window Help Main OK Timer Init OK USB HOST Init OK USB HID Mouse Waiting for USB Mouse to be attached Attach Event Class 3 SubClass 1 Protocol device attached Interfaced Event interfaced setting protocol d
182. t supported in the LLS and VLLSx modes 16 4 Clock source The SLCD module supports four different clock sources See the Table 16 2 and Figure 16 1Figure 16 1 below SOPT1 OSC32KSEL CD SOURCE Internal Reference Slow Clock 32KHz SCTRIM MCG C1 IRCLKEN lt 1 LCDCLK Internal Reference Fast Clock 2MHz FCTRIM Figure 16 1 SLCD clock source options on the K40 family Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 151 Hardware considerations Table 16 2 LCD clock source options on the K40 family LCD Clock Source LCD and System Configuration 32 kHz Internal Reference SOURCE 1 ALTDIV 0 1 MCG_C1_IRCLKEN 1 MCG_C2_IRCS 0 MCG_IREFSTEN 1 MCG_C3_SCTRIM Slow internal reference clock selected See the Multipurpose Clock Generator MCG for more details 2 MHz Internal Reference SOURCE 1 ALTDIV 2 2MHz 64 MCG_C1_IRCLKEN 1 MCG_C2_IRCS 1 MCG_IREFSTEN 1 MCG_C4_FCTRIM Fast internal reference clock selected See Multipurpose Clock Generator MCG for more details System Clock SOURCE 0 SOPT1 OSC32KSEL 0 Crystal must be in the 32 KHz range The system oscillator drives a 32 kHz clock to the SLCD TSI and LPT RTC oscillator clock SOURCE 0 SOPT1 OSC32KSEL 1 RTC_CR_OSCE 1 RTC_CR_CLKO 1 RTC oscillator drives a 32 kHz clock to the SLCD TSI and LPT See RTC Os cillator Chapter and the RTC Clock Module 16 5
183. ter of the device specific reference manual Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 13 Typical system initialization 1 3 1 Device state during reset With the exception of the JTAG pins during reset the digital I O pins go to a disabled high impedance state with internal pullups pulldowns disabled Pins with analog functionality will default to their analog functions 1 3 2 Device state after reset After reset the digital I O pins remain disabled until enabled by software Also interrupts are disabled and the clocks to most of the modules are off The default clock mode after reset is FLL Engaged Internal FEI mode In this mode the system is clocked by the frequency locked loop FLL using the slow internal reference clock as its reference The watchdog timer is active therefore it will need to be serviced or disabled if debugging The core clock system clock and flash clock are enabled after reset to support booting Also the flash memory controller cache and prefetch buffers are enabled 1 4 Typical system initialization The following is a summary of typical software initialization The code snippets are taken from a hello world project written in IAR Embedded Workbench This project is available in the Kinetis sample code found in the file KINETIS512 SC zip which accompanies this users guide 1 4 1 Lowest level assembly routines These routines are assembly source code found in
184. ternal reference clock keep FRDIV at existing value to keep FLL ref clock in spec set IREFS to 1 to select internal reference clock MCG C1 MCG C1 CLKS 1 MCG C1 FRDIV 3 MCG C1 IREFS MASK wait for internal reference to be selected while MCG S amp MOG S IREFST MASK wait for fast internal reference to be selected while MCG S amp MOG S IRCST MASK wait for clock to switch to IRC while MCG S amp MCG S CLKST MASK gt gt MCG S CLKST SHIFT Ox1 now move to BLPI MCG C2 MCG C2 LP MASK set the LP bit to enter BLPI set up the SIM clock dividers BEFORE switching to VLPR to ensure the system clock speeds are in spec MCGCLKOUT 2 MHz in BLPI mode core 2 MHz bus 2 MHz flexbus 2 MHz flash 1 MHz SIM CLKDIV1 SIM CLKDIV1 OUTDIV1 0 SIM CLKDIV1 OUTDIV2 0 SIM CLKDIV1 OUTDIV3 0 SIM CLKDIV1 OUTDIVA 1 Now that MCGCLKOUT is at 2 MHz the MCU VLPR power mode may be selected Refer to the power management controller for details on this When the MCU transitions back to normal run mode the MCG will still be configured in BLPI mode The MCG is then configured in PLL engaged external mode by means of software as follows Moving from BLPI to PEE first move to FBI MCG C2 amp MCG C2 LP MASK clear the LP bit to exit BLPI move to FBE clear IREFS to select the external ref clock set CLKS 2 to select the ext ref clock as clk source it is a
185. tional GPIO measurement methods 17 4 TSI configuration All use cases for the TSI module refer to using capacitive electrodes as touch sensors For further information on using touch sensors and HMI see application notes titled How to Implement a Human Machine Interface Using the Touch Sensing Software Library document number AN3934 and Designing Touch Sensing Electrodes document number AN3863 at the Freescale webpage www freescale com touchsensing There are three modes of operation that must be considered when configuring the TSI The three modes are used in most applications Continuous active mode All enabled electrodes are scanned continuously e Scanning period is determined by SMOD register deal for scanning once the application is in run mode e Software triggered active mode Kinetis Quick Reference User Guide Rev 0 11 2010 160 Freescale Semiconductor Chapter 17 Touch Sense Input TSI Module All enabled electrodes are scanned once No scanning period as scan is run only once deal for scanning initially For example when the initial baseline values for the electrodes are determined Continuous low power mode Only one electrode is continuously scanned e Single enabled electrode can be used to wake up the system from low power mode e Scanning period is independent from the active mode scanning period Enabled when the MCU goes into low power mode if the STPE bit is set Usually a much slowe
186. tis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 157 Introduction Electrode Figure 17 1 Capacitive touch sensing electrode model A common measurement method for capacitive touch sensing is the RC method In this method a large pullup resistor approximately 1 MQ is connected to each electrode The processor or sensing ASIC measures the time it takes the electrode or capacitor to become charged when a finger approaches the electrode the capacitance increases and so does the charging time this charge time change is considered a touch The problem with this method is the pullup It is a weak pullup and thus susceptible to external noise The TSI uses a different measurement method It has two constant current sources one for charging and the other for discharging the electrode This creates a triangular wave This wave has a configurable peak to peak voltage or delta voltage Observe Figure 17 2 It shows the electrode current source oscillator structure External Electrode Figure 17 2 TSI Electrode current source oscillator Kinetis Quick Reference User Guide Rev 0 11 2010 158 Freescale Semiconductor eee Chapter 17 Touch Sense Input TSI Module The time the electrode takes to charge is directly proportional to the current source output and the size of the capacitor per the following formula I Flee 5 Coys V Figure 17 3 TSI electrode frequency formula The TSI measures the
187. two modes CPOL 0 CPHA 0 or CPOL 1 CPHA 1 Able to read erase and program on chip flash memory Able to reset Kinetis allowing it to boot from flash memory after firmware updated Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 85 Using the EzPort module 9 1 1 3 Command description When in Ezport mode Kinetis operates as a SPI slave and receives commands from an external SPI master and translates those commands to flash memory accesses Table 9 2 is acomplete list of commands supported by the Ezport module Table 9 2 Ezport commands Command Description Code Address Dummy Data bytes bytes byte 0 0 0 WREN Write enable 0x06 WRDI Write disable 0x04 0 0 0 RDSR Read status register 0x05 0 0 1 READ Flash read data 0x03 3 0 1 FAST_READ Flash read data at high speed OxOb 3 1 1 SP Flash sector program 0x02 3 0 8 section SE Flash sector erase Oxd8 3 0 0 BE Flash bulk erase Oxc7 0 0 0 RESET Reset chip Oxb9 0 0 0 WRFCCOB Write FCCOB registers Oxba 0 0 12 FAST RDFCCOB Read FCCOB registers at high Oxbb 0 1 1 12 speed WRFLEXRAM Write FlexRAM Oxbc 3 0 4 RDFLEXRAM Read FlexRAM Oxbd 3 0 1 FAST_RDFLEXRAM Read FlexRAM at high speed Oxbe 3 1 1 NOTE The 1 in the data bytes column means the SPI master could read data continuously from the Ezport module Starting from one byte the reading address will increment automatically while r
188. ud rate for communication baud NOTE The UART modules are pinned out in multiple locations so the initialization function below doesn t know which UART pins to enable The desired UART pins should be enabled before calling this initialization function void uart init UART MemMapPtr uartch int sysclk int baud register uintl6 ubd brfa uint8 temp Enable the clock to the selected UART if uartch UARTO BASE PTR SIM SCGC4 SIM SCGC4 UARTO MASK else if uartch UARTI1 BASE PTR SIM SCGC4 SIM SCGC4 UART1 MASK else if uartch UART2 BASE PTR SIM SCGC4 SIM SCGC4 UART2 MASK else if uartch UART3 BASE PTR SIM SCGC4 SIM SCGC4 UART3 MASK Kinetis Quick Reference User Guide Rev 0 11 2010 102 Freescale Semiconductor Chapter 11 Universal Asynchronous Receiver and Transmitter UART Module else if uartch UART4 BASE PTR SIM _SCGC1 SIM _SCGC1_UART4 MASK else SIM _SCGC1 SIM_SCGC1_UART5 MASK Make sure that the transmitter and receiver are disabled while we change settings UART C2 REG uartch amp UART C2 TE MASK UART C2 RE MASK Configure the UART for 8 bit mode no parity We need all default settings so entire register is cleared UART C1 REG uartch 0 Calculate baud settings ubd uint16 sysclk 1000 baud 16 Save off the current value of the UARTx BDH except for the SBR temp UART BDH REG uartch amp UART BDH
189. ulator operation modes The voltage regulator is composed of two different regulators the standby regulator and the run regulator You can select which regulator will be used by using the standby bit in the system integration module The input pin for the regulator is called VREGIN and the output pin is VOUT33 Run Mode Kinetis Quick Reference User Guide Rev 0 11 2010 128 Freescale Semiconductor Chapter 14 Universal Serial Bus OTG Module The regulating loop of the RUN regulator and the STANDBY regulator are active but the switch connecting the STANDBY regulator output to the external pin is open Standby Mode The regulating loop of the RUN regulator is disabled and the standby regulator is active The switch connecting the STANDBY regulator output to the external pin is closed Shutdown The module is disabled STANDBY Regulator Regulated Output i Voltage Figure 14 3 Voltage regulator block diagram When the input power supply is below 3 6 V the regulator goes to pass through mode The following figure shows the ideal relation between the regulator output and input power supply OUTPUT Volt 33 L MM 27 L r og PREMISE E 1 1 1 1 1 1 1 L 1 1 1 be 1 1 1 1 1 1 1 1 1 1 30 36 5 5 INPUT Volt Figure 14 4 Regulator output Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 129 Module configuration 14
190. ur data partition as 0 KB and the size of the EEPROM backup memory as 256 KB This creates 2 EEPROM subsystems 2KB in size with each subsystem being backed up by 128KB of EEPROM backup memory Example Code Write the FCCOB registers FTFL FCCOBO FTFL FCCOBO CCOBn 0x80 Selects the PGMPART command FTFL FCCOB1 0x00 FTFL FCCOB2 0x00 FTFL FCCOB3 0x00 FTFL FCCOB4 0x32 Subsystem A and B are both 2 KB FTFL FCCOB5 0x08 Data flash size 0 KB EEPROM backup size 256 KB FTFL FSTAT FTFL FSTAT CCIF MASK Launch command sequence while FTFL FSTAT amp FTFL FSTAT CCIF MASK Wait for command completion Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 81 E Using the FlexNVM 8 1 2 3 Combination In this configuration the FlexNVM is partitioned to use part of the available memory as data flash and part as EEPROM backup space The FlexRAM partitioned for EEPROM can range from a minimum of 32 bytes to the maximum size of FlexRAM 0 bytes selects a configuration with no EEPROM The size of the EEPROM backup space must be at least 16KB in size 8 1 2 3 1 Code example and explanation The following example uses a device with 256KB of FlexNVM and 4KB of FlexRAM This example assumes the part is erased and that the flash memory clock gate control is enabled in the system integration module SIM The default state in the SIM is flash memory clock enabled In this example
191. urces that are required to track touches with the TSI For advanced HMI functionality Freescale provides the Touch Sensing Software TSS library free of charge This library provides basic touch sensing and advanced API for HMI functions like multiple key detection grouping of controls like keypads sliders and rotaries It also implements advanced filtering and automatic baseline tracking providing further robustness to the measurements Also included is the standard GPIO based sensing method if 16 electrodes are not enough GPIO pins can be used to provide even more touch sensors For more info on the TSS library and downloads visit www freescale com touchsensing Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 163 TSI configuration 17 4 1 1 Code Example and Explanation After initialization in the TSI configuration the next step is to detect touches As can be seen in the figure the end of scan interrupt is used At each end of scan the interrupt subroutine is called by the TSI module and all post processing is done in the ISR There is no baseline tracking baseline is assumed to be constant and this way the main algorithm to implement is debouncing Debouncing is the process of validating that a button push or in this case a touch is valid Debouncing is something that needs to be done even in standard mechanical keyboards or buttons In mechanical buttons electrical disturbances caused by the two metal
192. urn on This will let you know your tower was put together correctly A 4 Terminal configuration The OSJTAG feature on the Kinetis Tower Board will create a virtual serial port that communicates to your computer over the USB cable connected in the previous section This virtual serial port is connected to UARTO on the TWR K40X256 and UARTS5 on TWR K60N512 Next open the Terminal Utility from the Start Menu by going to P amp E Multilink Embedded Toolkit gt Utilities gt Terminal Utility Configure the terminal client to use USB COM 115200 baud 8 data bits 1 stop bit and no parity Then click Open Serial Port to start the connection Terminal Window application v1 01 i i Duplex ra l saud BE aes Open Serial Port LLLI 1 H r 1 A jela 5 Terminal Window Clear Window A 5 Download sample code 1 Download the latest sample code repository for your Tower module from http freescale com twr k40x256 and http freescale com twr k60n5 12 2 Unzip the KINETIS512_SC zip file into any directory Go to kinetis sc build iar to see all the different projects available 4 The next section describes running the basic Hello World example but the same instructions can be used with other projects as well o2 A 6 Running the Hello World demo 1 Open IAR and go to File gt Open gt Workspace in the menu bar 2 Open the hello world eww workspace at kinetis sc build iar hello_world Kinetis Quick Refere
193. via and short trace close to the VDD pin 2 3 3 Oscillators The Kinetis MCU starts up with an internal digitally controlled oscillator DCO to control the bus clocking and then software is used to enable one or two external oscillators if desired The external oscillator for the Multipurpose Clock Generator MCG module can range from a 32 768kHz crystal up to a 32MHz crystal or ceramic resonator The external oscillator for the Real Time Clock RTC module is a 32 768kHz crystal Kinetis Quick Reference User Guide Rev 0 11 2010 Freescale Semiconductor 23 PCB routing considerations 2 3 3 1 RTC oscillator The RTC oscillator connected to the EXTAL32 and XTAL32 pins is the simplest to route Both pins are located on outside ring pads on the BGA package so the crystal can be placed on the top layer of the PCB close to the MCU Since this oscillator does not require any other external components the routing is straight from the crystal to the MCU pins While the 32 768kHz crystal is available in leaded cylindrical and surface mount packaging we recommend using the cylindrical package to simplify placement and routing The EXTAL32 and XTAL32 pins can be brought out directly from the MCU and the crystal can be placed as close as possible to the MCU which improves noise immunity Surface mount crystals may have pad spacing that is further apart than the leaded crystals making the routing and placement more complex 2 3 3 2 MCG os
194. wer and ground to digital systems is a topic that is discussed and debated in many textbooks and references The basic concept is to ensure that the MCU and other digital components have a low impedance path to the power supply The typical guidance that was given for one and two layer PCBs was to use wide traces and few layer transitions The recommendations for today s high speed MCUS follow those given for high speed microprocessor systems specifically use planes for power and ground This may raise the PCB cost but the benefits of crosstalk reduction reduction of RF emissions and improved transient immunity can be realized with lower overall production and maintenance costs In general the ground routing should take precedence over any other routing Ground planes or traces should never be broken by signals For packages with leads like the LQFP a ground plane directly below the MCU package is recommended to reduce RF emissions and improve transient immunity All of the VSS pins of the MCU should be tied to a ground plane Ground traces from a plane should be kept as short as possible as they are routed to circuitry on signal layers top and bottom Power planes may be broken to supply different voltages All of the VDD pins of the MCU should be tied to the proper power plane Power traces from the planes should be kept as short as possible as they are routed to circuitry pullups filters other logic amp drivers on the top and bott
195. work time can be synchronized by a specific message When multiple messages are pending for transmission the highest priority message is selected to be transmitted first There are three types of transmission priority scheme suitable for all application needs Lowest ID Lowest buffer number Highest local priority Transmission of messages can be aborted per request in order to transmit a higher priority message Remote request frames may be handled automatically by FlexCAN or by software Low power modes are also supported Other additional features are available please refer to the device specific reference manual 15 2 Configuration examples The SCI2CAN demo shows how to nitialize the FlexCAN module Configure a message buffer for transmit and or receive Read messages received in the interrupt service routine The demo codes are SCI2CAN bridge demo and Rx FIFO demo The bridge demo in the local node will send the character entered in the local HyperTerminal to the CAN loop back node which echoes it to the local node The Rx FIFO demo will configure Rx FIFO ID filter table elements in format A to receive eight messages with specified identifiers configure one MB as Rx MB and send nine messages to the CAN loop back node The local node will print received messages as well as the recipient information on the HyperTerminal The CAN loop back node by default is the local node itself and can be configured as the remote node via
Download Pdf Manuals
Related Search
Related Contents
Télécharger - Industrie Canada Pike Service Manual - Diagenode Nokia Asha 302 Bedienungsanleitung Document Control User Guide: System Set up ABS-360 トリニティテスタ De'Longhi KBR 3015 User's Manual ETB7818 User Manual Copyright © All rights reserved.
Failed to retrieve file