Home

LPCXpresso Experiment Kit User`s Guide

image

Contents

1. 9 09 9 9 9 9 ee e e 0 0 9 09 09 09 09 09 9 09 9 9 9 9 9 LI 909 09 090 099 09 09 e 09 09 09 0 09 09 09 ee 6 e o 09 09 09 9 09 9 09 9 ee 6 Made with 9 Fritzing org ira 2f Draadhaar Pannanfinne far DCD I ED Taetinm ure 30 Breadboard Connections for RGB LED Testing Fig 7 8 2 Lab 7b Control RGB LED In this experiment you shall create a program that can control the intensity of each of the three LED Select which color to adjust with a push button rotate around the three main colors red blue green at each press and set intensity level with the trimming potentiometer Base the program on the knowledge developed in previous PWM related experiments for example Lab 6d Below is the breadboard design that can be used U1 LPCXpresso board khe 4 HE pl 3 6 ny ae e e gt gt e e 5 2s grmpm d M iiia 33 e D e e o e o Made with 9 Fritzing org PT 24 Div enli meret CPannantiannec far DCD CD Cvnarimante Fi gure J Breadboard Connections for RGB LED Experiments Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 9 Control a 7 segment Display In this experiment you will learn how to control a 7 segment LED display The component included in the kit actually has two 7 segment digits More about this furthe
2. Place the PWM related functions in file pwm c 7 11 1 Lab 10a Control RGB LED In this experiment we will repeat the experiment in section 7 8 Control an RGB LED specifically section Lab 7b Control RGB LED Start by recreating the breadboard hardware in Figure 31 see page 62 The red LED is controlled by signal GPIO 28 PWM the green LED is controlled by signal GPIO 29 PWM and the blue LED is controlled by signal GPIO 30 PWM Signal GPIO 28 PWM can carry signal CT16B1 MATO assuming that pin PIO1 9 is configured for this and signal GPIO 29 PWM can carry signal CT16B1 MATT assuming that pin PIO1 10 is configured for this Note that signal GPIO 30 PWM pin PIO1 11 is not connected to any timer match output It was not possible to design the pcb to allow this For breadboard experiments it is however possible to for example select signal GPIO 2 MISO pin PO 8 that can carry signal CT16BO MATO Note that this is timer 0 and not timer 1 as the code above configures Either you generate the third PWM signal in software as we have done before or you create functions for generating PWM signals from timer 0 also In the latter case the breadboard connections must be updated connect signal GPIO 30 PWM to pin GPIO 2 MISO Repeat the exact functionality in Lab 7b Control RGB LED i e create a program that can control the intensity of each of the three LED Select with color to adjust with a push button rotate around the thr
3. Descriptions This function setup 32 bit timer 1 to generate EK an interrupt after specified time and then call a SU registered callback function parameters delay in ms and callback function pointer Returned value None c KK Ck kCKCkCk ck k kk KCkCk Ck ck k Ck KK Ck ck k kk KK K ck ck kk KK Ck ck k kk KK K ck k kk KK KK kk kCk kc kckck kk kc kckck k ck kk kk kk void registerCbAndDelay uintl6 t delayInMS void pF void register callback function PCB pF setup timer to fire in delayInMS ms enable 32 bit timer 1 interrupt NVIC EnableIRO TIMER 32 1 IROn KKK KK KR KKK KK KK KK KK KK K KAZ A KK K AKA KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK k kk Function name toggleLED Descriptions This function toggles output PIOU 2 Parameters None Returned value None KCKCKCKCKCkCkCk CK Ck k kok k Ck k k Ck k k k k k k k k k k k k k k k k k k k k k k ee void toggleLED void toggle LED on PIOU 2 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide KKK KKK KK KK KK AK kA X KAZ K kA AK AA X KAZ K kA AK AA X k AX AK kA KAZ Ck kCk ck ck ck k ck ck k ck ck ck k ck ck k ck ck ck k ck ck k kc kk Function name main Descriptions The main function Parameters None Returned value None c HK KK KK k ck k kk kk ck ck kk k ck k kc k kk k ck k kc k ck kc k ck kk ck ck k kc k kk ck ck k kc k ck kk ck kk ck
4. LPC SYSCON gt SYSAHBCLKCTRL 1 lt lt 12 LPC SYSCON gt UARTCLKDIV 0x1 divided by 1 LPC UART gt LCR 0x83 8 bits no Parity 1 Stop bit regVal LPC SYSCON gt UARTCLKDIV Fdiv SystemCoreClock LPC SYSCON gt SYSAHBCLKDIV regVal 16 baudrate LPC UART gt DLM Fdiv 256 LPC UART gt DLL Fdiv 256 LPC UART gt LCR 0x03 DLAB O LPC U RT PCR 0x07 Enable and reset TX and RX FIFO Read to clear the line status regVal LPC UART gt LSR Ensure a clean start no data in either TX or RX FIFO while LPC_UART gt LSR amp LSR_THRE LSR_TEMT LSR_THRE LSR_TEMT while LPC_UART gt LSR amp LSR_RDR regVal LPC UART gt RBR Dump data from RX FIFO return KKK KKK KKK KK KK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 105 Function name UARTSendChar Descriptions Send a byte char of data to the UART 0 port c parameters byte to send Returned value None ke hk KK Ck A K AKA kk KK KK KK KK Ck AAA A kCkCk ck k KK KK KAZ kk kCkCkckck kk kCkcCkckck kk kCk K kck kk ck kc kckck k ck k ck kk kk void UARTSendChar uint8 t toSend THRE status contain valid data while 1 LPC UART gt LSR 6 LSR THRE LPC UART OTHR toSend Kk kk k k k k k kok k k k k k k k k k k k k k k k k
5. 9 9 99 9 s 3 9 d gt ossaJdxadT7 w403 dxu MMM o B B N M o ES Made with 9 Fritzing org Figure 6 Breadboard Connections for LED1 breadboard view Figure 7 below illustrates how it can look like in reality Note that the connections on the breadboard are slightly different than outlined in Figure 6 above It demonstrates that it is possible to make the connections in many different yet compatible ways hi hd P m 2 Lad v Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Figure 7 Breadboard Connections for LED1 real photo The current through the Light Emitting Diode LED is limited and controlled by the series resistor It has to be limited since the voltage drop across the LED is fairly constant The voltage difference between the LED s forward voltage drop and driving voltage must be absorbed by the series resistor The current through the LED and series resistor can be calculated as Vsupply Vleddrop R Different LEDs have different typical current levels It can be 1 2 10 20 mA for smaller LEDs Bigger LEDs can have much higher ratings The LED forward drop voltage is typically 1 5V for a red LED Other colors have different forward voltage drops There are also variations between different brands Consult the LED s datasheet for details about forward voltage drop and
6. Forward declaration of the specific IRO handlers These are aliased to the IntDefaultHandler which is a forever loop When the application defines a handler with the same name this will automatically take precedence over these weak definitions f KKK KKK KKK KKK KK KK KAZ K kA X KAZ K kk AK AA X KAZ K kA KAZ K kA Ck ck k ck ck k ck ck kk ck ck k ck ck ck k ck ckck ck ck ck k kk kk void CAN IROHandler ALIAS IntDefaultHandler void SSP1 IROHandler ALIAS IntDefaultHandler void I2C IROHandler ALIAS IntDefaultHandler void TIMER16 0 IROHandler ALIAS IntDefaultHandler void TIMER16 1 IROHandler ALIAS IntDefaultHandler void TIMER32 0 IROHandler ALIAS IntDefaultHandler void TIMER32 1 IROHandler ALIAS IntDefaultHandler void SSPO IROHandler ALIAS IntDefaultHandler void UART IROHandler ALIAS IntDefaultHandler void ADC IROHandler ALIAS IntDefaultHandler void WDT IROHandler ALIAS IntDefaultHandler void BOD IROHandler ALIAS IntDefaultHandler void PIOINT3 IROHandler ALIAS IntDefaultHandler void PIOINT2 IROHandler ALIAS IntDefaultHandler void PIOINT1 IROHandler ALIAS IntDefaultHandler void PIOINTO IROHandler j ALIAS IntDefaultHandler void WAKEUP IRQHandler j ALIAS IntDefaultHandler i k _ ia _ b MMK K NNN m vl NL L So SS L i L ia NL L XL If the user program does not contain declarations of these routines handlers then they will default t
7. ms ticks 10 KK 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 kk k k k kk kk KICK KK Function name xbeeUp Descriptions XBee node up down callback parameters up will be 1 if the node is up 0 if it is down Returned value None KK Ck kCKCkCk AA kk KCkCk Ck k kk kCkCkCk ck k kk KK K KAZ AZ KK KAZ kk kCk K AAA KK KK kk kCk Ck kck kk ck kc kckck k ck k kk k kk static void xbeeUp uint8 t up p intf RFr Xbee Up 90 ein up devIsReady up KKK KKK KKK KK KK KK KKK K K K AAA A KK K KAZ A KK K KAZ KK KK K AAA KK KK KK KK KK KK KK KK KK k kk Function name xbeeNode ee Desoriptions XBee node discover callback Will be called as a response mom to a Xbee node discovery request All found nodes are fes reported back one by one through this callback parameters addrHi upper 32 bits of the 64 bit node address WW addrLo lower 32 bits of the 64 bit node address EK rssi signal strength Returned value None KK Ck kCkCkCk ck k kk KK ck ck kk kCkCk Ck ck k kk kCk Ck kck kk KK Ck ck k KKK Ck ck k kk kCkCkckck kk kCk kc kck kk ck k kckckck ck kk kk kk static void xbeeNode uint 2 t addrHi Winta t addrLo uinto t fssl printf RF Node x x rssi d r n addrHi addrLo rssi KOK 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
8. LPCXpresso Experiment Kit Users Guide Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Learn embedded programming with NXP s LPC 1000 family of Cortex M0 M3 microcontrollers NL EA USG 1206 Rev A LPCXpresso Experiment Kit User s Guide Embedded Artists AB Davidshallsgatan 16 211 45 Malm Sweden info EmbeddedArtists com http www EmbeddedArtists com Copyright 2013 Embedded Artists AB All rights reserved No part of this publication may be reproduced transmitted transcribed stored in a retrieval system or translated into any language or computer language in any form or by any means electronic mechanical magnetic optical chemical manual or otherwise without the prior written permission of Embedded Artists AB Disclaimer Embedded Artists AB makes no representation or warranties with respect to the contents hereof and specifically disclaim any implied warranties or merchantability or fitness for any particular purpose Information in this publication is subject to change without notice and does not represent a commitment on the part of Embedded Artists AB Feedback We appreciate any feedback you may have for improvements on this document Please send your comments to support EmbeddedArtists com Trademarks All brand and product names mentioned herein are trademarks services marks registered trademarks or registered service marks of their respective owners
9. en wikipedia org wiki Asynchronous serial communication Note and understand the difference between the signaling method asynchronous serial communication and standards of voltage signaling The signal drawn in Figure 5 illustrates the signal to from the UART peripheral inside the LPC111x It is a 3 3V logic signal This is common for communication between units on the same board or closely mounted boards RS232 is a common signaling standard with large voltage swings 3 15V that is used between units that are physically apart RS422 and RS485 are other commonly used signaling standards Communication is normally point to point meaning that a transmitter sends data to one receiver There are signaling standards that also supports network topologies for example RS422 and RS485 Higher protocol layers must then be involved in implementing addressing schemes between the nodes Note that this experiment requires a UART to USB cable from FTDI TTL 232R 3V3 Digikey 768 1015 ND or Mouser 895 TTL 232R 3V3 This cable is a bridge between a UART channel and USB communication Via USB it creates a virtual COM port on a PC The UART communication is tunneled over USB to the PC When plugging in the USB connector on a PC a driver will be installed See FTDI s installation guides for details how to install the driver for different operating systems http www ftdichip com Support Documents InstallGuides htm Copyright 2013 Embedded Artists AB
10. int i 0 printf xbeeData x x rssi d len d r n addrHi addrLo rssi len if len lt 1 1 return switch buf 0 Set LED request This is a two byte request where the data indicates if the LED should be turned on or off case RFPT SET LED if len gt 1 if buf 1 1 1 GPIOSetValue LEDI PORT LEDI PIN LED ON else GPIOSetValue LEDIl PORT LEDI PIN LED OFF break default for i 0 i lt len itt if i gt 0 amp amp 1 8 0 primer Men printf x buf i print Ven break KKK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name sendSetLedRequest kxk Descriptions Broadcasts a request over Xbee to set the status of the LED parameters ledOn should the LED be lit or not Returned value ERR OK Or an error code kxk KK Ck kCKCkCk AA kk KK K KAZ Ck KK Ck kck kk KK K ck k KK KK KK AXA KK Ck ck k kk KK K KAZ kCk AK ck ck kk ck kckckck k ck ck k kk kk static error t sendSetLedRequest uint8 t ledOn uinte t data l2l winto t id 0 data 0 RFPT SET LED data 1 ledOn return xbee send XBEE ADDRHI BROADCAST XBEE ADDRLO BROADCAST data 2 amp id int main void error t err ince t state 0 uint t otd tate 195W PRESSED Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 116 Set LED1 pin as output Se
11. A Ex eE n E BLDC Sensored NXP LPC1114 301 Figure 85 LPCXpresso IDE Program Flash Icon The next step is to select which processor to download to Select LPC1115 or LPC1114 from the list that is presented Then press OK button Note that this step is sometimes not needed because the LPCXpresso IDE can itself detect which processor it is connected to The next step is to browse to the file to download Press the Browse button Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 148 Frogram Flash Program target flash LPCT1xx NAP LPC11U37 501 on Options Display progress log Reopen on completion V Reset target on completion C Repeat on completion Connection Options Speed 250 Use JTAG interface Code Read protect CRP selection Nome Erase only required pages Figure 86 LPCXpresso IDE Program Flash Window Browse to the projects top directory and then Debug In this subfolder there is either a file ending with axf or bin Select one of these files Press the Open button 1 Find workspace and all sample apps b Accel systick irg wakeup gt Ji CMSISv2p00 LPCI1Uxx 5 4 Select either axf Tn 2 Find project or bin file top directory 3 Find Debug subdirectory gt J LCD ADC temp wdt wakdur gt Jy LCD graphics gt Jo lib_LPC11U14Dev Filnamn DemoApp axf Figure 87 Browse to File to Download Copyrigh
12. LPCXpresso Experiment Kit User s Guide Page 101 The UART signals from the LPC111x are made available on connector J18 see schematic below Signal GPIO 5 TXD carries the transmitted UART signal and GPIO 6 RXD is the received UART signal The experiments can take place on the pcb or on a breadboard Resistor R62 has been added for protection in case GPIO 6 RXD is programmed by mistake as an output If that would happen R62 limits the currents to safe levels so no output gets damaged FTDI UART to USB Connector D2 Figure 58 J18 D2 and R62 on Schematic Page 7 Note orientation of the 6 pos connector of the cable The black cable is positioned on pin 1 and is ground Figure 59 illustrates correct orientation when mounting the cable on the pcb Also note that the cable can actually power the system since the FTDI cable can supply a 5V voltage Diode D2 is included in case supply comes from multiple sources for example 2 1mm power jack J1 or USB connector J17 TITTEN TITT 113 ti its MAASSA UT seeeererrree Figure 59 LPCXpresso Experiment Kit PCB with UART to USB Cable Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 102 On the PC side a terminal application is needed A terminal application connects to a COM port and displays everything received and also allows sending data from the application via keyboard and sending a file There are a few good term
13. PIO1 3 AD4 CT32B1 MAT2 18 46 PIO AZ i PIO1 4 AD5 CT32B1 MATS WAKEUP GPIO 16 KE 20 47 PIO 33 GPIO CT32B0 ale KE 21 48 PO 34 PIO 8 CT16B1 _CAPO PIC A E 22 48 PIO a5 H PIOO 6 USB CONNECT SCK PIO R CONN 23 50 PIO 36 SWCLK PIOO 10 SCK CT16B0_MAT2 24 51 PIC 37 PIO3 0 a LED 25 52 PIO 38 QA PI 3 1 GPIO 22 LED 28 53 PI 30 08 PIO3 2 PIC 2 0 27 54 MT Figure 5 Signal GPIO 4 LED SSEL on Schematic Page 2 As a first step get a LED representing LED1 a 330 ohm resistor representing R4 two male to male prototype cables and the breadboard from the components bag Mount these on the breadboard and Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide connect to the LPCXpresso LPC111x board as illustrated in Figure 6 Note that only the target processor part of the LPCXpresso board is shown the black box labeled LPCXpresso board The photo to the left illustrates which part of the real LPCXpresso his black box represents LPC Link side LPC111x target side SELLE PIU R23 R49 x keer amp DIN R25 R51 LPCXpresso board S s 99 9 9 9 9 9 s 9 9 s j Pin 8 SSEL PIOO 2 d 3 L4 d d i d d F y d y D Y A3H GTTT2d1 O S6UdKId1 3 o S132g peppequ j Nor i re dXN ha psubrseg o B yI a HE EN A M 79V O OQ O OQ 9 9 9 91 J J p J An 2E VU V U ee eee s
14. Setup the timer to count up from zero to a match value This value is the cycle period D The value is calculated as cycle period count clock period 2 The counter counts up to this match value cycle period value and then restarts from zero This repeats for as long as the timer is enabled 3 Setup a match value which represents the duty cycle d D 4 When the cycle period counter restarts from zero the PWM output signal is set low When the cycle period counter match the match register the PWM output signal is set high As seen there are two separate steps for creating a PWM signal The first is to create a cycle period and the second is to create the duty cycle The cycle period is typically fixed throughout the application execution time and is a design parameter The duty cycle is on the other hand something that typically changes during the application execution time If the cycle period is not so critical just high enough then a suitable value for the period register can be 100 The resolution on the duty cycle is then 1 100 steps The match register is set to a value between 0 and 100 If higher resolution on the PWM signal is needed the cycle period can for example be set to 1000 Then the resolution is 0 196 In general it is no problem to have any value in the period register The value in the match register is calculated like this assuming 0 100 duty cycle as input parameter Match register Cycle regi
15. Welcome LPCXpresso alh x File Edit Navigate Search Project Run Window Help Div im O SHl amp 5 iQ leisg io o eM Ai Core Regi Periphera 7 E Welcome HN EE Bis E file C nxp LPCXpresso 4 0 5 123 Ipoxpresso pages registered htm gt E 4 E DemoApp gt 3 Binaries gt al Includes vo gt amp src PRESSO 4 gt Debug powered by Aicode red b amp src 1 Right click on L5 is fully activated gt s DemoApp axf arm le M ee DemoApp Debug lib id axf or bin file DemoApp Debu f presso 4 The software is now fully activated and can be used for production LPCXpresso can be used to E 9 nload applications containing up to 128KB of code into an LPC target DemoApp Debug DemoApp bir a DemoApp m md read the getting started guide for step by step instructions to build your first LPCXpresso project makefile objects mk sources mk DemoApp Debuc E Co Ctrl C the LPCXpresso Support page for new LPCXpresso software releases more example projects and announcements py j DemoApp Releas aa Dace Ctrl V b ashApp gt ES LCD ADC temp wat Delete P a LCD graphics m PCXpresso Forum community is exclusively built for LPCXpresso users and is an invaluable resource for getting help and gt TES lib LPC11U14Dev Rename F2 on use of the LPCXpresso tools and boards 4 t connected and join the LPCXpresso community Quick 23 N di RedC g Import Start her
16. contain valid data while UPC UART gt L R amp LSR_THRE F LPC UART gt THR toSend enable TX IRQ LPC UART gt IER IER THRE KKK KKK KKK KK KK KK KK KK K K AAA A KK K AA KK KK K KAZ KK KK K AAA A KK KK KK A KK KK KK KK KK KK kk Function name UARTGetCharBlock Descriptions Receive a char from UART O0 parameters None Returned value Received char KK Ck kCKCkCk AA kk KK KK KK KK K AAA A KK K AKA kk KK KAZ AX kCkCkCkck k kk KK Ck kck kk KK AK kck kk ck kckckck k ck k ck kk kk uint8 t UARTGetCharBlock void exercise to implement this function KKK KK KKK KK KK KK KK KK KK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name UARTGetChar Descriptions Receive a char from UART O0 parameters pointer to where to store received char Returned value TRUE if char received else FALSE KCKCKCKCKCKCKCk CK Ck k kok k Ck k kok 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 Ck k k k Ck k k k k k k Ck k ck ck ck uint8 t UARTGetChar uint8 t pRxChar uintia tmpT ll check if buffer is empty if rxHead rxTail return FALSE tmpTail rxTail 1 amp RX BUFFER MASK rxTail tmpTail pRxChar rxBuf tmpTail return TRUE Copyright 2013 Embedded Artists AB Page 110 LPCXpresso Experiment Kit User s Guide Page 111 Place the UART rel
17. else MouseInputReport bX MouseInputReport bY 0 MouselInputReport bmButtons Fix the code and verify that the mouse pointer can be moved diagonally and that text selection works Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 128 7 19 Extra Work with USB Host In this experiment you will learn how to work with an USB host interface This experiment requires the LPCXpresso LPC1769 board which has an USB Host interface 1 19 1 Lab 18a USB Host Using the USB Host interface of the LPC1769 it is possible to read write from a USB Memory Stick This has a wide range of uses including e Providing files for a web server e Data logging e Storing of initialization data The data on the memory stick is persistent allowing states and data to be kept between power cycles This experiment is based on the USBHostLite project that is part of the software package distributed with the LPCXpresso IDE It expects an msread txt file content not important to be present in the root of the memory stick s file system The file will be copied into possibly overwriting mswrite txt The memory stick should be formatted as FAT Note that an external 5V supply is needed either via J1 or J17 Also note that two jumpers shall be inserted in J11 pos 1 2 and 3 4 This experiment is based on the code examples that are delivered with the LPCXpresso IDE The code is structured very differently none of the code
18. low speed peripherals The basic clock frequency is 100 kHz but there are newer specifications that support higher speeds for example 400 kHz that is often supported called Fast mode Fm Higher frequencies of 1 MHz Fm 3 4 MHz High speed mode Hs and 5 MHz Ultra Fast mode UFm also exist but are less widespread The lC bus is a synchronous bus meaning that there is an explicit clock signal It builds on the master slave concept where one unit is a master and controls the communication One slave is addressed on the bus and is the other end of the master slave communication There can be many masters on the bus but only one active at a time The IC bus uses two bidirectional open drain lines pulled up by resistors e SCK serial clock the master always generates the clock e SDA serial data the master generates the data when transmitting to the slave The slave generates the data when transmitting to the master The picture below illustrates how many masters and slaves can share one lC bus MICRO CONTROLLER A LCD DRIVER STATIC RAM OR EEPROM CONTROLLER B Figure 55 12C Bus For more information about IC see http en wikipedia org wiki I5 C296 B2C There is a lot of details about the I4C bus that have not been covered in this short overview like how addressing works how bus arbitration works how read and write operations work how acknowledge of data works etc Have a look in chapter 1
19. then the shorting jumper should be placed in 2 3 position of J12 This is the left position for the jumper when viewed like in Figure 64 In this case an external power supply can power the RF module via U1 voltage regulator The RF module experiments are based on the interrupt driven UART code from Lab14c The UARTSendString and UARTSendBuf fer functions are needed 7 16 1 Lab 15a XBee RF Module This exercise requires at least two XBee modules and the same number of experiment boards to be able to test XBee communication One of the boards will be setup as a controller and the other as node s There are many different XBee modules with different functionality and programming interfaces The XBee module used in this experiment is XB24 AWI 001 It can be bought from for example Digikey XB24 AWI 001 ND or Mouser 888 XB24 AWI 001 Prepare the boards by plugging in the XBee module in the J15 socket and inserting a jumper in J12 at position 1 2 to get power from the LPCXpresso board The XBee driver is quite large and is found in the xbee c and xbee h files in the code framework that is provided Copy all drivers created so far into the project including the interrupt driven UART code from Lab 14c Below is the template for the main program include stdio h include LPCl1xx h include type h include board h include gpio h include delay h include xbee h Application configuration
20. 1 Stop bit regVal LPC SYSCON gt UARTCLKDIV Fdiv SystemCoreClock LPC SYSCON gt SYSAHBCLKDIV regVal 16 baudrate LPC UART gt DIM Fdiv 256 LPC UART gt DLL Fdiv 256 LPC UART gt LCR 0x03 DLAB 0 LPC UART gt FCR 0x07 Enable and reset TX and RX FIFO Read to clear the line status regVal LBC UART gt LSR Ensure a clean start no data in either TX or RX FIFO while LPC UART gt LSR amp LSR THRE LSR TEMT l LSR THRE LSR TEMT while LPC UART gt LSR amp LSR RDR regVal LPC UART gt RBR Dump data from RX FIFO initialize the transmit data queue txHead 0 txTail 0 txRunning FALSE initialize the receive data queue rxHead 0 rxTail 0 Enable the UART Interrupt NVIC EnablelRO UART IROn LPC UART gt IER IER RBR IER THRE IER RLS Enable UART interrupt KKK KK KKK KK KK KK KK KK KK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name UART IROHandler Descriptions UART interrupt handler parameters None Returned value None c KK Ck kCKCkCk ck k kk KCkCk ck ck k Ck KK AK Ck ck k kk kCkCk ck ck kk KK Ck ck k kk kCk Ck ck k kk kCkCk kck kk kCk Ck ck ck k k ck kc kckck k ck KK kk void UART IROHandler void volatile nints t IIRV lue LSRValue st tusk eg uint8 t Dummy Dummy volatile usint52 t tmpHead volatile Uints2 t tmpTail statusheg
21. 15 include i2c h 16 17 include uart2 h 18 20 Stop at first line in main function 23 uint8 t data 8 25 uint8 t uartlRead 1 6 uint32 t recvd 8 uint32 t len 6 GPIOInit init timer32 8 18 amp 1o D sj 32 I2CInit I2CMASTER 8 34 UARTInit 115288 35 uart2 init 115288 CHANNEL A 37 if uartlRead 38 UARTSendString uint8 t r nReading data from this UART r n on al fa m n ACU TE E Z m nm dDI ol DEN R Am A Z MANTI i m Figure 81 LPCXpresso IDE Stop at First Line in main Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 144 It is possible to set breakpoints by double clicking in the left margin A small dot marks that a breakpoint has been set to a specific source code line In Figure 82 below the breakpoint has been set to line 34 in function main A breakpoint is removed by double clicking on the dot c main c Lc stdio h c uart c c cr startup Ipcli c c timer32 c d Welcome ic main c 23 25 Reading data from UART1 and writing to UART2 and vice versa 4include type h include uart h include stdio h include timer32 h include gpio h include i2c h include uart2 h uint8 t uartiRead 1 Double click in left margin to set breakpoint uint32 t recvd 6 Ali e ee ae Double click again to remove GPIOInit init timer32 8 TTTCMASTER 6 al reakpoin
22. 2 defined as you will have to derive the address in several steps tip start searching for the LPC IOCON register at the end of the LPC11xx h file The register will be accessed as LPC IOCON PIOO 2 Is the derived address the same as in the LPC111x user s manual Now have a look in chapter 12 LPC111x LPC11Cxx General Purpose I O GPIO in the LPC111x user s manual for a description of how the general purpose I O functionality is controlled There is a GPIO data direction register that controls the direction of each pin in a port PIOO_2 belongs to port 0 Bit 22 in register GPIOODIR controls the direction of the pin See Figure 8 for details 12 3 2 GPIO data direction register Table 174 GPIOnDIR register GPIOODIR address 0x5000 8000 to GPIO3DIR address 0x5003 8000 bit description Bit Symbol Description Reset value Access 11 0 I0 Selects pin x as input or output x to 11 0x00 RAW 0 Pin PlOn x is configured as input 1 Pin PlOn x is configured as output 31 12 Reserved Figure 8 GPIO Data Direction Register Register GPIOODATA holds the current state of the pins in port 0 Bit 2 in this register reflects the state of pin PIOO 2 This is regardless if the pin is an input or output If a pin is an output the value in GPIOxDATA is driven to the pin Table 173 GPIOnDATA register GPIOODATA address 0x5000 0000 to 0x5000 3FFC GPIO1DATA address 0x5001 0000 to 0x5001 3FFC GPIO2DATA address 0x5002 0000 to 0
23. Artists LPCXpresso website 55 Import files int m F nrni bo rch JE Export projects to a Export projects and references to archive zip S Console 23 E Problems J Memory Red Trace Preview gt Smart Import wizard No consoles to display at this time G Build and Settings GI Debug and Run E E Extras N o h n Figure 75 LPCXpresso IDE Import Archived Project Next browse and select the downloaded zip file containing the archived projects Make sure all sub projects are selected to be imported see figure below note that the screen shot below is generic and the project names will be different Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 140 Develop Welcome page LPCXpresso File Edit Navigate Search Project Ru a UG bmw M2 a m FR jt Import archived projects zip Y Q6 MY j 1 Browse and select Select a directory to search for existing Ecli rojects g i i iuit ad archived project file vw gt Project Ex 2X 3 Core Regi Perip Select root directon powered by Milcode red 2 Select all sub projects in list production LPCXpresso can be used to PCXpresso project Y Quick Z3 HW RedC 69 Varia 9e E example projects and announcements CI Start here Project and File wizards G Import and Export invaluable resource for getting help an jes I
24. Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 107 Create a program that outputs a message with the help of printf on the UART channel and receive the message on a terminal program on a PC Also let the program verify that scanf works Remember that the UART must still be initialized before printf scanf are used 7 15 3 Lab 14c Interrupt driven UART handling and ring buffers Blocking function calls can be problematic since it can block other activities in a system A way to handle this is to create circular buffers both for received characters and transmission An interrupt handler place received characters in the receive buffer The program can then peek into the circular buffer to check if there are any received characters If not execution can continue with other tasks Below is code the implements UART receive functionality with the help of interrupts and circular buffers The interrupt routine ISR handle both receive and transmit interrupts Study the code to understand how it works include lpcl1xx h include uart h size of transmit buffer size MUST be power of two define TX BUFFER SIZE 256 define TX BUFFER MASK TX BUFFER SIZE 1 size of receive buffer size MUST be power of two define RX BUFFER SIZE 256 define RX BUFFER MASK RX BUFFER SIZE 1 define LSR RDR 0x01 define LSR OE 0x02 define LSR PE 0x04 define LSR FE 0x08 define LSR BI 0x10 define LSR THRE 0x20 de
25. From left to right the four pins in the picture are Red LED cathode All LEDs anode positive side Green LED cathode Blue LED cathode Harvatek HT 333RGBW A Any RGB LED with common anode and a low value of blue LED V around 3 2V will work This component is polarized Pin 1 is in the lower left corner in the picture to the left Lite On Inc LTD 4608JF Digikey 160 1536 5 ND Mouser 859 LTD 4608JF This is a Surface mounted component and can only be soldered to the pcb i e not used on the bread board This component is polarized There are green marks on the cathode side Harvatek HT17 2102SURC Possible substitute is Kingbright APT2012SURCK Digikey 754 1133 1 ND Mouser 604 APT2012SURCK LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB PNP transistor BC557B Q1 Q2 Q3 http en wikipedia org wiki Bjt_transistor Resistor 15 Kohm 7 pcs R1 R3 R35 R36 R41 R42 R59 http en wikipedia org wiki Resistor Resistor 0 ohm 1 pcs R2 http en wikipedia org wiki Resistor Resistor 330 ohm 30 pcs R4 R5 R6 R8 R9 R10 R11 R12 R13 R14 R15 R16 R17 R18 R19 R21 R22 R23 R25 R29 R30 R31 R32 R33 R34 R37 R38 R62 R63 R64 http en wikipedia org wiki Resistor This component is polarized One side of the plastic package is flat and the other side is rounded When mounting this component make sure it is turned correc
26. IIRValue LPC UART gt IIR IIRValue gt gt 1 skip pending bit in IIR IIRValue amp 0x07 check bit 1 3 interrupt identification Lf IIRV amp lue IIR RLS Receive Line Status LSRValue LPC UART gt LSR Receive Line Status if LSRValue amp LSR OE LSR PE LSR FE LSR RXFE LSR BI There are errors or break interrupt Copyright 2013 Embedded Artists AB Page 108 LPCXpresso Experiment Kit User s Guide Page 109 Read LSR will clear the interrupt Dummy LPC UART gt RBR Dummy read on RX to clear interrupt then bail out return if LSRValue amp LSR_RDR Receive Data Ready If no error on RLS normal ready save into the data buffer Note read RBR will clear the interrupt tmpHead rxHead 1 amp RX BUFFER MASK rxHead tmpHead if tmpHead rxTail tmpHead LPC UART gt RBR dummy read to reset IRO flag else rxBuf tmpHead LPC UART gt RBR will reset IRO flag else if IIRValue IIR RDA Receive Data Available Receive Data Available tmpHead rxHead 1 amp RX BUFFER MASK rxHead tmpHead if tmpHead rxTail tmpHead LPC UART gt RBR dummy read to reset IRO flag else rxBuf tmpHead LPC UART gt RBR will reset IRQ flag else if LIBValue IIR CTI Character timeout indicator Character Time out indicator functionality not implemented else if I
27. Interrupt s SysTick IROn 1 15 Cortex M0 System Tick Interrupt k x LPC1LIxx Specific ee Numbers HK KK KK ck k kk kk ck ck kk k ck kk ck k ck k ck kk ck ck ck kk kk kk WAKEUPO IROn 0 All I O pins can be used as wakeup source WAKEUP1 IRQn There are 13 pins in total for LPC11xx WAKEUP2 IROn WAKEUP3 IRON WAKEUPA IROn WAKEUP5 IROn WAKEUP6 IROn WAKEUP7 IROn WAKEUPS IROn WAKEUP9 IROn WAKEUP10 IRON WAKEUPII IROn WAKEUP12 IROn SSP1 IROn I2C IROn TIMER 16 0 IROn TIMER 16 1 IROn TIMER 32 0 IROn TIMER 32 1 IROn SSPO IROn UART IROn ADC IROn WDT IROn BOD IROn EINT3 IROn EINT2 IROn EINT1 IROn EINTO IROn IROn Type KO oo UIO G BUN F NN N Y N k A PEF NFO F D SSP1 Interrupt I2C Interrupt 16 bit TimerO Interrupt 16 bit Timerl Interrupt 32 bit TimerO Interrupt 32 bit Timer Interrupt SSPO Interrupt UART Interrupt A D Converter Interrupt Watchdog timer Interrupt Brown Out Detect BOD Interrupt External Interrupt 3 Interrupt External Interrupt 2 Interrupt External Interrupt 1 Interrupt External Interrupt 0 Interrupt PRR Q u NON WN ys FO No O1 15 16 U CO h2 P2 NY HOC O Or Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide An interrupts source is enabled by the call below The example enables the 16 bit timer 0 interrupt enable 16 bit timer 0 interrupt NVIC EnableIRQ TIMER 16 0 IROn It is also possible t
28. LPC111x user s manual chapter 12 4 1 Write read data operations In short the LPC GPIOx gt DATA register can be accessed on many different addresses The address used to access the register determines which bit s that is are accessed The function prototype is presented below Create a version of the function that utilizes the masked read functionality Also create a version of the function that utilizes the bit masking we have used in previous labs KKK KKK RK KK KK AK AA X KAZ K kA KAZ X kk K kA X kA K kA Ck Ck k kA ck ck ck kck ck k kc k ck k ck ck k ck ck ck k ck ckck kc kck k kk Function name GPIOGetValue kxk Descriptions Read bit value in a specific bit position UR in GPIO portX X is the port number c parameters port num bit position Returned value O if bit is not set else a non zero value if bit is set KK KK kk k ck k kc k kk ck ck kk k ck kk ck kk k ck k X kA ck ck kk ck ck k K ck kk ck ck k kc k ck kc k ck kk k ck kk ck k ck ck ck k kckck ck kck kk kk uints t GPIOGetValue uxnt352 t portNum uint52 t bicPosi implemented either with masked read functionality in the GPIO hardware or via direct bit masking with GPIOxDATA amp 1 bit Compare which functions is fastest A simple method is to create a loop and call the function a million times Turn on a LED before starting the loop and turn it off after the loop Manually clock the time the LED is on To get the execution ti
29. Lab 8a Test segment Display In this first experiment with a 7 segment display the microcontroller will not be used We will only use the LPCXpresso board to get the 3 3V supply Verify that you can turn on each segment of the display by moving cables on the breadboard The picture below illustrates the first breadboard setup with the display Note that the picture of the dual digit 7 segment display we have is not correct in the picture below In reality the digits are turned 90 degrees and have two digits There are however 10 pins on the component just as shown below LPCXpresso board ns m Segment A connect to ground to turn on Segment or ry i lt dre X Segment B connect to ground to turn on adn TUTTO Segment G connect to ground to tum on Segment E r i m i Anode digit 1 connect to 3 3V to control Anode digit 2 Segment F connect to ground to turn on SegmentD s le HMM Made with 9 Fritzing org Figure 35 Breadboard Connections for 7 segment Display Testing Also verify that you can select with digit of the two to control When working with digit 1 pin 9 shall be connected to 3 3V and when working with digit 2 pin 4 shall be connected to 3 3V Both pin 4 and 9 shall never be connected to 3 3V at the same time When working with both digits they must be time multiplexed Half of the time digit 1 is on and the other half digit 2 is on More about this
30. Read LM75 Temperature Sensor 96 7 14 3 Lab 13c Control LEDs via PCA9532 97 7 15 Work with a Serial Bus UART 100 7 15 1 Lab 14a Transmitting and Receiving via the UART 106 7 15 2 Lab 14b Direct printf to UART 106 7 15 3 Lab 14c Interrupt driven UART handling and ring buffers 107 7 16 Extra Work with RF module 112 7 16 1 Lab 15a XBee RF Module 113 7 16 2 Lab 15b GPS Receiver 117 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB 7 17 Extra Work with Serial Expansion Connector 7 17 1 Lab 16a 128x128 OLED Graphical Display 7 18 Extra Work with USB Device 7 18 1 Lab 17a USB Device HID 7 18 2 Lab 17b USB Device Mouse HID 7 19 Extra Work with USB Host 7 19 1 Lab 18a USB Host 7 20 Extra Work with Ethernet Interface 7 20 1 Lab 19a easyWeb Web Server 7 20 2 Lab 19b IwIP TCP IP Stack Web Server and FreeRTOS 7 24 Differences between LPCXpresso LPC111x and LPC1114 in DIL28 8 Projects 8 1 Interface a Color Sensor 8 2 Interface a Real time Clock RTC 8 3 Interface a GPS Module 8 4 Interface an SD MMC Memory Card 8 5 Interface an Accelerometer and Gyro 8 6 Control a LED Matrix 8 7 Create a Game with Display Accelerometer or Gyro 8 8 Create General Menu System for a Display 8 9 Retrieve Information from Web Servers 8 10 8 11 8 12 8 13 8 14 8 15 8 16 8 17 8 18 8 19 8 20 8 21 USB Mouse Emulation Registry in E2PROM
31. Real Time Dynamic Data with JAVA Applet Multiplayer Game via RF module Home Alarm System Polyphonic Audio Generation Audio Processing Home Automation Control a Robot RS 485 Network Interface an FPGA CPLD Chip Analog Electronic Experiments 9 LPCXpresso IDE How to get Started 9 1 Importing Projects 9 2 Working with a Project and Compiling 9 3 Debugging a Project and Downloading 9 3 1 9 4 Create own Projects by Copy Existing Project Downloading Just Code 9 5 Common Problems 9 5 1 Error message Failed on chip setup 123 123 126 126 127 128 128 129 129 130 133 135 135 135 135 135 135 136 136 136 136 136 137 137 137 137 138 138 138 138 138 138 138 139 139 141 142 146 150 151 152 LPCXpresso Experiment Kit User s Guide 10 Further Information 153 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 1 Document Revision History Wee oe e Work in progress 2013 01 29 Minor corrections clarifications 2013 02 25 Completed section 7 9 7 10 acsi PA6 2013 03 19 Completed section 7 11 7 14 Cleanup in variable declarations in code fragments Added instructions about creating driver structured source code PA 2013 04 08 Completed section 7 15 Changed all code fragments to use predefined typedefs for variable declaration Minor corrections 2013 06 13 Completed section 7 16 7 20 Minor corrections clarifications Copyr
32. Timer In this experiment you will learn how to work with a hardware timer 1 10 1 Lab 9a Create Exact Delay Function In earlier experiments a delay loop has been used to create delays This is not a good solution for two reasons First the processor will be fully occupied looping and cannot do any other useful work and it results in unnecessary power consumption Secondly if something interrupts the processor the delay length will no longer be correct In this experiment a more accurate delay function shall be created The processor will still be idling waiting for the delay to elapse Later on when we explore interrupts we will create a timer functionality that is more universal and power efficient Have a look in chapter 20 32 bit counter timer CT32B0 1 in the LPC111x user s manual for a description of the how the 32 bit timers works Note that chapter 21 describes the same timer for the LPC1115 the XL device family but for our purposes the timers are identical in the LPC111x family A timer can be quite complicated since it can be used for creating PWM signals and capturing external events with time stamps and other more or less advanced functions The principle to use a timer as delay function is as follows 1 Setup and start the timer to count up from zero to a set value The set value is calculated as time to delay count clock period The timer counts up increments 2 Wait until timer reaches the match value a bit
33. a TCP or a UDP connection There must of course be a TCP UDP server on the system that produces the real time data It is this server that the JAVA applet connects to Create such a system Let the server produce a stream of data for example a sinus valued signal stream Alternatively the server can stream the values from both analog inputs of the board Let the JAVA applet display this data stream in a suitable way 8 13 Multiplayer Game via RF module Create a multiplayer game with the help of RF modules For example ping pong on a graphical display 8 14 Home Alarm System Create a home alarm system with remove sensors that communicate wirelessly with a central It can even communicate with a GSM 3G phone modem and make a call send an SMS in case of an alarm Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 138 8 15 Polyphonic Audio Generation Create an audio output with speaker amplifier A low pass filtered PWM output can be used to generate the audio waveform Implement polyphonic tone generation and play a melody with multiple tones 8 16 Audio Processing Create an audio interface with both input and output Create audio effects for example an echo chamber Alternatively create a system for voice recording and playback 8 17 Home Automation Create a system for home automation There are many different systems that can be created for handling ventilation heating blower watering lighti
34. also be called synchronous function calls Place the UART related code in file uar t c and place the function prototype declarations in file uart h Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 106 1 15 1 Lab 14a Transmitting and Receiving via the UART Expand the UARTSendChar function to UARTSendString uint8 t pStr function transmits a zero terminated string the terminating zero is not transmitted and UARTSendBuffer uint8 t pBuf uintl6 t length functions Create a small program that makes use of these transmission functions Also let the program echo every received character Connect the FTDI cable and verify that the program works as intended Test to echo a longer string Received x where xis the received char from the LPC111x Type characters on the PC terminal program and observe the echoed response from the LPC111x Now test to send a series of 100 characters back to back from the PC This is for example done by sending a 100 byte long file Select Send file in the File menu What will happen Every received character results in several characters echoed back to the PC These echoed characters will take longer time than the time of the originally received character Characters are received at full speed back to back and soon both transmit and received FIFOs will be full Received characters will start to be missed The solution is flow control A receiver
35. and hence the buzzer The series resistor on the transistor s base connection limits the current since signal GPIO 7 BUZZ will be close to ground OV when pulled low by the LPC111x and a PNP bipolar junction transistor s emitter base voltage is fixed to around 0 7V Buzzer Figure 15 Buzzer on Schematic Page 4 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide LPCXpresso and mbed connector pin naming is generic LPCXpresso 7314 J2 n LPC1343 1114 LPCXpresso dual 1X27 pos VIN 4 5 5 5V 2 2d bY not used 3 30 Reset PIOO 0 GPC D0 RES 4 31 PIOO 8 MOSI CT16BO MAT1 SWO APIC 1 MO 5 32 FTH AX PI O 8 MISO CT16B MATO GPIO 2 MISQ amp 33 EIH RXFP PIO2 11 SCK PIO 3 SCK T 34 EIH TX PIOO 2 SSEL CT1660_CAPO SPIO 4 4 ED S amp B 35 FTH IX PIO1 7 TXD CT32B0_MAT1 GPIO 5 TXN g 2 DM pili E hm aed Ti RA i EL ie LI i 4 DF PIOO 7 CTS LED O GPO BUI 38 PI 24 KE FIO2 0 DTH PIO 8 LED SS 12 39 PO 25 VBl PlO2 1 DSH PIC 9 4 FD 13 40 PIO 26 SDA PlO2 2 DCD PO 10 4 FD 14 41 PI 27 5 TDI PFlOO 11 ADO CT32B0 MAT3 PIC AINC 15 42 F 2B PW TMS Pl 1 O AD1 CT32B1_CAPO wie AT 18 43 PIO 29 PW TOO PI 1 1 AD2 CT32B1 MATO PIC AINZ 17 44 PIO 30 PWM TRST PIO1 2 AD3 CT32B1 MAT1 PIO A 18 45 PIO 31 ED CA2 SWDIO PIO1 3 AD4 CT32B1 MAT2 18 46 PIC 32 GPIC PIO1 4 AD5 CT32B1_MAT3 WAKEUP PI 16 KE 20 AT PIO 33 6 PIC O1 5 RTS CT32B0 CAPO F E Ail 48 PO 34 PIO1 8 CT
36. and should be treated as such Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Table of Contents 1 Document Revision History 7 2 Introduction 8 2 1 Features 8 2 2 ESD Precaution 9 2 3 General Handling Care 9 2 4 Code Read Protection 9 2 5 CE Assessment 9 2 6 Other Products from Embedded Artists 9 2 6 1 Design and Production Services 9 2 0 2 OEM Evaluation QuickStart Boards and Kits 10 3 LPCXpresso Experiment Kit 11 3 1 Embedded Systems Programming 12 4 Kit Content 13 5 Powering Options 25 6 Soldering 27 6 1 Component Placement 27 7 Experiments 29 7 1 Preparation 29 7 2 Control a LED 29 7 2 1 Lab 1a Control LED 30 7 2 2 Lab 1b GPIO and Bit Masking 39 7 2 3 Lab 1c Delay Function LED Flashing 36 7 24 Lab 1d Morse Code 37 7 3 Read a Digital Input 38 7 3 1 Lab 2a Read Push button 38 7 3 2 Lab 2b GPIO and Bit Masking 41 7 3 3 Lab 2c Logic between inputs and output 41 7 3 4 Lab 2d Toggling LED 44 7 3 5 Lab 2e Sampling of Inputs 44 7 4 Control Multiple LEDs 46 71 4 1 Lab 3a LEDs in Running One Pattern 46 7 4 2 Lab 3b Control of Running One Pattern 47 7 4 3 Lab 3c Rotary Switch Control of Running One Pattern 48 7 5 Print Messages 49 7 5 1 Lab 4a Semihosting and printf 49 7 0 2 Lab 4b Semihosting Performance Test 51 7 9 3 Lab 4c Printing Events 91 7 5 4 Lab 4d Reading from the Console 91 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide
37. becomes an output Figure 24 shows the breadboard setup for connecting the trimming potentiometer to the LPCXpresso board pin 15 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 2 Analog Inputs GND Figure 23 Trimming Potentiometer on Schematic Page 4 Begin with building the breadboard circuit below U1 LPCXpresso board MON Pp dba de te Pin 15 bal 49000 08439 42 GPIO 11 AINO ee eeeee eeeee ee PIOO 11 ADO sal 33433 W 33339 33 D e e 0 eeecee ee w F 1 Made with 9 Fritzing org Figure 24 Breadboard Connections for Trimming Potentiometer R7 Create a function for reading the analog value of a specified analog channel Use constants to define the possible channels to convert Tip 1 Read in the ADC chapter in the LPC111x User s Manual about the CR register By setting bit 24 and the channel to convert in bit 0 7 a conversion is started Tip 2 A conversion takes some time Check the DONE bit in register ADOGDR or ADODRx where x is the channel to convert Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Tip 3 After a conversion the ADC is stopped by resetting bit 24 in the CR register Tip 4 When reading the converted value note that the register value must be shifted in order to be in the interval of 0 1023 bit 0 9 valid Below is the program structure to use to read the trimming potentiometer value once every 250 ms
38. current level The red LED s included in the component kit has a forward voltage drop of 1 5V and designed for 10mA current With a 330 ohm series resistor the current is limited to about 5mA which is OK also The light intensity at 5mA is acceptable for our experiment purposes The current level determines the driving method For moderate levels typically below 4 mA most microcontrollers and logic gates can drive the LED directly This is the method used in our experiments Some microcontrollers have high current capacity outputs The LPC1110 family microcontrollers have a 20 mA output pin PIOO 7 see datasheet for details Almost all output pins have higher current capabilities sinking current than driving current It is therefore common to connect LEDs like in Figure 4 with the cathode connected to the microcontroller pin When driving current is flowing into the micro controller pin i e sinking current Another reason for letting the microcontroller drive the LED by sinking current is that most microcontrollers power up with all pins as inputs with pull up resistors enabled This basically means that the pin will be driven high weakly The LED will not turn on shortly during a power up It will be at a known off state until the application program controls the LED actively If the driving current is higher gt 5 mA a high current driver chip can be used or discrete transistors mosfets A LED is a polarized component meaning
39. dual 7 segment display The ISR alternates which digit that is updated The main program just set up the timer ISR and writes the segment outputs in a global variable that the timer ISR can read when updating the digits The suggested program structure for the timer ISR is presented in the code block below Declare variable to store digit outputs volatile uint8 t digitSegments 2 Define Interrupt Service Routine for 32 bit timer 41 void TIMER32 1 IROHandler void name of function is predefined counter that indicate active digit numbered 0 and 1 Statio tinto activebigit if activeDigit 0 Disconnect anode of digit 0 pull control signal high Send segment outputs via SPI for digit 1 Connect anode of digit 1 pull control signal low activeDigit 1 else Disconnect anode of digit 1 pull control signal high Send segment outputs via SPI for digit 0 Connect anode of digit 0 pull control signal low activeDigit 0 clear interrupt Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 14 Work with a Serial Bus 12C Note that the breadboard cannot be used in these experiments The chips used are surface mounted and these must be soldered to the pcb before starting In this experiment you will learn how to work with the Inter Integrated Circuit Bus or I4C bus for short It is a multi master bus for relatively
40. e e e qe J 1 ne k P e ee ar P ee e ee e e ee e ee ee e ee ee e 34 349348 24949 8 9 9 2 Mid 0 283 e CE Made with J Fritzing org Figure 42 Breadboard Connections for Dual Digit 7 segment Display with Shift Register Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Create a subroutine for updating the shift register Let the subroutine take an 8 bit variable as input where bit 0 represents segment A bit 1 segment B etc The suggested structure of the subroutine is presented in the code block below void updateShiftReg uint8 t segments Wines DXtent Pull SCK and MOSI low pull SSEL low wait lus Loop through all eight bits ror bitCnt 0 bitCnt lt 8 bitCnt output MOSI value bit 7 of segments wait lus pull SCK high wait lus pull SCK low shift segments segments segments lt lt 1 Pull SSEL high The suggested delay values are quite small 1us They can be smaller according to the 74HC595 datasheet but for simplicity you can use 1us The previous delay function created had a resolution of ims Update this function so that it is possible to also have smaller values in the microsecond region Finally create a look up table for getting the segment values given a number between 0 and 9 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 740 Work with a
41. found in the schematic on page 4 upper left corner LED1 s cathode is connected to signal GPIO_4 LED SSEL LED1 s anode is connected to 3 3V via a current limiting series resistance Figure 4 illustrates were LED1 can be found in the schematic On schematic page 2 we can see that this signal is connected to PIOO 2 on the LPCXpresso LPC1115 board Figure 5 illustrates where to find the signal and also where to find the 3 3V supply Tr 2 Analog Inputs 8 RED LEDs LED3 330R RED v R12 D 10 LED CA1 k m LEDA 330R 5 RED Figure 4 LED1 on Schematic Page 4 LPCXpresso and mbed connector pin naming is generic LPCXpresso 4 J2 m LPC1343 1114 LPCXpresso dual 1X27 pos E GND 1 3 f 28 3V3 VIN 4 5 5 5V 2 FEE T not used 3 30 Reset PIOO 0 PIO RFS 4 31 PIOO 8 MOSI CT16B0 MAT1 SWO P o a 5 32 FTH HRXMh PIOD 8 MISO CTIGB MATO F MISO amp 33 ETH AXP Te 34 ETH TAN Plog 2 SSELTCTIGBO CAPO OP 41EDASEL 8 35 FTH TXF f T aP S LAD 0 00 0 SJ 36 DM PIO1 6 AXD CT32B0 MATO PIO amp RXD 10 37 E Piao 7 CTS LED PIO 7 BLIZZ 11 38 O 24 K FIO2 0 DTR S 3 85 12 39 O 25 VB Pl 1 DSR i 1 5 13 40 iQ 26 50 PlO2 2 DCD PC 10 4 ED CA 14 41 PI 27 5 TDI PlOO 11 ADO CT32BO0 MAT3 PIC AING 15 42 PIO 2B PW TMS PIO1 0 AD1 CT32B1 CAPO PIC AT 18 43 P O 29 PW TOO PIOH 1 AD CT32B1 MATO PIC AT 17 44 PIO 30 PWYM TRAST PlO1 2 AD3 CT32B1 MAT 1 PIC 14 AIh 18 45 PICO 31 1 ED CA2 SWDIO
42. in setting the bit rates Some features like auto flow control auto baud modem signaling and RS 485 functionality will not be covered by these experiments The transmit signal TXD is available on pin PIO1 7 signal GPIO 5 TXD in the schematic and the receive signal RXD is available on pin PIO1 6 signal GPIO 6 RXD in the schematic Below are some functions to get the UART functionality started The UARTInit function will initialize the pin muxing enable the UART peripheral setup the bit rate and empty the FIFO s include V LPCIIsx h include uart h define LSR RDR 0x01 define LSR OE 0x02 define LSR PE 0x04 define LSR FE 0x08 define LSR BI 0x10 define LSR THRE 0x20 define LSR TEMT 0x40 define LSR RXFE 0x80 KKK KKK KKK KK KK K K AAA KK K K AAA A KK K KAZ A KK K KAZ KK KK K kA KK KK KK KK KK KK KK KK KK KK KK kk Function name UARTInit k k Descriptions Initialize UARTO port setup pin select XR Glock parity Stop bits FIFO eto parameters UART baudrate Returned value None KK Ck kCkCkCk AA kk KCkCk Ck k kk KK K AXA Z kCk Ck kck kk kCkCkCkck k KK CkCk Ck AAA kCkcCkckck kk kCk KK KK kc kckck k ck ck k kk kk void UARTInit uint52 t baudrate Mints TE PALV uint32 t regval LPC IOCON gt PI01 6 amp 0x07 UART I O config LPC IOCON gt PI01 6 0x01 UART RXD LPC IOCON gt PI01 7 amp 0x07 LPC IOCON gt PI01 7 0x01 UART TXD Enable UART clock
43. input and sets the appropriate segment outputs for each input value As a variation to above modify the code so that every time you press the push button the number is incremented Another variation is to create a program that creates a running one segment in a circular structure segment A gt B gt C gt D gt E gt F gt A etc Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 1 9 3 Lab 8c Control 7 segment Display cont In this experiment you shall present the value on ADC input 0 on one digit in the display When turning the trimming potentiometer a value between 0 and 1023 will be read 10 bit resolution This value shall be converted to a number between 0 and 9 One obvious conversion is ADC value 1024 10 In theory this conversion is correct but since we are working with integer values the term ADC value 1024 will always be 0 By rewriting it as ADC value 10 1024 the precision will be kept Assuming that the calculations are done on 16 bit variables the calculation of ADC value 10 is still within 16 bits of precision so no overflow will occur The translation ADC value 10 1024 works perfect for presenting the value 0 9 Consider however how a function to present the value 0 10 would have looked like Figure 37 present the proposed conversion function in black and a function that would work well for the range 0 10 in red Output value ADC value offse
44. k k k k k k k k k k k k k k k k k k k Ck CK CK Ck Ck k k Ck Ck k k k k k k Kk Ck Ck Ck Ck Ck k k Ck Ck k Ck Ck Ck k Function name UARTReceive Descriptions Receive a block of data from the UART 0 port based KA on the data length parameters buffer pointer data length Returned value Number of received bytes KK KK KK KK KK KK KK KK KK KAZ KK kCkCk kck KK KK KAZ kk A AK K AAA kCkCk ck ck KK KK KK KK kc kckck k ck kk kk kk uint32 Lt UARIBecerirve ulint9 t buffe r uinti Lr length uint32 t blocking ulnt32 reovd 0 lnto2 t BboReocv length if blocking 1 while toRecv 1 wait for data while LPC UART gt LSR amp LSR RDR buffertt LPC UART gt RBR recvd toRecv else while toRecv 1 break if no data if L LPC UART 2LSR amp LSR RDR break xbuffer LPC UART gt RBR recvd toRecv return recvd Function UARTSendChar transmits one byte char of data UARTReceive is a function that can receive data either blocking or non blocking Blocking means that the processor spends all time idle waiting in the function call for the wanted number of characters to be received Non blocking means that the function returns with the number of available characters that was were received It will be somewhere between zero 0 and length number of characters Another name for non blocking is asynchronous function call Blocking calls can
45. 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 Ck k k k k k k Ck k k k Ck kc k ck ck void initPWM uintl6 t cycleLengthInUs LPC SYSCON gt SYSAHBCEKCTRL 1 lt lt 8 Enable timer 1 enable clock to block setup I O pins to be MAT outputs LPC IOCON gt PI01 9 amp 0x07 LPC IOCON gt PI01 9 0x01 16 bit timerfl MATO LPC IOCON gt PIO1 10 amp 0x07 LPC IOCON gt PIO1 10 0x02 16 bit timer 1 MAT1 LPC TMR16B1 gt TCR 0x02 reset timer Set prescaler so that timer counts in us steps SystemCoreClock LPC SYSCON gt SYSAHBCLKDIV 48000000 gt Timer clock is 48MHz LPC IMRIGBI PR SystemCoreClock LPC SYSCON 2SYSAHBCLRDIV 1000000 1 LPC TMRIOBI 2MEZ2 cycleLengthlnUs Setup match registers to generate a PWM signal with 0 duty constant low LPC JIMRIGOBI 2MRO LPC TMRIOBI 2MR2 LPC TMRI6BI gt MRI LPC TMRIOBI 2MR2 LPC TMRIGBI gt IR Oxff reset all interrupts not needed LPC TMRIOBI 2MOR Ii lt lt 7 3 reset timer on MR2 match LPC TMR16B1 gt PWMC 1 lt lt 0 1 1 Enable PWM mode for MATO and MAT1 KKK KKK KKK KK KK KK KK KK KK KK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name startPWM xx Descriptions Start 16 bit timer 1 Parameters None KK xx Returned value None KCKCKCKCKCKCkCKCkCK CK kok k k K Ck Ck k k k k k k k k k k k k k k k Ck k k k k k
46. k k k k k k k k k k k k k k k k k k k k k kk k k k k k kk k Ck k Ck k Ck ck void startPWM void LPC TMRIGBI TCR Ox0l Start timer 16Bl start generating PWM signal s KKK KK KKK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name stopPWM kxk Descriptions Stop 16 bit timer 1 c Parameters None kxk Returned value None KK Ck kCKCkCk AA kk KK KK KK kCkCkCk ck k kk KK KK KK kCkCk kck k kk A K kckck kk kCkCk Ck k kk kCk Ck ckck kk ck kckckck k ck kk kk kk void stopPWM void LPC TMR16B1 gt TCR 0x00 stop timer 16B1 stop generating PWM signal s KK 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 as Function name updatePWM Descriptions Update the PWM output setting c Parameters channel selects with PWM signals to update 0 or 1 Tm value set duty cycle a value between 0 and 100 Returned value None KK Ck kCKCkCk AA kk KCkCkCk ck kk KK K K ck k kk kCkCk kck kk KK K kck k KK A AK K kck kk kCkcCk kck kk kCk Ck KAZ ck kckckck k ck KK kk void updatePWM uint8 t channel uint8 t value Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide uint32 t matchValue matchValue LPC TMR16B1 gt MR2 100 value 100 if channel 0 LPC TMR16B1 gt MRO matchValue else if channel 1 LPC TMRI6BI gt MRI matchValue
47. k k k kk k k kk k kk k k k kk kk kk kk Function name xbeeTxStatus DescripLlions Transmit status callback Called as a result of a packet Dan being sent from the Xbee node parameters frameId ID of the frame that was sent WR Status status of the transmit request Returned value None KK KK KK KK KK KCkCk Ck ck k Ck KK K AAA A kCk K kck KK KK KAZ KK KK K ck k kk KK KK KK kCk AK kck kk ck KK KK ck k ck kk kk static void xbeeTxStatus uint8 t frameId xbeeTxStatus t status if status XBEE TX STAT OK printf RF d TX failed d r n frameId status KKK KK KKK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 115 Function name xbeeTxStatus KR Descriptions Received data callback Called when data has been received ud by the Xbee node parameters addrHi upper 32 bits of the 64 bit node address X addrLo lower 32 bits of the 64 bit node address WE rssi signal strength ERK buf buffer containing the data nes len number of received bytes Returned value None KCKCKCKCkCkCk CK Ck Ck Ck k k k k k Ck 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 Ck Ck k Ck k ck ck ck static void xbeeData uint22 t addfHi uint32z t sddrLo winte t rssi uint t Dut Wines Lem
48. k kk kCk Ck kck kk kCkCk Ck ck k kk kCkCkckck kk kCk Ck kck kk ck kc kckck k ck ck k kk int32 t lm75b readTemp void uinte t cmd temp 2 intiz 4 t D cmd LM75B REG TEMP I2CWrite LM 5B I2C ADDR amp cmd 1 I2CRead LM75B I2C ADDR amp temp 0 2 11 MSB bits used Celsius is calculated as Temp data 1 8 t temp O0 lt lt 8 temp 1 Return temperature times 100 e g in 0 01 degrees PSC x KKK KKK KK KK I Ke I KK I KK KK KK Description Write to config register of LM75B Params Config byte Returns None KK Ck kCKCkCk ck k kk kCkCk Ck ck kk KK Ck ck k kk kCk Ck kck kk KK Ck ck kk kCkCkCkckck kk kCkCk Ck k kk kCk Ck kck kk ck kc kckck k ck kk kk kk void lm 5b config int8 t config uints t oemd 2 cmd 0 LM75B REG CMD cmd 1 contig I2CWrite LM75B I2C ADDR amp cmd 0 2 KKK KK KKK KK KK KK KK KK K K AAA KK K AA KK KK K KAZ KK A AK KK KK KK KK KK KK KK KK KK KK KK KK kk Function name main Descriptions The main function Parameters None Returned value None kx Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide KK KK KK KK KK KCkCkCk ck kk KK K AAA Z kCk Ck kck KK KK KAZ kk A AK K ck k kk kCkcCkckck kk kCk Ck KAZ ck kc kckck k ck kk kk kk void main void initialize I2C as needed I2CInit I2CMASTER 0 enter forever loop while 1 read temperature an
49. mean sea level Units M 09 meters Units of geoids separation Checksum 65 lt CR gt lt LF gt 0 End of message termination k j Table 3 Position Fix Indicator Description O Fix not available 1 GPSfi 2 Differential GPS fix Figure 66 GPS Module Data Format The code below will read one message at a time from the GPS and then extract the time and latitude parts into the gpsData structure include LPC11xx h include uart h include gps h put typedef declaration below gpsData in gps h file Data structure for the GPS values typedef struct gpsData uince t satellitesUsed 20 uinte t urterimel20 3 uinte t elitrtudel20 uinte t bufLatitude 20 uint8 t bufLongitude 20 int positionFixed int northSouthIndicator int eastWestIndicator int latitude int longitude apsData static uint8 t END OF MESSAGE 0 static Uinte DIVIDER 7477 The parsed data static gpsData data Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 119 KOK 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 CK Ck CK k CK k k k k k kk k k k k k k kk kk kk k k k k k k Ck kk k k Ck Ck Ck Ck Ck k Function name hasPattern Descriptions Tests if pBuf starts with pPattern c parameters Buffer to search and pattern to match Returned value 1 if pBuf sta
50. must be able to inform a transmitter that it must wait for a while before transmitting more characters One commonly used software solution for this is called Xon Xoff flow control see http en wikipedia org wiki Software flow control for more information A commonly used hardware solution is called RTS CTS flow control see http en wikipedia org wiki Flow control 28data 29fHardware flow control 7 15 2 Lab 14b Direct printf to UART In exercise Lab 4a 4d semihosting was explored In this experiment the printf output will be sent to the UART communication channel Remember that the C runtime library had to be of the correct type for semihosting to work Have a look at Figure 21 and make sure the project settings select Redlib nohost as the C runtime library for this exercise There are hooks in Redlib for directing the printf output to any wanted communication channel the UART in this case The two simple functions below is all that is needed to direct the printf output to the UART and also to let scanf input come from the UART include stdio h include uart h use UART for printf int sys write int iFileHandle char pcBuffer int iLength UARTSendBuffer uint8 t pcBuffer iLength send data buffer to UART return iLength int sys readc void char c V RTReceive uint8 t 50 l TRUE return int c Place the two functions above in a file called retarget c Copyright 2013
51. needed libraries dtinclude stdio h int main void printf AnThis is a performance test n while 1 return 0 Now remove the 500ms delay in the loop and check how fast loop counter increments now It will not be very fast This shows the bottleneck of the Semihosting functionality It takes time to transfer the characters to the LPCXpresso IDE About how many characters can be transferred each second Note that this value will differ from PC to PC 1 5 3 Lab 4c Printing Events In this experiment you shall create a program that writes in the console every time a push button is pressed For simplicity use the breadboard setup in Lab 3 1 5 4 Lab 4d Reading from the Console In this experiment we will learn how the microcontroller can read input from the console in the LPCXpresso IDE The standard library function getchar is demonstrated The Semihosting implementation has limited functionality when it comes to reading from the console The calls are blocking meaning that the microcontroller will stay in the library function call until the user on the LPCXpresso IDE side has entered the characters and hit the enter key This is not strictly following the ANSI C definition of getchar where it should be a non blocking call i e return immediately even if no character was pressed by the user Test the code below Include needed libraries include lt stdio h gt int main void printf n
52. newValue 7 newValue newSample gt gt 3 Test to filter the samples and observe that they will be more smooth and stable Place the ADC read functions in file adc c Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 6 2 Lab 5b Event Threshold Another way to handle noise varying values from an analog signal is to introduce threshold handling In this exercise you shall implement a program that reports when the value of an analog signal has changed more than a set limit Create a program that prints the value of AINO in the console whenever the change in value s large than 2 of the full scale Tip 1 2 of 1024 steps equals 20 48 which can be rounded down to 20 Tip 2 Remember the last reported value and compare the new sample against this value If you compare against the previous samples value then it is theoretically possible to slowly slowly turn the trimming potentiometer without getting any change report event As an extra experiment create a program that reports changes as already implemented However if no changes are detected report the current value once every 5 seconds 1 6 3 Lab 5c Read Light Sensor In this experiment a light sensor will provide the analog input value instead of a trimming potentiometer The sensor R24 can be found on schematic page 4 as illustrated in Figure 25 below The more light the sensor is exposed to the lower the resistance becomes
53. press the Step Over or Step Into buttons Both step buttons will stop execution after the current statement The difference is that if the statement involves a function call Step Over will not single step through all statements in the function that is called Step Into will do just this The current experiment exemplified just perfect where the different is When hitting the delay function it is best to Step Over instead of into it Single stepping through all the loop iterations would take forever Add a loop counter in the forever loop Set a breakpoint in the forever loop in main so that execution halts every loop iteration Verify that it is possible to get the value of the loop variable by hovering over the variable Remove the breakpoint and test single stepping with both Step Over and Step Into Gm a2 n 4 E T 4 LU Figure 10 LPCXpresso IDE Step Over Into Buttons 7 2 4 Lab 1d Morse Code Create a function that flashes the LED according to the Morse code alphabet Check the Wiki for details http en wikipedia org wiki Morse code The function shall take an arbitrary string as input and send the string by flashing the LED Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 3 Read a Digital Input In this experiment you will learn how to control the I O pins of the LPC111x as inputs More specifically you will learn how to read a digital input that refle
54. register define SSPCR1 LBM define SSPCR1 SSE define SSPCR1 MS define SSPCR1 SOD Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide c c c c c c p dir dir di div dir di dir dir di di div di di dir di dir dir dir dis dir dir dis di di di di dir dir dis dir di dir dir di dis dir die di di dir di dir dir dir dir dir dir dies dir dir dies dio dir dios di di dir dir dir di dir dir di dis di dir dis dir dir di di dir dir di dir Function name SSPOInit Descriptions SSP port 0 initialization routine Note that GPIO control of SSEL signal is not done must be done separately parameters None Returned value None KK kk KCkCk ck k kk KK Ck k kk kCKCk Ck ck k kk kCkCk k ck k Ck KK Ck k k kk kCkCkckck kk KK Ck k kk Ck kCkcCkckck k ck k kc kckck KK KKK void SSPOInait void c kx kx kx x kx kx kx k kx uint8 t i dummy dummy LPC SYSCON gt PRESETCTRL 0x1 lt lt 0 Reset SBP block LPC SYSCON gt SYSAHBCLKCTRL 1 lt lt 11 Enable SSP block DPC SYSCON gt SSPOGLKDIV 0x02 Clock to SSPD block is divided by 2 which will equal 24MHz clock rate SSP I O config LPC IOCON gt PIO0 8 amp 0x07 LPC IOCON gt PIO0 8 0x01 DOPO MISO LPC IOCON PIOO 9 0x07 LPC IOCON PIOO 9 0x01 Z GOSPO MOSI 37 LPC LOCON 2
55. sent to the browser The static page is declared in webside h const unsigned char WebSide lt html gt r n lt head gt r n lt meta http equiv refresh content 1 gt r n lt title gt easyWEB dynamic Webside lt title gt r n lt head gt r n r n The dynamic content comes from the InsertDynamicValues function in easyweb c It locates and replaces the markers in the WebSide data ouggested changes e Change colors on the page e Make the colored bar decrease instead of increase e Add a second bar and let the two bars represent the values on the two trimming potentiometers e Read and present the current temperature 7 20 2 Lab 19b IwIP TCP IP Stack Web Server and FreeRTOS 1 Goto FreeRTOS IO and FreeRTOS CLI demo2 2 Download the projects LPC1769 FreeRTOS Plus Featured Demo 002 zip 3 Create a new workspace and import the contents of the downloaded zip file Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 131 4 Remove the call to vStartSPlInterfaceToSDCardTask from main in FreeRTOS Plus Demo 2 Source main c This is needed to prevent the demo from crashing as a result of a missing SD card 9 Modify the FreeRTOS Plus Demo 2 Source FreeRTOSConfig h to get unique addresses MAC address configuration define configMAC ADDRO 0x00 define configMAC ADDR1 0x12 define configMAC ADDR2 0x13 define configMAC ADDR3 0x10 define configMAC ADD
56. soldering all components to be pcb A better time to solder the components is after having completed all the initial basic experiments 7 4 Preparation One preparation is needed before it is possible to start with the experiments The LPCXpresso LPC111x board must be made experiment friendly a header with female and make connectors shall be soldered to the LPCXpresso board See picture below for details Note that there are two sets of two of similar 27 position headers in the component kit It is the headers with long pins that shall be soldered to the LPCXpresso board ri E An 2 Li e A i A t saver 4 t f gt u 4 1 i a SE A aa f 4 i EF Figure 3 LPCXpresso Board with Prototype Headers 7 2 Control a LED In this first experiment you will learn how to control the I O pins of the LPC111x microcontroller More specifically you will learn how to control a LED This first experiment will have a very detailed description since it is the first one and there are a lot of things to learn about how to create compile download and debug a program in the LPCXpresso IDE The level of details in the descriptions will gradually decrease in later experiments Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 2 1 Lab 1a Control LED We will start with controlling LED1 in the schematic which is
57. that it matters how the two ends are connected The two ends are called anode and cathode respectively Current flows from anode to cathode but blocks in the reverse direction Sometimes the anode is called the positive side and cathode the negative side The cathode is typically marked somehow on a LED shorter pin cut in plastic package etc Mounting a LED the wrong way has no catastrophic result The result is that the LED will not light since current through the LED will be blocked Failing to add the series resistor will have more sever effects though Depending on high strong how much current it can deliver the power supply is the current level through the LED can become high enough to destroy the LED Therefore be careful to always connect a series resistor with correct resistance value The LPC111x is a relatively low pin count processor with only 48 pins This is true for the package used on the LPCXpresso board There are other packages with different number of pins for this processor also The external pins on the chip package are not enough for connecting all internal peripheral units to unique pins Instead each I O pin has up to four alternative connections Read the LPC111x user s manual for more information You will have to read a lot in this document so you better get started immediately Have a look in chapter 7 LPC1100 LPC1100C LPC1100L series I O configuration in the LPC111x user s manual for a description of the how
58. that messages can be streamed A simple solution is to just store the bit pattern of the message A more advanced solution can store the messages as ASCII strings In the latter case a bit map defining all characters must also be defined For more advanced and fun use create a game for the LED matrix See for example these projects for some ideas http www evilmadscientist com 2008 meggy jr rgb http hackaday com 2010 02 19 update most interesting game in 64 pixels http interactive matter eu blog 2010 05 08 blinken buttons for beginners a smt beginners kit 0 7 Create a Game with Display Accelerometer or Gyro Create a game with a graphical display and an accelerometer or gyro Navigating a rolling ball in a labyrinth or recreate the classical snake game for example 8 8 Create General Menu System for a Display Create a general menu system for small character based LED for example a 2x20 character display Use the joystick buttons or the rotary switch as user input To get some ideas about which functions that are needed in a menu system have a look at older non smart phone cell phones These phones had small displays and few buttons There you can find many typical functions that are needed Character based LCDs typically have an 8 bit parallel interface Many of them also have a 4 bit interface mode to save interface pins Write code that works for both modes Alternatively us e a graphical display for more f
59. to U7 PCA9532 The signals can be manually bridged to any other free pin in the specific experiment Buzzer signal GPIO 7 BUZZ is not connected at all The signal can be manually bridged to any other free pin in the specific experiment RGB LED signal GPIO 30 PWM is only connected to U7 PCA9532 This is the signal controlling the green LED Note that signals GPIO 28 PWM and GPIO 29 PWM are both connected to the LPC1114FN28 and U7 This is because U7 has built in functionality for PWM control so there is a possibility to experiment with this specifically Quadrature encoder signals GPIO 38 QA and GPIO 39 QB are only connected to U7 PCA9532 The signals can be manually bridged to any other free pin in the specific experiment LPCXpresso Experiment Kit User s Guide Page 135 8 Projects This chapter contains a list of project ideas that build on the knowledge gained from the experiments in the previous chapters The projects involve a bigger programming effort than before and are real world in the sense that part of a real product application can very likely contain one of the project ideas The idea is to deepen your understanding of embedded systems and enhance your programming skills The projects are not described in detail like the experiments Instead the descriptions are quite short and are mainly supposed to give you some ideas and get you started Solve the details on your own that is what programming is all about anyway
60. works well with 3 3V supply Normally the problem is the blue LED which has high forward voltage drop Typically in the region of 3 5 4 5V The used RGB LED has V about 3 2V That is also a reason why the current levels are quite low The RGB LED component is also shown in Figure 29 From left to right the four pins in the picture are e Red LED cathode connected to R26 e All LEDs anode connected to 3 3V via SJ1 which is closed e Green LED cathode connected to R27 e Blue LED cathode connected to R28 7 8 1 Lab 7a Test RGB LED In this first experiment with an RGB LED the microcontroller will not be used We will only use the LPCXpresso board to get the 3 3V supply With three LEDs there are eight combinations Verify that you can create all seven colors besides black dark Insert the resistors in seven different combinations as shown in Figure 30 below Which colors do you get Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide U1 LPCXpresso board p i 90 o 09 0909 9 09 9 9 09 9 9 9 9 9 9 9 9 06 ee ee U i eee 0 0 9 ee 9 09 9 9 9 9 90 ee 0 9 09 09 09 09 09 9 09 9 9 9 9 9 9 9 e ee e 9 ee ee ee ee 9 09 09 ee 09 ee 09 09 9 9 9 ee ee ee ee ee ee ee ee ee eO 9 e ee 09 9 09 9 099 9 e 9 0 0 09 09 9 9 e ee e ee e e 9 90 090 9 9
61. 1 5 falling edge interrupt LPC GPIOI IC I lt lt 5 3 write with bit 5 set to clear interrupt from PIO1 5 j void main void initialize so that PIO1 5 generate an interrupt falling edge sensitive enable port 1 interrupt NVIC EnableIRQ EINT1 IRQn enter forever loop let interrupt handle processing while 1 here is a potential to go into a low power mode Note that due to contact bouncing inside the pushbutton sometimes several edges will be detected when the pushbutton is pressed In this experiment this effect is ignored but to in a real system contact bounce must be handled properly Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 13 2 Lab 12b Timer IRQ In this experiment an interrupt will be generated from a timer In Lab 1c Delay Function LED Flashing a simple for loop was used to create exact a delay function Recreate the experiment and flash with a LED Start with a fixed flash pattern say 5 Hz Keep the breadboard setup from the previous experiment see Figure 13 page 39 This experiment is also an extension to Lab 9a Create Exact Delay Function where a 32 bit timer was user to create exact delay functions The code below illustrated a suitable framework to start from Define Interrupt Service Routine for 32 bit timer 41 void TIMER32 1 IROHandler void name of function is predefined toggle LED om PIOU 2 and clear ti
62. 111x user s manual for a description of how the SSP block works SSP Synchronous Serial Port is NXP s peripheral block that is capable of SPI communication plus some other formats that will not be investigated in this experiment It is SSP 0 that we will work with with the following pinning e GPIO 1 MOSI PIO0 9 e GPIO 2 MISO PIOO 8 e GPIO 3 SCK PIO2 11 Further we will use GPIO signals for SSEL More specifically signals GPIO 4 LED SSEL PIOO 2 for the shift register experiments and GPIO 8 LED SSEL PIO2 0 for the e2prom experiment It is possible to use the SSP 0 SSEL signal directly which is available on PIOO 2 but in order to make the code general and supporting multiple SPI slaves we will control the SSEL signals with GPIO signals The code below initializes the SPI interface Study the code below and read the LPC111x user s manual to understand the different register initialization steps Especially note that in order to receive one byte one byte has to be transmitted i e one byte is clocked out one is clocked in at the same time define FIFOSIZE 8 SSP Status register define SSPSR TFE 1 lt lt 0 define SSPSR TNF L lt lt 1 define SSPSR RNE 1 2 tdefine SSPSR REF pL owe 3 define SSPSR BSY L lt lt 4 SSP CRO register define SSPCRO DSS 1 0 define SSPCRO FRF 1 4 define SSPCRO SPO 1 lt lt 6 define SSPCRO SPH 1 7 define SSPCRO SCR 1 8 SSP CRI
63. 16B1 CAPO PIC E 22 48 PIO 35 K FIOO 6 USB CONNECT SCK PO 3B COS 23 50 lO AR SWCLK PIOQ 10 SCK CT16B0 MAT2 24 51 EO 37 PIO3 0 PIC LED 25 52 PO 3B8 QA PIOS3 1 GPIO 22 LED 28 53 P O 30 08 PIO3 2 P 23 ED 27 54 MT Figure 16 Signal GPIO 7 BUZZ on Schematic Page 2 Add the buzzer to the breadboard Some rearrangement might be needed Note that the buzzer in the component kit might look different from the one in the picture below Also note that both the PNP transistor and the buzzer are polarized components so it is important to turn them correct Also note that the series resistor on the PNP base pin is 1 5 kohm a different value than we have used so far U1 LPCXpresso board 4444 EKEK Pin 8 SSEL Pin 28 3941 4 PIOO 2 3 3V d m 225 i Me 431 4 pl i 1 Made with J Fritzing org Figure 17 Breadboard Connections for SW2 SW3 Buzzer and LED Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Modify the existing code in this experiment so that the LED and the buzzer are controlled the same way LED on buzzer on As a fun extra experiment repeat the Morse code experiment in Lab 1d with the buzzer as Morse code output instead of the LED Note that the buzzer will turn on during program download on LPCXpresso boards This is because pin PIOO 7 is also connected to a LED on the LPCXpresso board This will drive the signal low and hence turn on the buzzer The so
64. 1it t 0 7 1 0 int i 0 for i 0 i lt 4 i ls i TIS LED SET Ox0001 States mode lt lt 0 LS LED SET 0x0002 states mode lt lt 2 IS LED SET 0x0004 states mode lt lt 4 IS LED SET 0x0008 states mode lt lt 6 states gt gt 4 static void setLeds void uints t Dufla uxntg t Isl j uintl6 t states l 0 0 0 0 ledStateShadow LEDs in On Off state setLsStates states ls LS MODE ON set the LEDs that should blink setLsStates blink0Shadow ls LS MODE BLINKO setLsStates blinklShadow ls LS MODE BLINK1 buf 0 PCA9532 L90 PCA9532 AUTO INC buf 1 ls 0 buf 2 ls 1 buf 3 ls 2 buf 4 1s 3 I2CWrite PCA9532 I2C ADDR buf 5 kk Ck CK Ck Ck Ck k Ck CK k k k Ck Ck k k k k Kk k k Ck Ck k k k k k Kk k k k k k Ck Ck k k Ck Ck k Ck Ck k Ck Ck k Public Functions KK Ck kCkCkCk ck k kk kCk Ck k ck kk KK Ck ck k kk kCk Ck kck kk KK ck ck kk kCkCkc k ck k kk kCkc Ck ckck kk kCk kc kckck kk kc kckck k ck kk kk kk A a a aa a aa a aa ao a o CKCKCKORCKOKCKORCK KCKOK CK KCK KO K KCKOK CK KO KO KO a KO KO a a a KCKOK a a CK OK CK K CK CK CK K CK K Ck K Ck KO kk Description gt Set LED states on or off Params ui in ledOnMask The LEDs that should be turned on This mask has priority over ledOffMask s in ledoffMask The LEDs that should be turned off KK Ck kCKCkCk
65. 2 8 28 HVQFN33 LPC1114FBD48 301 LPC1100 32kB 8kB no 1 1 2 8 42 LOFP48 LPC1114FBD48 303 LPC1100XL 32kB 8kB yes 1 1 2 8 42 LOFP48 LPC1114FBD48 323 LPC1100XL 48kB 8kB yes 1 1 2 8 42 LOFP48 LPC1114FBD48 333 LPC1100XL 56kB 8kB yes 1 2 8 42 LQFP48 LPC1115 LPC1115FBD48 303 LPC1100XL 64kB 8kB yes 1 1 2 8 42 LOFP48 J Figure 74 LPC111x Variant Comparison There are some differences when working with the LPC1114FN28 102 chip Memory wise the difference is small The chip has half the amount of SRAM 4kByte when compared to the LPC1115 1114 on an LPCXpresso board The big difference is less available pins When working on the breadboard the solution is simply to switch which pins to use since all are not used simultaneous so no problem there When having soldered all components to the PCB the setup is more fixed Most of the pins that are lacking on the DIP28 package have been routed to U7 PCA9532 the I2C GPIO expander That way it is possible to access these signals pins via 12C instead The experiments affected with pcb mounted components are the following e 8LEDs signals GPIO 9 LED SSEL GPIO 21 LED GPIO 22 LED and GPIO 23 LED are not connected to the LPC1114FN28 GPIO 9 LED SSEL is however connected to U7 PCA9532 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 134 Copyright 2013 Embedded Artists AB 9 push buttons signals GPIO 17 KEY GPIO 18 KEY and GPIO 35 KEY are only connected
66. 3 R5 R55 R56 R57 R58 http en wikipedia org wiki Resistor Piezo buzzer 1 pcs SP1 http en wikipedia org wiki Buzzer Pushbuttons 5 pcs SW1 SW5 Pushbuttons for breadboard 2 pcs This is a surface mounted component and can only be soldered to the pcb i e not used on the bread board This is not a polarized component Panasonic ERJ 6ENF2001V Digikey P2 00KCCT ND This component is polarized One pin is longer than the other The longer pin is the positive side The top label also indicates this side with a small plus sign CUI Inc CEP 2242 Digikey 102 1115 ND This component and can only be soldered to the pcb i e not used on the bread board The reason for this is that the pins are too short to get reliable connection on the bread board There are two other special switches in the component kit that are suitable for bread board usage Omron B3F 1000 Digikey SW400 ND Mouser 653 B3F 1000 These switches are for breadboard usage Note that the pins must be cut to suitable length before mounted in the breadboard Panasonic EVQ 11L05R Digikey P8079SCT ND Mouser 667 EVQ 11L05R LPCXpresso Experiment Kit User s Guide Rotary encoder 1 pcs This component and can SW6 only be soldered to the pcb i e not used on the bread board Below is without center switch Panasonic EVE GA1F1724B Digikey P10859 ND Mouser 667 EVE GA1F1724B Voltage regulator This c
67. 5 LPC111x LPC11Cxx I2C bus controller in the LPC111x user s manual for a description of the how the 2C block works It is more complicated interface than for the timers and SSP peripherals The basic principle is to send commands to the I peripheral block These commands are carried out in the external 1 C bus and a status is presented as result Based on the status the lC driver gives the next command It is not recommended to start from scratch and create an 12C driver Instead the driver supplied from NXP will be used see files 12c c i2c h Let s investigate the application program interface API for this driver The file i 2c h contains amongst other declarations the following function declarations e l2Clnit this function must be called before the 12C driver is used and any I2C communication can take place The function initializes the pins PIOO 4 PIOO 5 to be I2C pins and other necessary initialization The function has two parameters The first parameter tells if the 12C interface shall be a master or slave interface In this case it is a master interface and no further parameter is needed In case it is a slave interface the second parameter is the slave address of this interface Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide e l2CRead this function perform a read operation The function has three parameters The first is the slave address to communicate with The second is
68. 7 6 Read an Analog Input 53 7 6 1 Lab 5a Read Trimming Potentiometer o3 7 6 2 Lab 5b Event Threshold 26 7 6 3 Lab 5c Read Light Sensor 56 7 6 4 Lab 5d ADC Noise Test 07 7 7 Pulse Width Modulation 58 7 1 Lab 6a PWM Control of a LED 58 7 1 2 Lab 6b PWM Control of a LED cont 1 59 7 1 3 Lab 6c PWM Control of a LED cont 2 59 7 7 4 Lab 6d PWM Control of two LEDs 60 7 8 Control an RGB LED 61 7 8 1 Lab 7a Test RGB LED 61 7 8 2 Lab 7b Control RGB LED 62 7 9 Control a 7 segment Display 63 7 9 1 Lab 8a Test 7 segment Display 64 7 9 2 Lab 8b Control 7 segment Display 64 7 9 3 Lab 8c Control 7 segment Display cont 66 7 9 4 Lab 8d Control Dual Digit 7 segment Display 66 7 9 5 Lab 8e Control 7 segment Display via Shift Register 68 7 10 Work with a Timer T1 7 10 1 Lab 9a Create Exact Delay Function 71 7 11 PWM via a Timer 72 7 11 14 Lab 10a Control RGB LED 74 7 11 2 Lab 10b Buzzer and Melodies 74 7 11 3 Lab 10c Control a Servo Motor 75 7 12 Work with a Serial Bus SPI 78 7 12 1 Lab 11a Access Shift Register 81 7 12 2 Lab 11b Control 7 segment Display 82 7 12 3 Lab 11c Access SPI E2PROM 82 7 13 Work with Interrupts 87 7 13 1 Lab 12a Generate IRQ via GPIO 89 7 13 2 Lab 12b Timer IRQ 90 7 13 3 Lab 12c Timer IRQ with Callback 91 7 13 4 Lab 12d Nested Interrupts 92 7 13 5 Lab 12e Control Dual Digit 7 segment Display 93 7 14 Work with a Serial Bus I2C 94 7 14 1 Lab 13a Solder Surface Mounted Components 95 7 14 2 Lab 13b
69. 7 segment Display via Shift Register on page 68 again In that experiment the SPI bus was simulated in software Now the SSP peripheral block shall be used for the SPI communication Refresh your memory of the schematic by looking at Figure 41 again Rebuild the breadboard circuit in Figure 42 which you should have done already in Lab 11a The MISO signal is no longer need since the content of the shift register is of no interest Use GPIO 4 LED SSEL PIO0_2 as SSEL signal and do not forget to initialize this GPIO signal as an output and to also control the signal levels during SPI communication just like in the previous Lab 7 12 3 Lab 11c Access SPI E2PROM In this experiment we will interface the 25LC080 chip which is a 1024 byte serial E2PROM that directly interface the SPI bus In this experiment signal GPIO_8 LED SSEL PIO2 0 is used as SSEL signal Have a look at the datasheet for the 25L C080 chip for example here http ww1 microchip com downloads en DeviceDoc 22151b pdf or search Microchip s website if the link does not work The 25LC080 chip has a set of instructions All SPI transmissions begin with the instruction to execute The needed parameters for the instruction are then transmitted The set of instructions are shown in the picture below the picture comes from the 25LC080 datasheet Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide TABLE 2 1 INSTRUCTION SET OPP 0000 0011 F
70. 75Ch LOC 0x01 Needed to conf PIO2 11 as SCIK LPC IOCON PIO2 11 8 0x07 LPC IOCON PIO2 11 0x01 SSPO SCLK SSPCPSR clock prescale register master mode minimum divisor is 0x02 LPG SSPD OCPSB 032 Set DSS data to 8 bit Frame format SPI mode 40 CPOL 0 CPHA 0 and SCR is 7 which equals 24MHz CPRS SCR 1 1500 kHz SCLK frequency LPC SSPO gt CRO 0x0707 clear the RxFIFO tor i 0 i lt FIFOSIZE i dummy LPC SSPO gt DR Master mode LPC SSP0 gt CR1 SSPCR1 SSE CkCk Ck Ck k k k k k k k k A k k k A k k k k k k 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 k 4 k k k k 4 2 ck k kk X Function name SSPOSend Descriptions Send a block of data to the SSP port the first parameter is the buffer pointer the 2nd parameter is the block length parameters buffer pointer and the block length Returned value None XOEOKCKOKGEOEOROKORORORCKCKOKCKOR a o KOR KCKOKORCKOR KOK o o o o o a a a CK a o RO KO RKCK a CKCKCKOK CK o ho o o o ho a CK o ho a ha k KKK KE A void SSP Sendi uints t pBur uint32 t length uint32 L5 uj uint8 t dummy dummy for i 0 i lt length i Move on only if NOT busy and TX FIFO not full while t LPC SSP SR 4 SSPSR TNE SSPSR BSf I9 SSPSR TNE LPC SSPUSSDRE pBur pBuf while LPC SSP0 gt SR amp SSPSR BSY SSPSR RNE SSPSR RNE Whenever a byte is writ
71. Adjust the program code in Lab 5a to read from AIN2 instead of AINO and check what converted values to expect in different light conditions What is the range of values between absolute dark and full sunlight Light Sensor 3V3 R24 PHOTOCELLPTH R25 330R GND Figure 25 Light Sensor on Schematic Page 4 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide U1 LPCXpresso board ee ooo Pin ae eee GPIO_13 AIN2 21 PIO1 1 AD2 4994 e e e e e 9 9 o o e e 0 ee ee o e e 9 e 9 o e 9 9 o o e e e e Made with 9 Fritzing org Figure 26 Breadboard Connections for Light Sensor R24 7 6 4 Lab 5d ADC Noise Test As seen and experimenting with in Lab 5a and 5b here is noise in converted analog values In this experiment we shall investigate the ADC noise in more detail We shall gather statistical information about the noise distribution Create an application that gathers 1 000 000 samples from AINO and sort these values according to frequency in occurrence One solution is to create an array of 1023 32 bit variables and let each of these variables be a counter representing the number of times that particular value has been observed This solution would require 4kByte of RAM which is not a problem It the resolution would have been higher for example 12 bits then the memory consumption might be too high An alternative solution would be to have a smaller array T
72. Bee compatible socket for ZigBee and WiFi modules Note that RF module is not included e PC1114 in DIL28 package with 12MHz crystal and SWD connector only for pcb mounting e Local 3 3V voltage regulator e Miscellaneous resistors capacitors transistors and connectors e Breadboard with cables e Naked PCB Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 2 2 ESD Precaution Please note that the LPCXpresso Experiment Kit come without any case box and all components are exposed for finger touches and therefore extra attention must be paid to ESD electrostatic discharge precaution Always work with the LPCXpresso Experiment Kit in a place with proper ESD protection T A Avoiding electrostatic discharge is all about having the same electric potential and to avoid building up charges between different areas where you work This is easily accomplished by having a conductive surface on your workbench and connecting yourself with this surface via a wrist wrap Note that Embedded Artists does not replace boards that have been damaged by ESD 2 3 General Handling Care Handle the LPCXpresso Experiment Kit and all included components with care The board is not mounted in a protective case box and is not designed for rough physical handling Connectors and components can wear out after excessive use The LPCXpresso Experiment Kit is designed for prototyping use and not for integration
73. CFG ACT AS COORDINATOR 1 Configure the XBee module to act as a coordinator 0 Configure the XBee module to act as an end device 7 define CFG ACT AS COORDINATOR 0 RF message IDs add your own here but make sure that the coordinator and the nodes have the same numbering y define RFPT SET LED 1 Forward declarations static void xbeeUp uint8 t up Static void xbeeNode uint22 t addrHi uints2 t addrLo winto t ssi static void xbeeTxStatusi ulnt9 t frameld xbeeTxStatus t error static void xbeeData uint3z Lt adarHi uint5z2 t addrLo winte t Ts81 ince E bur unte t len static xbee callb t callbacks 1 xbeeUp xbeeNode xbeeTxStatus xbeeData k static uint9 t devIsRkead 0 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 114 volatile uint52 t ms ticks 0 KKK KKK KKK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK kk Function name SysTick Handler KRK Descriptions Interrupt handler Updates the ms ticks variable to hold qum the number of milliseconds since start This will be gt reasonably accurate and is used by the Xbee driver to handle timeouts parameters None Returned value The time in milliseconds KRK KK Ck kCKCkCk AKA kk KK KK KK KK Ck AAA A kCk Ck kck KK KK K K ck k KK KK kckck kk kCkcCk ck k KK KK Ck KAZ kc kckck k ck kk kk kk void SysTick Handler void
74. Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 13 3 Lab 12c Timer IRQ with Callback In this experiment the timer interrupt will call a registered function called a callback function It is a commonly used program structure that can be very powerful and flexible Create a program that uses a timer callback to control flashing of a LED Keep the breadboard setup from the previous experiments see Figure 13 page 39 otudy the code framework below It outlines how a timer callback functionality can be implemented e A function pointer to the callback function is stored e A timer is setup to generate an interrupt after a specified time After triggering the interrupt the timer stops e When the timer interrupts occurs the callback function is called Declare function pointer to a void void function for the callback function volatile void pCB void Define Interrupt Service Routine for 32 bit timer 1 void TIMER32 1 IROHandler void name of function is predefined check if function pointer is value not equal to NULL if pCB NULL call function pointer call callback function PCB also valid syntax pCB invalidate function pointer pCB NULL stop timer clear timer interrupt KKK KKK KKK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name registerCbAndDelay
75. D state on step to the left Turning the switch one step to the right shall advance the LED state on step to the right The rotary switch used can also be called a quadrature rotary encoder The encoder is named SW6 in the schematic and can be found on schematic page 5 see Figure 19 below Rotary switch Quadrature signals Figure 19 Quadrature Encoder SW6 on Schematic page 5 The encoder outputs two signals A and B according to Figure 20 below The two signals vary over four states A B 0 0 1 0 1 1 0 1 Depending on rotation direction the four states are traversed from left to right or right to left Clockwise 3 Counterclockwise a LJ EF LI L One notch 1 2 Figure 20 Quadrature Encoder Output Signals A rotation step can be detected by sampling the two inputs and determining what the new state is If this new state is same as the current one no rotation has occurred However if there is a difference then a rotation has been detected If for example the current state is A B 1 0 and the new state is 1 1 the rotation is in the right direction If the new state is 0 0 the direction is instead to the left Another method to detect rotations is to detect negative edges on signal A The level on signal B high or low at this point in time determines the direction Position 2 in Figure 20 above represents the counterclockwise direction B is low and 1 represents th
76. F module interface is found on schematic page 7 also replicated in the picture below All components in Figure 63 must be soldered J2 the LPCXpresso board connector on schematic page 2 must also be soldered Digi XBee R RF module SEL LINK J12 2 3 EXI C12 ew GND 15 5 14 A 3 al 1 2 2l dj Figure 63 RF Module Interface on Schematic Page 7 Many RF modules come in the XBee physical form factor An UART interface is connected for communication with the RF module All 20 pins are however available via connectors J13 J14 in case some other pins must be connected for more advanced experiments where more functionality in the modules is utilized Figure 64 illustrates how an XBee module is mounted in J15 Note that J12 should normally have a shorting jumper in position 1 2 the right position as illustrated in the picture below T 2 Led dif faxStr wn gt XBee 2 FOC COLA K K 47344428 r wr OE EAA 1 2 M Ls ANM Of Ss Figure 64 XBee Module Mounted in J15 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 113 A shorting jumper in position 1 2 of J12 means that the RF module is powered from the 3 3V supply from the LPCXpresso or mbed board This supply is somewhat current limited about 100 150mA but Will be sufficient for most RF modules However some modules have higher current requirements and
77. Guide Page 151 Project Explorer 3 z Peripherals fi Registers MEL gt Lab Test Semihosting gt Lib_CMSISv1p30_LPC11x gt S Lib EaBaseBoard gt e Lib FatFs SD gt e Lib MCU da ye np 1 Right click on project to gt ES uart2 a copy and select Copy Paste WM Delete Delete Source Mnwe Figure 91 Copy Existing Project Project Explorer 33 Peripherals fii Registers H M b US Lab Test Semihosting gt us Lib CMSISv1p30 LPC11xx gt ES Lib EaBaseBoard gt E Lib FatFs SD gt tS Lib MCU b eS LS20031 gps example gt ES uart2 b zs xbee oled 2 Right click on empty space in Project Explorer Go Into and select Paste Open in New Window Figure 92 Paste Project Copy Project 3 Give a name for the new project Use default location _ Note no spaces Project name Bep per NL Location CAUsersvAnders Documents PCXpresso 5 0 11 Browse in project name That can give problems later on when compiling x and linking Figure 93 Copy Project and Rename 9 5 Common Problems In this section a number of common problems are listed Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 152 9 5 1 Error message Failed on chip setup ET UU RR Target reported errors Reason 03 Failed on chip
78. Host port on a PC laptop USB hub e When using the LPC1114 in DIL28 package an external 5V DC supply is needed Feed the 5V via J1 or J17 as described above and mount R2 in order to let U1 be the 3 3V regulator in use Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide e When using an mbed module this module can generate the needed 3 3V supply supply comes from its own USB connector R2 should not be mounted in this case The mbed module can supply much more current on the 3 3V supply than an LPCXpresso board can n case the mbed module is not powered via its USB connector it is possible to power it with an external 5V DC supply via connector J1 or J17 as described above Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 6 Soldering This chapter describes how to solder the components to the naked pcb Note that when a component has been soldered it can no longer be used for breadboard experiment This chapter will not present a full beginner tutorial on soldering but rather point out how to get started There are many good soldering tutorials on the Internet which can easily be found via a Google search Sparkfun has a good starting guide http www sparkfun com tutorials 354 They also have a series of guides for soldering SMD Surface Mounted Device components http www sparkfun com tutorials 36 The following material is requires before
79. IRValue IIR THRE THRE transmit holding register empty check if all data is transmitted if txHead txTail uinco2 t bytesTosend if statusReg amp 0xc0 bytesToSend 16 FIFO enabled else bytesToSend 1 no FIFO enabled do Z ealeulate buffer index tmpTail txTail 1 amp TX BUFFER MASK txTail tmpTail LPC UART gt THR txBu f tmpTail while txHead txTail 44 bytesToSend all data has been transmitted else txRunning FALSE LPC UART gt IER amp IER THRE disable TX IRO KKK KKK KK KK KK KK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name UARTSendChar kxk Descriptions Send a byte char of data to the UART 0 port parameters byte to send Returned value None kxk KK Ck A K AKA kk KCkCkCk ck kk KK Ck ck k k kk AK K kck kk KK ck k k kk A K Ck kck kk kCkCk ck k kk kCk AK kck kk KK KK KK ck kk kk void UARTSendChar uint8 t toSend Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide uint32 t tmpHead calculate head index tmpHead txHead 1 amp IX BUFFER MASK wait for free space in buffer while tmpHead txTail disable TX IRQ LPC UART gt IER amp SIBER THRE if txRunning TRUE txBuf tmpHead toSend txHead tmpHead else txRunning TRUE Extra check should not be needed THRE status
80. Include needed libraries include lt stdio h gt Define constants define AINO 0 Add ADC functions for initializing and reading values int32 t main void printf nThis program reads AINO repeatedly n Initialize ADC peripheral and pin mixing ADCInit 4500000 4 5MHz ADC clock while 1 uintl6 t analogValue analogValue getADC AINO printf nAINO d analogValue Delay 250ms j return 0 You will notice some noise in the converted values It is not always a stable value This is quite normal to expect in a not noise optimized setup that we have with the breadboard and the LPCXpresso board Besides proper hardware design a method to handle noise is to low pass filter the converted values Below are two examples of how this can be done It is a simple first order filter The closer to 1 ALFA is the more filter effect is applied the lower the cut off frequency will be in the filter Floating point calculations are not to recommend in smaller embedded systems The execution time will be long for these calculations but the biggest problem is typically that the code size will increase considerable when the C runtime floating point libraries are linked to the program An integer solution is to recommend instead One example where ALFA is 0 875 is outlined below Floating point calculations define ALFA 0 95 newValue ALFA newValue 1 ALFA newSample OR Integer calculations
81. O 8 PORT SSEL GPIO 8 PIN SSEL LOW output write command and address buf 0 INST WRITE buf 1 address gt gt 8 amp Oxff buf 2 address amp Oxff SSPOSend amp buf 0 3 send bytes to write E2PROM SSPOSend pBuf length pull SSEL CS high GPIOSetValue SSEL GPIO 8 PORT SSEL GPIO 8 PIN SSEL HIGH Add functionality in the write operation to check so that no page boundaries are crossed Even better add functionality to break up a large write block to smaller correctly addressed page writes Do not forget to add functionality in the write function to set the write enable latch before every write operation Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Create a program that writes a string and reads it back to verify that the write operation was successful Also let the program print the content of the memory locations directly after power up By doing so it is also possible to verify that the SPI E2PROM is a non volatile memory that keeps the content over a power cycle Build the breadboard setup below and verify that it is possible to write and read in the memory region on the 25LC080 chip Note that the 330 ohm series resistor on the MISO pin pin 2 of the 25L C080 is not strictly needed It is a safety precaution in case a faulty or wrong program executes on the LPC111x making the MISO pin an output in the LPC111x If this happens then the signal will have two drivers T
82. PIN 9 continue with the rest of the pins 1 17 1 Lab 16a 128x128 OLED Graphical Display In this exercise the serial expansion connector will be used to interface a 1 5 inch RGB OLED with a resolution of 128x128 pixels see product page http www embeddedartists com products displays 15 rgb oled php The display can be bought directly from Embedded Artists Digikey EA LCD 008 or Mouser 924 EA LCD 008 The display contains a built in controller SSD1351 from Solomon Systech that is interfaced via a 4 pin SPI channel or an 8 bit parallel interface but in this exercise the SPI interface will be used Pin 3 4 6 and 11 are used for the SPI interface Pin 11 is the fourth signal that is used to differentiate between command and pixel data information transfers Further pin 12 is used for reset of the display The display module has five DIP switches All switches except for pos 3 shall be in ON position See the display module s schematics for details Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 124 Figure 68 illustrates how the display is connected to the LPCXpresso Experiment board via a 14 pos cable lt Ba TT rms M Za HU I v poyi ASEITA jm Figure 68 1 5 inch RGB OLED Connected via Serial Expansion Connector In the preparation a number of defines SEC14 PIN were defined Each module that is connected via the serial expansion connector can set
83. PUTO 0x00 define PCA9532 INPUT1 0x01 define PCA9532 PSCO 0x02 define PCA9532 PWMO 0x03 tdefin PCA9532 PSCI 0x04 define PCA9532 PWM1 0x05 define PCA9532 LSO 0x06 define PCA9532 LSI 0x07 define PCA9532 LS2 0x08 define PCA9532 LS3 0x09 define PCA9532 AUTO INC 0x10 f ROKCKCKCKCKCKCKCKKCkCkCKCKCKCK kCkCkCKCKCKCK Ck kCkCKCKCKCKCKkCkCKCKCKCKCK KC KK KK KK KK KK KK KK KK KK KK KK kA KK kk Defines and typedefs KK KK KK K AA kk KK KK KK kCkCk KK KK kCk Ck kck KK KK KKK KK KK KK KK KK k k KK KK KK KK KK KK KK KKK Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide define LS MODE ON 0x01 define LS MODE BLINKO 0x02 define LS MODE BLINK1 0x03 f ROROROKORCROKCKOKCKOKCKORCKCKCKCKCKCKCKCKCKORCKCKCKORCKOKCKORCK KCKORCK ROCK ROCK KOCKORCK RARER ROCK ROCK a a a a a ha a CKOK CK CK ka a CK CK CK K CK KEKE Local variables KK Ck kCkCkCk ck k kk KCkCk k ck kk KK Ck ck k kk KK K kck kk kCk Ck kck kk Z KK K AAA kCkcCkckck kk kCk Ck kck kk ck kc kckck k ck KK kk static uintlo t blink0Shadow 0 static uintl6 t blinklShadow 0 static uintl16 t ledStateShadow 0 f ROKCKCKCKCKCKCKCK AAA KK K K AAA KKK K AAA KK K K AXA A KK KK KK KK K K AXA KK AK K AAA KK Kk KC KK KK KKK KK k kk Local Functions KCKCKCKCKCkCk Ck CK CK CK Ck k k Ck k k k k k k k k k k k k Ck k k k k k k k k k k static v id SeLtbeortates usntlo states uiBLs cy IS UWint8 t mode rderine IS LED SET DIC x x amp D
84. Periphera 7 9 Welcome 2 g E P file C nxp LPCXpresso 4 0 5 123 Ipcxpresso pages registered htm gt gt e gt S Accel systick irg wakeup gt TES CMSISv2p00 LPC11Ux ti 1 Click to select main project gt presso m powered by code red i 2 Browse and edit project files gt aj Includes gt amp src gt Debug E DemoApp Debug launch E DemoApp Release launch gt FlashApp gt E LCD ADC temp wdt wakeup E apr LPCXpresso Getting Source code gt iS lib OryxDev LPCXpresso Resources f A Check the LPCXpresso Ed itor Wi ndow eases more example projects and announcements gt RTC irg wakeup gt S Semihosting ADC temperature sleep ctivated now fully activated and can be used for production LPCXpresso can be used to ing up to 128KB of code into an LPC target Getting Started Please read the getting started guide for step by step instructions to build your first LPCXpresso project X Visit www nxp com LPCXpresso Forum W Quick 23 N Bi RedC Varia 96 Break ELI l in The LPCXpresso Forum community is exclusively built for LPCXpresso users and is an invaluable resource for getting help and advice on use of the LPCXpresso tools and boards So get connected and join the LPCXpresso community C Start here j New project 9 Import project s o1 Bil el Build DemoApp Debug
85. R4 0x15 define configMAC ADDR5 0x12 IP address configuration define configIP ADDRO 192 define configIP ADDR1 168 define configIP ADDR2 5 define configIP ADDR3 201 Run the ping test as described in insert ref here and then point the web browser to http lt your selected ip number The page will look like this Task statistics Page will refresh every 2 seconds Task State Priority Stack F eee RKK KKK K K oe tcpip R 2 222 0 IDLE R 0 70 1 Tmr Svc B 3 58 2 CmdInt S 3 280 3 Refresh count 4 Figure 72 Task Statistics Screenshot The FreeRTOS allows multiple threads to run in seemingly parallel The program has both a web server and a telnet server The telnet server can be accessed by e g Putty on port 22 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 132 192 168 5 201 PuTTY Test the three available commands help task stats and run time stats Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 133 7 21 Differences between LPCXpresso LPC111x and LPC1114 in DIL 28 The experiments are based on the LPCXpresso LPC111x boards that can be based on the LPC1114 or the LPC1115 For all practical purposes these two chips are interchangeable The LPC1115 has the double amount of FLASH 64kByte instead of 32kByte for the LPC1114 At the time of writing the LPCXpresso LPC1114 board has been discontinued in favor for t
86. This is a test of getchar n while 1 inta t rxchar rxChar getchar printf c xGhar return 0 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Run the program and enter five characters and then hit enter What happens The reason for this is that there is a queue on the LPCXpresso side Each time getchar is called om the microcontroller side a character is removed from the queue Also note that text written by the user is printed in green color and text from the target system i e the LPC111x is printed in black color The blocking implementation of the read functions limits the usefulness A final application would never use this functionality It would simply not be practical to always have the LPCXpresso IDE connected to the system It can however be a very useful functionality when debugging The application can for example ask the user at startup if special settings shall be used The user can then quickly test several settings without having to recompile the application As an extra experiment create a program that reads input from the console and converts it to a number Check that only digits are entered and that the final number is within the range of a 32 bit number Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 6 Read an Analog Input In this experiment you will learn how to convert an analog sign
87. This pair of connectors has shorter pins The other pair has longer pins This pair of connectors shall be soldered to the pcb as a socket to the LPCXpresso board sullins PPTC271LFBN RC Digikey S7025 ND This component and can only be soldered to the pcb i e not used on the bread board Pin 1 is in the top upper left corner in the picture There is no distributor LPCXpresso Experiment Kit User s Guide equivalent for this component RJ45 Ethernet connector J4 Pin list 1x3 J5 J6 J8 J12 Pin list 2x3 J7 and J11 combined USB B connector J9 USB A connector J10 Copyright 2013 Embedded Artists AB This component and can only be soldered to the pcb i e not used on the bread board Stewart SI 50170 F Digikey 380 1103 ND Sullins PECO3SAAN Digikey S1012E 03 ND This component and can only be soldered to the pcb i e not used on the bread board Sullins PECO3DAAN Digikey S2012E 03 ND This component and can only be soldered to the pcb i e not used on the bread board TE Connectivity 292304 2 Digikey A98573 ND Mouser 571 292304 2 This component and can only be soldered to the pcb i e not used on the bread board TE Connectivity 292336 1 Digikey 292336 1 ND Mouser 571 292336 1 LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB socket connector for wireless module J15 Shrouded pin list 2x7 J16 USB
88. a buffer pointer to where the read data is copied The third parameter is the number of bytes to read e l2CWrite this function perform a write operation The function has three parameters The first is the slave address to communicate with The second is a buffer pointer from where to get the data to transfer to the slave The third parameter is the number of bytes to write transfer 1 14 1 Lab 13a Solder Surface Mounted Components In this Lab the surface mounted components shall be soldered to the PCB as a preparation for the following 12C related experiments Besides the surface mounted components a few connectors are also needed to be soldered for powering and connection to the LPCXpresso LPC111x board The following components shall be soldered see chapter 4 for pictures of all different components e J1 2 1mm power jack This is for allowing an external 5V DC supply to power the board e J2 dual 1x27 pos headers for connection to the LPCXpresso LPC1 11x board e J17 mini B USB connector on bottom side as alternative power source e Components on schematic page 6 o Temperature sensor U6 LM75 C10 100nF R57 R58 2K o 12C GPIO expander U7 PCA9532 C11 100nF R43 R56 2K LED11 LED18 Figure 56 illustrates where on the PCB the components shall be soldered Read chapter 6 for information about soldering In general there are many good tutorials on the Internet on how to solder through hole components as well as surface mou
89. ake one sample to determine in which range the vales seems to be Then set a range of for example 32 around this value Also have two special counters that represent values under or above the edge values This way it would be simple to check if the range accidentally is bad The result shall also be printed in the console in a user friendly way so that the result is easy to understand for the user What can the possible source of noise be Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 7 Pulse Width Modulation In this experiment you will learn how to generate a pulse width modulated PWM signal The PWM signals will be generated purely in software A more hardware oriented implementation with the help of timers will be investigated in later experiments Figure 27 below outline the breadboard design that allows performing all experiments around PWM signals Start with building this All resistors are 330 ohm U1 LPCXpresso board w E 900 00 00 9909 9 9 9 9 9 9 e e Made with 3 Fritzing org Figure 27 Breadboard Connections for PWM Experiments 7 1 1 Lab 6a PWM Control of a LED In this experiment you shall investigate how to generate a signal with a given duty cycle and how the LED intensity varies with duty cycle Figure 28 illustrates the PWM signal structure The high time defines the duty cycle It this signals directly drives a LED the LED will be fully on when
90. al TRUE Variable VIEW 188 break Hover cursor over variable and a 151 H i i 182 if timeout gt I2C MAX TIMEOUT variable window will pop up E i showing the current value 184 retVal FALSE break aal Expression Type timeout uint32 t timeout Details 68058819 Default 6858819 Decimal 6858819 Hex Bx5c5d483 Binary 1811188818010100800000811 Figure 84 LPCXpresso IDE Variable View 9 3 1 Downloading Just Code This section describes how to download an application to the LPCXpresso board i e to the LPC111x without also starting a debug session Click on the Program Flash icon from the tool bar see picture below The icon can be at different places depending on window size Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 5 amp Pk a Jevelop EVEIOp File Edit Navigate Search Run Project Window Help B 9 b wc da aes i Pv jv 3 Binaries in Includes S driver 9 src 45 config linker C cmsis S startup amp Debug gt LPCXpresso MC BLDC Sensored Debug launch BLDC Sensored Release launch E lib small printf m Proj e N m Project Ex Program Flash P rog ra Flas h Ico n Start here j New project v Import Example project s Build all projects Debug amp Build BLDC Sensored Debug of Clean BLDC Sensored Debug Debug BLDC Sensored Debug 3 Quick Settings v Project a
91. al to a digital value There is a 10 bit ADC Analog to Digital Converter on the LPC111x microcontroller The ADC is described in chapter 25 LPC111x LPC11Cxx ADC in the LPC111x user s manual The ADC peripheral needs some initialization before it can be used Also the pin muxing needs to set the analog input functionality to the pins There are 8 inputs to the ADC and hence 8 pins that can be initialized The function outlined below initialize the first four pins as analog inputs The function also initializes the ADC to be ready for conversion commands Check the LPC111x user s manual and make sure you understand the different register initializations below KR KK KK K KKK KK KK K KA KK KK K KAZ A KK K AA KK KK K KAZ Z KK KK KK KK KK AXA KK KK KK KK KK KK KK Kk Function name ADCInit Descriptions initialize ADC channel parameters ADC clock rate Returned value None KK Ck kCKCkCk AA kk KK KK KK KK Ck ck k kk kCk K AKA kk KK K AXA Z kCkc kckck kk kCkCk ck k kk kCk Ck kck kk ck k kckck k ck kk kk kk void ADCInit uint32 t ADC CLK Disable Power down bit to the ADC block LPC SYSCON gt PDRUNCFEG amp 0x1 lt lt 4 Enable AHB clock to the ADC LPC SYSCON gt SYSAHBCLKCTRL 1 lt lt 13 Set pin mux correct for ADC INO IN1 IN2 LPC IOCON gt JTAG TDI PIO0 11 amp 0x8F LPC IOCON gt JTAG TDI PIO0 11 0x02 ADC LPC IOCON gt JTAG TMS PIO1 0 amp 0x8F LPC IOCON
92. all be port number bit number and direction After that recreate the program from the previous experiment using these two new functions It is good programming practice to place functions that are related in separate files It will enhance tile source code structure and make it easier to maintain and understand in general An accompanying include file h file declares the functions that are exposed to other source code files Place the GPIO related functions in a separate file called gpio c and create an include file gpio h that declares the exposed functions Also in order to keep the file main c reasonable short move all defines that are related to the board to a separate include file board h 7 2 3 Lab 1c Delay Function LED Flashing Next design a program that flash with the LED 50 ms milli seconds on 150 ms off 50 ms on and finally and 750 ms off Continuously repeat this 1000 ms cycle In is acommon task in embedded systems to operate on exact time and control external devices exactly In this case a LED One obvious solution is to create a delay function An example is listed below that forced the CPU to execute NOP no operation instructions in a loop Use this function and test different values in order to establish a relationship between the number of NOPs and the actual delay in time Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Delay by executing a given n
93. and can only be soldered to the pcb i e not used on the bread board This component is polarized When rotating the components so that the printed text on the package can be read pin 1 is in the lower left side on the package When mounting this component make sure it is turned correctly NXP PCA9532D Digikey 568 1039 5 ND Mouser 771 PCA9532D T This is not a polarized component CTS Freq Controls ATS120B Digikey CTX904 ND LPCXpresso Experiment Kit User s Guide o Powering Options There are a couple of different options how to power the experiments Below is a short list summarizing the options Controller R2 Power option 1 Power via external 5V supply J1 or J17 LPCXpresso board Do not mount R2 Power via USB Yes can also be done connector on p board LPC1114in DIL28 in DIL28 MomtR2 0 R2 I Lc NN not mount R2 Power via mbed __ DE can also be done connector If the servo interface USB Host interface and or RF module are used the board MUST be powered via an external 5V supply Powering via the USB connectors of the LPCXpresso mbed module is typically not enough Below is a more details description Read through all different options to determine which powering option fits your needs e The simplest and most common way is to let the LPCXpresso board generate the 3 3V supply that is needed This voltage is available on pin 29 on the LPCXpresso expansion connector see schematic for de
94. at is called the Nested Vectored Interrupt Controller NVIC It is an integral part of the Cortex MO core The NVIC can be regarded as a peripheral block but a special one It is programmed setup via registers just like any other peripheral It supports 32 interrupt sources and there are four programmable priority levels Individual interrupts can be masked i e disabled in the NVIC It is also possible to generate an interrupt via software writing in a special register will trigger the specified interrupt An indication that the NVIC is a special function block is that all information can be found in chapter 28 6 2 Nested Vectored Interrupt Controller in the LPC111x user s manual This is the chapter that contains Cortex MO core information Chapter 6 LPC111x LPC11Cxx Nested Vectored Interrupt Controller NVIC basically only contains a table Table 54 that lists the different interrupt sources in the LPC111x Almost all of the 32 sources are used Have a look in file LPC11xx h It is found in the CMSIS library in the inc sub directory Amongst other things the typedef declaration below is found in this file It lists the names and numbers of the different interrupt sources Interrupt Number Definition typedef enum IROn NonMaskableInt IROn 14 2 Non Maskable Interrupt x HardFault IRON 13 3 Cortex M0 Hard Fault Interrupt s SVCall IROn 59 IL Cort x M0 SV Call Interrupt ay PendSV IRON mas 14 Cortex MO Pend SV
95. ated code in file uart c and place the function prototype declarations in file uart h Do not forget to remove the retarget c file and change back C runtime library to Redlib semihost The code is quite complex and builds on two circular buffers The receive and transmit buffers can have different sizes but they must be a power of two The reason for this is the special mask operations bitwise AND with size minus 1 Characters to be transmitted should be placed in a circular buffer If transmission is not active start transmission again with the first character in the buffer As soon as a character has been transmitted the interrupt handler checks if there are more characters to be transmitted in the buffer If no more disable the transmission interrupt Extend the code above to also implementa uint8 t UARTGetCharBlock void function that blocks until a char has been received and returns the received character Let the new function make use of the UARTGetChar function Also update the UARTSendString and UARTSendBuffer functions from Lab14a The suggested function prototypes are as below These functions are needed on future experiments with RF modules KKK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK ck ck ck k ck ck k ck ck ck k KK KK KK KK ko Function name UARTSendString KK Descriptions Send a null terminated string to UART 0 port parameters byte to send and if call should wait for transfer t
96. avigate Search Project Run Window Help ra Sr Rr wide o amp S iim ERO pase 8 iS OF S S Rl e e a oH bow 3 EE S projed 1 Right click on ul project root and select gt Properties ae P uide 4 B MCU C Compiler LS20031_ C Preprocessor at Symbols C xbee cled gt E xbee oled Serieievartables nem Discovery Options e mesma Includes Environment 3 Optimization Manage linker scri f B src Logging 3 Debugging 33 Warnings pesattings cr startup Ipci1 c Q3 Miscellaneous gt main c i Target Editor gt larg gt gt Debug ain B readme txt C C General 4 MCU Assembler 3 General gt xbee oled Debug la xbee oled Release EIN Thumb mode xbee _Debug d Use C library Redlib semihost Project References Select which libraries to use when building Run Debug Settings GS Target E Enable Code Retrpre E 4 MCU Linker e General Libraries 3 Select Settings di Miscell Sarehan Settings Target 4 Select Target Figure 21 Selecting Semihosting C Library 7 9 1 Lab 4a Semihosting and printf In this experiment you will learn how to print messages from the LPC111x microcontroller to the console window in the LPCXpresso IDE The code below outlines what is needed in order to use printf Figure 22 below illustrates how the console window looks like when e
97. aw lcd t led outputs GPIOSetDir OLED SSEL PORT OLED SSEL PIN GPIO DUTPUT GPIOSetDir OLED DC PORT OLED DC PIN GPIO OUTPUT GPIOSetDir OLED RESET PORT OLED RESET PIN GPIO OUTPUT GPIOSetValue OLED SSEL PORT OLED SSEL PIN 1 GPIOSetValue OLED DC PORT OLED DC PIN i GPIOSetValue OLED RESET PORT OLED RESET PIN 1 SSPOInit printf nInitializing oled driver oled init sled rainbow amp lcd enter forever loop while 1 return 0 Run the program and verify that a white bar is shown on the display Now complete the rainbow function to show 8 differently colored bars on the display Explore the other drawing primitives in the draw c h file Some possible improvements of the code base e Increase the speed of the SPI bus to 6MHz originally 1 5MHz e Test the ssd1351 fadeln ssd1351 fadeOut ssd1351 verticalScroll ssd1351 horizontalScrol ssd1351 deactivateScroll functions Examples of usage can be found in the software package that came with the OLED display module Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 126 7 18 Extra Work with USB Device In this experiment you will learn how to work with an USB device interface This experiment requires an LPCXpresso board with USB device interface The LPCXpresso Experiment Kit pcb has been designed for the LPCXpresso LPC1769 board but it is also possible to use the LPC1347 and LPC11U14 board
98. basic Debug resso website grades etc visit the Code Red Technologies LPCXpresso website 35 Debug demo aoa basic Debug Visit the Embedded Artists LPCXpresso website O Sine ee debugging the project with the selected build configuration c C Project and File wizards Y E Console 23 I Problems g Memory dil Red Trace Preview L T S LH BH Ex m E ri E X Import and Export Y C Build demo aoa basic make clean Build and Settings Y rm rf src AndroidAccessoryHost o src cr startup lpci7 0 src main o src AndroidAccessoryHost d src cr startup lpci7 d src main d demo aoa basic axf E amp Debug and Run BE B Evtrse p eS demo aoa basic demo aoa basic NXP LPC1769 Figure 78 LPCXpresso IDE Debug Project In case flashing fails an error message like below will be displayed This is an indication that the debugger could not connect to the LPC111x The most common reason is that the microcontroller is in a low power mode where the debug connection is disabled Make sure the microcontroller is in ISP bootload mode and try again This is accomplished by pulling pin PIOO 1 low via 100 1000 ohm resistor to ground 02 Failed on connect Ee 07 Bad ACK returned from status wire error Figure 79 LPCXpresso IDE Program Failing to Flash Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 143 When t
99. ck k kc kck ck ck ck k kckck kc k k ck k kk void main void initialize GPIO as needed enter forever loop let interrupt handle processing while 1 register callback to toggle LED in 200ms registerCbAndDelay 200 amp toggleLED wait until callback has been called while pCB NULL Place the callback related functions in file timerCB c The structure above is not perfect since the caller must wait until the callback has been executed before the next callback can be registered and started To make it more user friendly extend the callback timer functionality to also support repeated calls When registering a new callback one parameter flag tells if it is a one time callback or a repeated callback A new function is then also needed to stop a repeated callback It would be good programming practice to let the function return an error if there is already an active callback in the system A much more flexible and robust framework would allow multiple callbacks to be registered and handled accordingly Such a framework is however a lot more work and out of the scope for this experiment 7 13 4 Lab 12d Nested Interrupts In this experiment the effect of nested interrupts will be investigated This experiment is a little combination of Lab 12a and Lab 12b Use the same breadboard setup as in these experiments one LED and one push button Setup a repeated timer interrupt to toggle the LED wi
100. constant value 0x04 Below is an alternative more compact way of writing the statements This is a common way to write this kind of statements Set PIOO 2 as an output LPC GELOD SDEIE 0x1 lt lt 2 Turn LEDI on set PIOO 2 pin low 1 e6 clear bit LPC GPIOU DATA amp 0x1 2 In real professional programs it is common to use defines to hide details about hardware manipulation Below is an example of how this can be done Create defines for simpler access of LED1 define DIR REG LED1 LPC GPIO0 gt DIR define DATA REG LED1 LPC GPIO0 gt DATA define PIO PIN LED1 2 define LED1 ON DATA REG LED1 amp 1 lt lt PIO PIN LED1 define LED OFF DATA REG LED1 1 lt lt PIO PIN LED1 Set PIOU 2 as an Output DIR REG LED1 0x1 lt lt PIO PIN LED1 Tarn LED1 on LED1 ON It is possible to take the principles further and create general macros for handling all ports and pins This was just an example of how to create well structured maintainable and professionally looking code Chapter 9 contains a description how to get started with the LPCXpresso IDE Read this chapter and follow the guide how to import the projects Start working with project lab 1a which is the base for this first experiment After compiling and linking without errors follow the guide how to download and run the project In embedded programming it is important to have full control over the variables more specifical
101. cts that state of a push button 7 3 1 Lab 2a Read Push button We will start with reading the state of push button SW2 in the schematic which is found in the schematic on page 4 lower left corner SW2 is connected to signal GPIO 1 KEY Figure 11 illustrates were SW2 can be found in the schematic On schematic page 2 we can see that this signal is connected to PIO1 5 on the LPCXpresso LPC111x board Figure 12 illustrates where to find the signal and also where to find the GND pin 5 push buttons in joystick configuration Figure 11 SW2 on Schematic Page 4 LPCXpresso and mbed connector pin naming is generic LPCXpresso LPC1343 1114 LECHE dual 1X27 pos e ea T IL 1 28 VIN PT 5 5V 2 29 a 30 PIO 0 A 4 31 PIOO 9 MOSI CT16BO MAT1 SWO PIO 1 MOE 5 32 ETH Rxh PI O 8 MISO CTIGB MATO PIO 2 MISQ amp 33 ETH AXP PIO2 11 SCK PIC CK 7 34 ETH TAN PIOO 2 SSEL CT16B0_CAPO PO 1 85 Bl 35 FIH TXE PIO1 7 TXD CT32B0 MAT 1 BIO 8 36 3B DIN PI 1 6 RXD CT32BO0 MATO PIC RXD 10 37 3 DP FIOO 7 CTS LED PI T BUZZ 11 38 GPIO 24 K PIO2 O DTR PIC D 5 12 39 GPIO 25 VBl PIO2 1 DSR zia 1 85 13 40 GPIO 26 50 FIO2 2 DCD PO 10 D CA 14 a E GPO 27 S TDI PlOO 11 ADO CT32B0_MAT3 PIC AINC 15 42 GPIO 28 PWN TMS PIO1 Q AD1 CT32B1 CAPO FIO AJ 16 43 PIO 29 PWN TDO Pl 1 1 AD2 CT32B1 MATO PIC AJ 17 44 FIO 30 PWV TRST PIO1 2 AD3 CT32B1 MAT1 PICO 14 AIR 18 45 GPIO 31 L ED CA2 SWDIO RIOT ra CAD Ma XA E l 19 46 GPIO A2 PIC BZU IE E
102. d print result wait 3 seconds Place the LM75 related code in file 1m75 c 7 14 3 Lab 13c Control LEDs via PCA9532 In this experiment a GPIO expansion chip PCA9532 shall be used The chip can also generate PWM waveforms to for example dim LEDs It is essential to study the PCA9532 datasheet before writing any code The PCA9532 chip has a more complex interface than the LM75 More registers must be controlled There are 16 I O pins and 10 registers in the chip e Two registers are used for reading the 16 inputs two bytes e There are two PWM generators in the chip Two registers are needed to control each generator so four registers in total for this e Four registers are used to control the 16 pins if they are outputs 2 bits per pin which means that one byte can control 4 pins resulting in four registers to control 16 pins A pin can have one of the following four states o Actively driven low o High impedance where the pin is typically driven high by an external pullup resistor The pin can also be an input in this state o Driven by PWM generator 0 alternating between actively driven low and high impedance o Driven by PWM generator 1 The external LEDs are connected via the cathode to the PCA9532 chip This is because the chip can only sink current Below is a code framework for controlling the 16 outputs via function pca9532 setLeds tdefine PCA9532 I2C ADDR xCD define PCA9532 IN
103. duty cycle is 0 and fully off when the duty cycle is 1 100 Duty d D Frequency 1 D d lt gt D lt gt Figure 28 PWM Signal Below is a code structure that can be used to generate a signal with a specified duty cycle The loop should be repeated as often as possible in order to keep generating the signal As seen the loop below will perform 100 iterations so the resolution of the duty cycle control is 1 Higher resolution is Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide possible by increasing the number of iterations but the trade off is lower freguency of the duty cycle This may or may not be a problem as we will investigate in later experiments Set wanted duty cycle wantedDutyCycle Set output high Enter duty cycle generating loop for loopCounter 0 loopCounter lt 100 loopCounter if loopCounter wantedDutyCycle Set output low Create a program that generate a fixed duty cycle and controls a LED Define the duty cycle with a constant in the program About what frequency does the PWM signal have measure with an oscilloscope of logic analyzer if possible Draw a diagram of the perceived LED intensity with different duty cycles Intensity Full None 0 20 40 60 80 100 Duty cycle 7 1 2 Lab 6b PWM Control of a LED cont 1 In this experiment let the value from the trimming potentiometer control the duty cycle Build on th
104. e code that was developed in Lab 6a Read the AINO value and set duty cycle between 0 100 accordingly As an extra experiment let the light sensor control the duty cycle If the room is dark have full intensity on the LED and vice versa 7 1 3 Lab 6c PWM Control of a LED cont 2 In Lab 6a the duty cycle frequency was fixed to a relatively high value In this experiment you shall investigate how this frequency affects the LED intensity At some point when lowering the frequency you will notice a flickering on the LED Create a program where one trimming potentiometer controls the duty cycle and another trimming potentiometer controller the frequency Tip Add a variable delay in the loop Let the delay be 1 us or multiples of it At 1 us delay a total of 100us delay will be added per cycle This equals 10 kHz Measure and verify that you get about this Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide frequency It will be slightly lower since more than just delays are performed in the loop If the delay is 2 us the frequency will be 5 kHz if 3 us it will be 3 3 kHz etc At what frequency does the LED flickering become apparent 714 Lab 6d PWM Control of two LEDs In this experiment you shall create a program that controls the intensity of two LEDs with the help of two trimming potentiometers One loop shall now control two different PWM signals As seen it becomes more and more complicated t
105. e o o e e e e e e e e e e e e e e e e e e ee ee ee e e e e e ee ee o e e e o e e e e e o e ee ee ee ee ee a e e e e o e eeeeeee e e o o Made with 9 Fritzing org Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide The suggested program structure is presented in the code block below Time multiplexed loop for controlling two 7 segment digits while 1 Calculate value to present on display e g read ADC input 0 Disconnect anode of digit 2 and reset segment outputs Connect anode of digit 1 to 3 3V Output value on digit 1 control segment outputs Wait 5ms Disconnect anode of digit 1 and reset segment outputs Connect anode of digit 2 to 3 3V Output value on digit 2 control segment outputs Wait 5ms Implement the time multiplexed control above and create a program just like on the previous experiment that presents the value of analog input 0 not on one digit 0 9 but on two digits 0 99 Adjust the conversion function accordingly 1 9 5 Lab 8e Control 7 segment Display via Shift Register In this experiment we shall use a shift register to control the LED segments This is the circuit that is drawn in the schematic and designed on the pcb The idea is to use a serial bus called SPI but in this experiment we will not use this bus That is for a late
106. e R Export arted Open Xpresso Getting Started Guide Open With 5o Resources it www nxp com Ipcxpresso support 50 Forum iew the forum and to register so that you can post visit www nxp com Ipcxpresso forum ormation New project Gi Pos a Refresh P it the NXP LPCXpresso website Import project s Make Targets information on upgrades etc visit the Code Red Technologies LPCXpresso website Build all projects Debuc the Embedded Artists LPCXpresso website Clean Selected File s 8 1 ul A aa riiai Build Selected File s of Clean DemoApp Debt en As js Debug DemoApp Deb Debug As Quick Settings v Profile As Team Project and File wizard Compare With Import and Export Replace With E Build and Settings Launch Configurations Debug and Run vn update n DemoApp Debug DemoApp bin NXP LPC11U14 201 Figure 90 LPCXpresso IDE Binary Utility 9 4 Create own Projects by Copy Existing Project The simplest way to create a new project is to copy an existing project Start by right clicking on a suitable existing project to start from Select Copy as illustrated in Figure 91 below Then right click on an empty space in the Project Explorer window and select Paste as illustrated in Figure 92 below Finally give the new project a suitable name as illustrated in Figure 93 below Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s
107. e bt powered by Aicode red gt ES demo aoa can gt ES demo a02 xbee LPCXpresso4 is fully activated gt ES FreeRTOS demo s Lib AOA Welcome to LPCXpresso 4 The software is now fully activated and can be used for production LPCXpresso can be used to E Lib B d generate and download applications containing up to 128KB of code into an LPC target gt ib_Boar gt E Lib CMSISv2p00 LPC17xx Getting Started gt ES Lib FatFs SD Please read the getting started guide for step by step instructions to build your first LPCXpresso project gt ES Lib FreeRTOS gt ES Lib Iwip e Lib MCU gt ES Iwip httpd LPCXpresso Resources gt e nxpUSBlib Check the LPCXpresso Support page for new LPCXpresso software releases more example projects and announcements LPCXpresso Getting Started Guide The Red State Guide provides information on using Red State state machine generator within LPCXpresso 0 Quicks 1 E RedC 0 Variab Break Fm Visit www nxp com Ipcxpresso support LPCXpresso Forum GI Start here The LPCXpresso Forum community is exclusively built for LPCXpresso users and is an invaluable resource for getting help and ie New project advice on use of the LPCXpresso tools and boards jin th i e Import project s So get connected and join the LPCXpresso community Build all projects Debug nd to register so that you can post visit www nxp com Ipcxpresso forum amp Build demo aoa
108. e clockwise direction B is high How to detect a negative edge on signal A Tip When sampling input A compare with previous sample If old sample is high and new sample is low then a negative edge has occurred Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 5 Print Messages So far the microcontroller has had limited possibilities to communicate with the user Technically it would have been possible to communicate information via the Morse code experiments via a LED or a buzzer but it is not a very user friendly method and it would take time to communicate longer messages In this experiment you will learn how to print messages from the program in the LPCXpresso IDE No breadboard work is needed for these experiments The LPCXpresso IDE has support for something called Semihosting It is a term from ARM that indicates that part of the functionality is carried out by the host The host in this case is the PC i e the LPCXpresso IDE It is a very useful debug tool for small systems that do not have a dedicated communication channel for outputting debug information It is very easy to enable Semihosting in a project Figure 21 below indicates the project setting that is needed to be carried out Basically it is an instruction to use a special C runtime library A library that directs printf output to the LPCXpresso IDE Develop xbee oled src main c LPCXpresso File Edit Source Refactor N
109. e plastic package on the short side This indicates where pin 1 is located lower left side in the picture to the left When mounting this component make sure it is turned correctly NXP 74HC595N Digikey 568 1484 5 ND Mouser 771 74HC595N This component is polarized One side of the plastic package is flat and the other side is rounded When mounting this component make sure it is turned correctly Microchip MCP9701 E TO Digikey MCP9701 E TO ND Mouser 579 MCP9701 E TO This component is polarized There is a cut in one end of the plastic package on the short side This indicates where pin 1 is located When mounting this component make sure it is turned correctly Microchip 25LC080D I P Digikey 25LCO80D I P ND Mouser 579 25LC080D I P LPCXpresso Experiment Kit User s Guide Temperature sensor LM75 1 pcs U6 I2C port expander PCA9532 1 pcs U7 12MHz HC49 crystal 1 pcs Y1 http en wikipedia org wiki Crystal_oscillator Copyright 2013 Embedded Artists AB This is a Surface mounted component and can only be soldered to the pcb i e not used on the bread board This component is polarized When rotating the components so that the printed text on the package can be read pin 1 is in the lower left side on the package When mounting this component make sure it is turned correctly NXP LM75BD Digikey 568 4688 1 ND Mouser 771 LM75BD118 This is a surface mounted component
110. e web page regardless of which URL is requested For example http 192 168 5 200 returns the same page as http 192 168 5 200 test a page html This experiment is based on the code examples that are delivered with the LPCXpresso IDE The code is structured very differently none of the code from the previous exercises is used You have to create a new workspace in LPCXpresso and then import the projects from Lab19a zip Connect an Ethernet cable between the J4 connector on the experiment board and a network hub switch router depending on the network you are connected to The project needs a couple of small changes to work Start by creating a unique Ethernet address MAC address by opening ethmac h and modifying these lines define our ethernet MAC address define MUST be unigue in LAN define define define define The address must be unique on the network If you are doing these labs with other students colleagues then you must all agree on which addresses to use to avoid name conflicts After selecting an Ethernet address it is time to select a fixed IP address This is set in tcpip h like this define MYIP 1 197 our internet protocol IP address define MYIP 2 168 define MYIP 3 5 define MYIP 4 200 This address also has to be unique within your network Compile and run the code To see if everything works open a command prompt and run ping to see if your board responds make sure to use the i
111. ead aaa tom memory anay begining at seeded address wmn 0000 0110 Set the write enable latch enable write operators Figure 49 25LC080 Instruction Set To read in the memory region a start address 16 bit address is transmitted after the READ instruction In total three bytes are transmitted from the microcontroller to the 25LC080 chip before bytes can be read from the memory As many bytes that are of interest can be read out in the read operation An internal address counter is incremented after each transmitted byte If the highest address is reached Ox03FF for this chip the address counter rolls over to address 0x0000 Note that the SSEL signal or CS that it is called in the picture below is low during the complete operation FIGURE 2 1 READ SEQUENCE High Impedance Data Out 7X 8X 5X 4X 3X 2X 1X 9 Figure 50 25LC080 Read Sequence To write in the memory region the WRITE instruction is used Similar to the read operation a 16 bit address is transmitted to set the start address of the write operation One or many bytes can be written at the same time see the pictures below FIGURE 2 2 BYTE WRITE SEQUENCE 0 1 2 3 4 5 6 7 8 9 10 11 21 22 23 24 25 26 27 28 29 30 31 Twc ree Instruction 16 bit Address Data Byte 0 0 o o ofiVo ts 14 1302 2K AY OL 7X SX 4X 3X 2X3 9 High Impedance Figure 51 25LC080 Byte Write Sequence De
112. ed at 10 Hz rate declare variables Uints t sStateLED Initialize pins to be inputs and outputs set outputs to defined states enter forever loop while 1 delay a specified period of time the sample period check if push button is pressed if toggle LED wait until push button is released while Experiment with different delay settings sample rates and see how fast you need the sample to push button in order not to miss a quick push button press About what sample rate is needed in order not to miss any button presses As an added bonus the problem with contact bounce is also handled when the delay was added That is because the microcontroller is idling in the delay loop while the contacts bounce Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 4 Control Multiple LEDs In this experiment you will learn how to control multiple I O pins simultaneously More specifically you will learn how to control eight LEDs This experiment builds on the knowledge you have gained from the previous experiments 1 4 1 Lab 3a LEDs in Running One Pattern As a start create the circuit with 8 LEDs and two push buttons as illustrated in Figure 18 below Only one push button is used in this experiment but in the two next two are needed Have a look at page 4 in the schematic to get al LED and push button connections LED1 LED8 and SW2 SW3 are mounted All
113. ee main colors red blue green at each press and set intensity level with the trimming potentiometer Test to blend the three colors and see which colors it is possible to create 7 11 2 Lab 10b Buzzer and Melodies In this experiment we shall use the buzzer to output tones and in the end a melody The buzzer self resonates with a tone of about 2 3kHz What you will do is to modulate the buzzer turn it on off with the frequency of the tone to produce This tone will be audible as well as the self resonate tone The code segment below illustrates how to generate a tone Note the table with constants for producing two octaves of notes Study the code below 2272 A 440 Hz 2024 B 494 Hz 3816 C 262 Hz 3401 D 294 Hz 3030 E 330 Hz 2865 F 349 Hz 25581 7 G 392 Hz 1136 a 880 Hz 1012 b 988 Hz 1912 c 523 Hz 1703 7 7 d 587 Hz 1517 e 659 Hz 1432 698 Hz 1275 77 g 784 Hz E7 KKK KKK K KKK KKK KK K AA KK KK K AAA A X AK K KAZ X K K KK KK KK KK KK KK KK KK A KK KK KK KK KK KK kk Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Function name playNote Descriptions Initialize 16 bit timer 1 for PWM generation Parameters noteInUs Period time in microseconds for tone WU durationMs Length of tone in milliseconds Returned value None KK KKK ck ck k kk kk ck ck k X k kk ck ck k
114. eturned value None HK KK KK ck kk kCk kk ck ck kk k ck k ck ck kk k ck KK kA K ck k X k ck kc kc k ck kc k ck k kc k ck k k ck k kc k ck k ck ck k kc k ck k kA k k kk void GPIOSetvalue uint32 portNum uinto2 t DItPOSl Uinta t bitVal Check that bitVal is a binary value 0 or 1 if bitVal lt 2 The MASKED ACCESS registers give the ability to write to a specific bit Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide or bits within the GPIO data register See the LPC11 13 user manual for more details lSSDitPoS1 Gives us the MASKED ACCESS register Specific to the bit that is being requested to be set or cleared bitVal bitPosi will be either be 0 or will contain a 1 in the appropriate bit position that matches the MASKED ACCESS register being written to x i switch portNum case PORTO EPC GPIOU 2MASRED ACCESS 1s lt bitPos1 batVal lt lt bitPosi break case PORTI LPC GPIOI 2MASKED ACCESS 1 lt lt bitPosi bitVal lt lt bitPosi break case PORT2 LPC GPIOZ MASRED ACCESS 1 lt lt bitPosi bitVal lt lt bitPosi break case PORT3 LPC GPIOS MASRED ACCESS i lt lt bitPosi bitVal lt lt bitPosi break default break Create a similar general function for setting the direction of any GPIO pin input or output Call this new function GPIOSetDir The function s input parameters sh
115. fine LSR TEMT 0x40 define LSR RXFE 0x80 define IER RBR 0x01 define IER THRE 0x02 define IER RLS 0x04 define IIR PEND 0x01 define IIR RLS 0x03 define IIR RDA 0x02 define IIR CTI 0x06 define IIR THRE 0x01 static volatile uint8 t txBuf TX BUFFER SIZE static volatile uinc32 txHead 0 static volatile nint EXTSLL 07 static volatile uint8 t txRunning FALSE static volatile uinte t rxBur BX BUFFER SIZE static volatile uint32 t rxHead 0 Static volatile Wint LE rxTall OF KKK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KKK ck ck k ck ck ck k ck ck KK KK KK KK KK Function name UARTInit Descriptions Initialize UARTO port setup pin select da clock parity stop bits FIFO etc parameters UART baudrate Returned value None AK KK Ck AK K AA kk KK KK KK KK K KAZ kk KK K AA KK KK K KAZ KK A AK K AAA KK KK AXA kCk KK KK KK KK KK KK KKK void UARTInit uint52 t baudrate Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide uintia t Fdiv uint32 t regVal NVIC DisableIRO UART IRON LPC IOCON gt PI01 6 amp 0x07 UART I O config LPC IOCON PIO1 6 0x01 UART RXD LPC IOCON PIOl1 7 a 0x07 LPC IOCON gt PIO1 7 0x01 UART TXD Enable UART clock LPC SYSCON gt SYSAHBCLKCTRL 1 lt lt 12 LPC SYSCON gt UARTCLKDIV 0x1 divided by 1 x LPC UART gt LCR 0x83 8 bits no Parity
116. from the previous exercises is used You have to create a new workspace in LPCXpresso and then import the projects from Lab18a zip Insert a USB memory stick in the J10 connector and then start the program The program uses semihosting so all printouts will be available in the LPCXpresso IDE If the memory stick is found and the file is copied the printouts should look like this Initializing Host Stack Host Initialized Connect a Mass Storage device Mass Storage device connected Copying from MSREAD TXT to MSWRITE TXT Copy completed If the memory stick was not inserted before the program started it will look like this Initializing Host Stack Host Initialized Connect a Mass Storage device ERROR In Host EnumDev at Line 407 rc 1 This is not very user friendly Improve the implementation of main to wait for the memory stick to be inserted copy the file wait for the memory stick to be removed and then start over Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 129 7 20 Extra Work with Ethernet Interface In this experiment you will learn how to work with the Ethernet interface and TCP IP This experiment requires the LPCXpresso LPC1769 board which has an Ethernet interface 1 20 1 Lab 19a easyWeb Web Server This experiment will demonstrate a very basic web server that is a part of the software package distributed with the LPCXpresso IDE The web server returns the sam
117. g and decreasing the LED running one speed Use two more push buttons for controlling the direction of the LED running one pattern and finally use one push button for start stopping the LED flashing All in all five push buttons are needed for this Only two are available for mounting on a breadboard Develop the program in steps First develop the variable speed solution Then set the speed to a fixed value and continue developing the direction control Then fix the direction and develop the start stop Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide control After these three steps all functionality has been developed Use the breadboard setup as illustrated in Figure 18 above There are five pcb mounted push buttons that can be used These push buttons are mounted in a joystick structure so the up down buttons can for example control the speed The right left buttons can be used to control the direction and the middle button can control start stop 1 4 3 Lab 3c Rotary Switch Control of Running One Pattern Note that this experiment can only be done in full on the pcb since the rotary switch cannot be mounted on the breadboard However it is possible to simulate a rotary encoder with two push buttons so the experiment can still be done on the breadboard if wanted In this experiment the rotation switch controls the LEDs running one pattern Turning the switch one step to the left shall advance the LE
118. ge or level sensitive interrupts Register GPIOnIEV controls if each individual pin interrupt is falling rising edge active or low high level active For edge sensitive interrupts register GPIOnIBE controls if a pin is sensitive to one edge rising or falling or both Whether to select an edge or level sensitive interrupt depends on the application and how the hardware interface works For the push button edge sensitive triggering is suitable since the key press occupation is what should be detected How long the key is pressed is of no concern in this experiment If the interrupt would have been level sensitive the interrupts routine ISR would have been activated over and over until the button is no longer pressed Level sensitive interrupts are suitable when the ISR can reset the interrupt condition by some action Note that the ISR must clear the interrupt condition for edge sensitive interrupts check the GPIOXIC register otudy the code below It is a framework for the experiment Note that the main loop does nothing just looping in a forever loop If power consumption is a concern it is suitable to place the microcontroller in a low power state Whenever the interrupt condition occurs the microcontroller will wake up and execute the ISR and then go back to the low power mode Define Interrupt Service Routine for Port 41 void PIOINT1 IROHandler void name of function is predefined toggle LED on PIOU 2 clear PIO
119. gt JTAG TMS PIO1 0 0x02 ADC LPC IOCON gt JTAG TDO PIO1 1 amp 0x8F LPC IOCON gt JTAG TDO PIO1 1 0x02 ADC LPC IOCON gt JTAG nTRST PIO1 2 amp 0x8F LPC IOCON gt JTAG nTRST PIO1 2 0x02 ADC LPC ADC gt CR 0x01 lt lt 0 SEL 1 select channel 0 7 on ADCO CLKDIV Fpclk 7 1000000 1 SystemCoreClock LPC SYSCON gt SYSAHBCLKDIV ADC Clk 1 8 OxO lt lt 16 BURST 0 no BURST software controlled 0x0 lt lt CLES 0 11 chocks 10 bits 0x0 lt lt START 0 A D conversion stops 0x0 lt lt EDGE O CAP MAT singal falling trigger A D conversion 7 6 1 Lab 5a Read Trimming Potentiometer In this experiment we shall read the value of analog input 0 There are two trimming potentiometers R7 and R20 on page 4 in the schematic One of them R7 is connected to GPIO 11 AINO and the other one R20 is connected to GPIO 12 AIN1 These signals correspond to AINO and AIN1 on the ADC The trimming potentiometers are connected to ground and 3 3V in each end By rotating the trimming potentiometers it is possible to adjust the analog voltage to any value between OV and 3 3V This corresponds exactly to the input range of the ADC OV input gives the converted value 0 and 3 3V input gives the converted value 1023 Figure 23 below shows the schematics around R7 The series resistor R6 330ohm is just for protection in case GPIO 11 AINO by mistake
120. gure below Welcome p File Edit Navigate Search Project Run Window Help Div E O 5 Sec n Qa hd wy hd v o vw v hd Project Ex 32 itt Core Regis Peripheral Welcome 3 ml J egis p B amp file C nxp Ipcxpresso 3 6 pages registered htm p powered by dill code red LPCXpresso is fully activated Welcome to LPCXpresso The software is now fully activated and can be used for production LPCXpresso can be used to generate and download applications containing up to 128KB of code into an LPC target Getting Started Please read the getting started guide for step by step instructions to build your first LPCXpresso project LPCXpresso Getting Started Guide LPCXpresso Resources software releases more example projects and announcements Quickstart 3 9 Variables 9e Breakpoint E 1 select Import and Export Start here i 3 s vice on use of the LPCXpresso tools and boards amp Project and File wizards So get connected and join the LPCXpresso community MN port and Export To y Import archived projects zip l 2 presso Forum community is exclusively built for LPCXpresso users and is an invaluable resource for getting help and Select Import archived projects zip C53 Import exisiting projects V ye 9 pror Import from a project archive zip file bie gag Import project s from XML Description not support Fo E Visit the Embedded
121. he LPC1115 version so the majority of users will likely work with the LPCXpresso LPC1115 board One of the included components is the LPC1114FN28 102 chip which comes in a DIP28 package That is a package that can easily be used on a breadboard Figure 74 below from the LPC111x User s manual lists the differences Type number Series Flash Total Power UART I2C SPI ADC GPIO Package SRAM profiles RS 485 Fast channels LPC1113FHN33 203 LPC1100XL 24kB 4kB yes 1 1 2 8 28 HVQFN33 LPC1113FHN33 301 LPC1100 24kB 8kB no 1 1 1 8 28 HVQFN33 LPC1113FHN33 302 LPC1100L 24kB 8kB yes 1 1 1 8 28 HVQFN33 LPC1113FHN33 303 LPC1100XL 24kB 8kB yes 1 1 2 8 28 HVQFN33 LPC1113FBD48 301 LPC1100 24kB 8kB no 1 1 2 8 42 LQFP48 LPC1113FBD48 302 LPC1100L 24kB 8kB yes 1 1 2 8 42 LOFP48 LPC1113FBD48 303 LPC1100XL 24kB 8kB yes 1 1 2 8 42 LOFP48 LPC1114 LPC1114FDH28 102 LPC1100L 32kB 4kB yes 1 1 1 6 22 TSSOP28 LPC1114FN28 102 LPC1100L 32kB 4kB yes 1 1 1 6 22 DIP28 LPC1114FHN33 201 LPC1100 32kB 4kB no 1 1 1 8 28 HVQFN33 LPC1114FHN33 202 LPC1100L 32kB 4kB yes 1 1 1 8 28 HVQFN33 LPC1114FHN33 203 LPC1100XL 32kB 4kB yes 1 1 2 8 28 HVQFN33 LPC1114FHN33 301 LPC1100 32kB 8kB no 1 1 1 8 28 HVQFN33 LPC1114FHN33 302 LPC1100L 32kB 4 8kB yes 1 1 1 8 28 HVQFN33 LPC1114FHN33 303 LPC1100XL 32kB 8kB yes 1 1 2 8 28 HVQFN33 LPC1114FHN33 333 LPC1100XL 56kB 8kB yes 1 1 2 8 28 HVQFN33 LPC1114FHI33 302 LPC1100L 32kB 4 8kB yes 1 1 1 8 28 HVQFN33 LPC1114FHI33 303 LPC1100XL 32kB 8kB yes 1 1
122. he code has been downloaded execution will stop at the first line in the main function Press F8 or the green arrow button to resume start execution Reset Start Resume Pause Stop debug Target Execution F8 Execution Session F 9 x ue b b b m Figure 80 LPCXpresso IDE Run Button It is possible to manually stop execution by pressing the Pause button After that it is possible to restart the execution by pressing the Start button or F8 Alternatively the target can be reset by pressing Reset button and the system return to the state just after program download i e at the first line in the main function The debug session is ended by pressing the Stop button The LPCXpresso IDE then returns to edit mode When the system has been stopped the call stack window indicates where the execution has stopped and the call path to get to that point s Debug 23 a Fe uart Debug C C MCU Application DSF 4 gf uart2 axf 4 P aco Hl cms Sms cB cR Call stack which Indicates the call E main at main c 23 Ox16e structure to get to the point where the sj gdb program is currently stopped Currently stopped at line 23 in main lc main c stdio h c uart c e cr startup Ipcll c c timer32 c a Welcome c maine 3 26 Reading data from UART1 and writing to UART2 and vice versa a g 18 include type h 11 include uart h 13 include stdio h 13 include timer32 h 14 include gpio h
123. his can cause damage to the respective pin drivers on the chips U1 LPCXpresso board J e e e e e 9 o e e e o o LJ ee e e e 9 o e e e o o e e o e o e e o o LJ e e e 9 o e e e 9 o ee e e v 9 o e e e o ee eee m CED o eee mn CHEND e GD 9 o n eee GUD o c eee e 0 e o o ve e o o o e e o o e e ee oo o ee ee e e o 9 o e e o o o ee ee e e ee 9 o e e e o o e e ee v e v o e e o 9 o ee ee e e o o e e e o ee e e e 9 e e e o ee v e v eo e e o o o ee ee ve v e o e e e o o ee ee ve e oo ve e 9 o ee ee e e e 9 o e e o o o e e ee e v e o e e e o o ee e e v e o e e o o ee e e e 9 o e e e o o e e ee e e v 9 o e eve e o e e o e 0 e 9 o e e e o ee e e ce ev eo o e ce e o ee ee e e e e e eve e o o ee 5 e e e eve e 9 o Made with 9 Fritzing org Figure 54 Breadboard with SPI E2PROM Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 13 Work with Interrupts In this experiment you will learn how to incorporate interrupts in your program Interrupts are a powerful concept in embedded programming It is a way to interrupt the normal program execution flow to service something else quickly This something else is typically a peripheral block that needs to be serviced or it is an external event that needs attention a reaction There is a functional block in the LPC111x th
124. hl BE E v 20 AT OPIU a33 GPI CG 17 KEY 21 48 GPIO 34 ETT nb T C GPIO TEKEY 21 48 GPIO 35 K PIOO 6 USB CONNECT SCK E SR CONN 23 50 GPIO 36 SWCLK PIOO 10 SCK CT16B0 MAT2 24 51 GAPO A lek PIO 21 LED 25 52 GPIO 38 QA gt 29 ED 2B 53 GPIO 380 0B PIO 23 ED 27 y5 ann Figure 12 Signal GPIO 17 KEY on Schematic Page 2 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Keep the previously mounted LED Get a push button representing SW2 and a 330 ohm resistor representing R31 from the components bag Note that there are two types of push buttons for pcb mounting and for breadboard mounting It is the latter that shall be used now Mount the push button and resistor on the breadboard and connect to the LPCXpresso LPC111x board as illustrated in Figure 13 LPCXpresso board Pin 8 SSEL PIOO 2 Made with J Fritzing org LE iniurg 12 Draadhasrd Cannartinne far SMIO and rigure 135 breaaboara vonnections Tor oVV4 ana It is common that microcontroller input pins have built in pull up resistors If the input is not driven the input is high Sometimes the behavior of the pins is very programmable for example if pull up or pull down resistors and input hysteresis shall be enabled In this experiment a pull up resistor must be enabled on the input pin When pressing the push button it will actively pull the input pin to ground Else the internal pull up resistor will pul
125. ia low pass filtering a PWM signal e How to create a capacitive touch sensor e How to use an opto coupler to galvanically isolate a digital signal Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 139 9 LPCXpresso IDE How to get Started This chapter gives a quick presentation of how to get started with the LPCXpresso IDE which is the integrated program development environment that was created for the LPCXpresso board family There are also more extensive and detailed presentations and descriptions on the LPCXpresso website 5 Before starting make sure that the latest version of the LPCXpresso IDE is installed See 5 nttp www nxp com pexpresso for details where to download and how to install 9 1 Importing Projects A package of projects has been created as a base for supporting the experiments It makes it easier to get up and running quicker with the first set of experiments Download this package from Embedded Artists support page after registering the product It is a zip file that contains all project files and is a simple way to distribute complete Eclipse projects This section describes how to import the package of projects into the Eclipse workspace Several projects will be imported simultaneously Start the LPCXpresso IDE and select a new and empty workspace directory Select the mport and Export tab in the Quickstart menu and then Import archived projects zip see fi
126. ight 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 2 Introduction Thank you for buying Embedded Artists LPCXpresso Experiment Kit designed to work with NXP s ARM Cortex M0 M3 LPCXpresso target boards This document is a User s Guide that describes the LPCXpresso Experiment Kit that describes hardware as well as software related to the kit 2 1 Features The kit has been created as a guided tour to learn embedded programming with NXP s LPC1000 microcontroller family with Cortex M0 M3 cores from ARM The experiments can be performed on a breadboard for maximum flexibility and ease of use It is also possible to solder the components to a printed circuit board pcb and learn soldering at the same time Components included in the kit are e OxLEDs e 2x Trimming potentiometers e xpush buttons e RGB LED e light sensor analog e Temperature sensor analog e segment LED dual digit e E2PROM with SPI interface e Temperature sensor with I2C interface only for pcb mounting e Piezo buzzer e Rotary quadrature encoder only for pcb mounting e Shift register e 2C ports expander PCA9532 only for pcb mounting e USB Host connector only for pcb mounting e USB Device connector only for pcb mounting e RJ45 connector for Ethernet only for pcb mounting e 14 pos serial expansion connector for interface to for example graphical displays e Jx servo connectors Note that servos are not included e X
127. in later experiments 1 9 2 Lab 8b Control 7 segment Display In this experiment you shall control one digit of the segment LED display with the microcontroller We will use eight outputs to directly control each segment of the display The anode of digit 1 will be connected directly to 3 3V while the anode for the second digit is left unconnected As we have done before the breadboard setup is prepared for the next experiments also We will for example not use the trimming potentiometer in this experiment Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide U1 LPCXpresso board eee o Rk bj Made with 3 Fritzing org Figure 36 Breadboard Connections for 7 segment Display The same eight outputs are used as in the experiments with the 8 running LEDs except for LED4 and LEDS e LED1 GPIO 4 LED SSEL corresponds to segment A e LED2 GPIO 8 LED SSEL corresponds to segment B e LED3 GPIO 9 LED SSEL corresponds to segment C e GPIO 36 controls segment D e GPIO 37 controls segment E e LED6 GPIO 23 LED corresponds to segment F e LED GPIO 22 LED corresponds to segment G e LED8 GPIO 21 LED corresponds to segment DP Create a program that increment a digit 0 9 each second It shall roll over to 0 when 9 is reached Let the dot LED light for 100 ms after an increment A suitable program structure is to create a subroutine that takes a number 0 9 as
128. in this experiment focus is on the principles and getting to know the SPI bus and the SSP peripheral block As a first part in this exercise update the SSPOlnit function to take an input parameter to control the SCLK frequency This can be done more or less complicated To keep it simple just calculate the SCR bits in the CRO register It will not give full coverage but at least some range Create an application the send one byte 8 bits and then reads it back Verify that the read back byte is correct Use GPIO 4 LED SSEL PIOO 2 as SSEL signal and do not forget to initialize this GPIO signal as an output and to also control the signal levels during SPI communication It shall be high when no communication takes place Pull the signal low before transmitting the byte and then pull it high after the transmission Rebuild the breadboard circuit in Lab 8e Control 7 segment Display via Shift Register on page 68 The 7 segment display is not needed but as preparation for the next experiment it is simplest to rebuild it all The breadboard setup is repeated below with one extra wire the MISO signal Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide U1 LPCXpresso board A e Made with 9 Fritzing org Figure 48 Breadboard with Shift Register and 7 segment Display with MISO 7 12 2 Lab 11b Control 7 segment Display In this experiment will shall revisit Lab 8e Control
129. inal applications e eraTerm which is recommended http sourceforge jp projects ttssh2 files e PUTTY http www chiark greenend org uk sgtatham putty e Terminal by Bray http sites google com site braypp terminal e RealTerm http sourceforge net projects realterm files Download and install the selected terminal application The next step is to configure the application Typical configuration settings are selecting COM port setting bit rate for example 9600 bps set if parity is used and number of stop bits Flow control is another setting that is common Select None for this setting Other settings require either additional hardware or software support For TeraTerm select New Connection in the File menu Select the COM port that appears when the FTDI UART to USB cable is connected to the PC Click OK The screenshot below illustrates the dialog window for setting up a new serial connection Tera Term disconnected VT File Edit Setup Control Window Help TCPAP ost myhost example com History Telnet SSH2 UNSPEC UM ae KATE L f COM3 V5com COM Port COM3 COMS VScom COM Port COM5 Figure 60 TeraTerm Configuration Step 1 To set the bit rate and other relevant settings for the serial channel go to Setup menu and select Serial Port A dialog like illustrated in the screenshot below opens Make sure Flow control is set to none Copyright 2013 Embedded Artists AB LPCXp
130. ind more information about this protocol specification A simpler project just output the results from the GPS module on a display with X Y coordinates A more advanced project visualizes the location on a graphical display 8 4 Interface an SD MMC Memory Card Interface an sd mmc memory card via the spi bus There are application notes from NXP that gives a good start Add FAT file system handling on top of the low level interface drivers 8 5 Interface an Accelerometer and Gyro Interface an accelerometer 2 or 3 axis or a gyro There are several chips with associated breakout boards for simpler interfacing on the market Select a chip with digital interface I2C or SPI Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 136 8 6 Control a LED Matrix Interface an 8x8 LED matrix There are both single color and RGB LED matrixes Create an application that can control each individual LED in the matrix To control the matrix it is suggested to have a timer interrupt that updates the LED matrix in a multiplexed way i e one columns or one row at a time The frequency must typically be at least 100 Hz in order to avoid flickering The timer interrupt function can get information about which LEDs to turn on off from a 64 bit array i e a vector of 8 bytes In case of an RGB matrix three such bit arrays are needed one for each color As a start create an application that updates the 64 LEDs so
131. ine LED1 PORT PORTO define LED1 PIN 2 define LED ON 0 Low output turn LED on define LED OFF 1 High output turn LED off Create define for simpler access of push button define SW2 PIN 5 Initialize pins to be inputs and outputs set outputs to defined states winta t ledState enter forever loop while 1 Check if push button is pressed input is low if LPC GPIO1 gt DATA amp 1 lt lt SW2 PIN 0 ledstate LED ON else ledState LED OFF Control LED GPIOSetValue LED1 PORT LED1 PIN ledState There are many things that can be done to create macro defines to get a better abstraction structure of the program above First the push button states pressed not pressed can have constants defined The LPC_GPIO1 gt DATA register can be defined as define SW2 DATAPORT LPC GPIO1 gt DATA It is also possible to create a general SW2 VALUE macro where the pin state is returned Update the code above according to these principles more general and better structured code It is also possible to create a general function GPlOGetValue just like GPlOSetValue This will be an exercise in the next experiment Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 1 3 2 Lab 2b GPIO and Bit Masking As presented in Lab 1b there is hardware support in the GPIO peripheral block for accessing selected bits as opposed to accessing all of them This is described in the
132. ing techniques e microcontrollers and how they interact with their environment Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide e electronic design in general e how to work with a breadboard e how to solder It is assumed that you know how to program in C You do not have to be an experienced user but at least know about the basics If not the Internet is full of ANSI C tutorials A good start can be https en wikibooks org wiki C_Programming The program development environment also called Integrated Development Environment IDE for short used is the LPCXpresso IDE which is a Eclipse based IDE a GNU C compiler linker libraries and an enhanced GDB debugger For more information see 5 3 1 Embedded Systems Programming Embedded systems programming is truly multi disciplinary An engineer must master many knowledge areas in order to do a good job There are at least five of these areas 1 General programming knowledge C algorithms and data structures understanding the development environment debugging techniques safe programming styles version handling documentation etc 2 Knowledge about programming close to the hardware Firmware programming interrupts memory mapped accesses for control registers types of memories etc 3 Knowledge about the specific hardware details about microcontroller used incl all peripherals I O communication interfaces etc 4 Application p
133. into an end product 2 4 Code Read Protection The LPC1000 family has a Code Read Protection function specifically CRP3 see datasheet for details that if enabled will make the microcontroller impossible to reprogram unless the user program has implemented such functionality Note that Embedded Artists does not replace LPC1000 family chip where the chip has CRP3 enabled It s the user s responsibility to not invoke this mode by accident 25 CE Assessment The LPCXpresso Experiment Kit is CE marked See separate CE Declaration of Conformity document The LPCXpresso Experiment Kit is a class A product In a domestic environment this product may cause radio interference in which case the user may be required to take adequate measures EMC emission test has been performed on the LPCXpresso Experiment Kit Standard interfaces like Ethernet USB serial have been in use Connecting other devices to the product via the general expansion connectors may alter EMC emission It is the user s responsibility to make sure EMC emission limits are not exceeded when connecting other devices to the general expansion connectors of the LPCXpresso Experiment Kit Due to the nature of the LPCXpresso Experiment Kit an evaluation board not for integration into an end product fast transient immunity tests and conducted radio frequency immunity tests have not been executed Externally connected cables are assumed to be less than 3 meters The general expans
134. ion connectors where internal signals are made available do not have any other ESD protection than from the chip themselves Observe ESD precaution 2 6 Other Products from Embedded Artists Embedded Artists have a broad range of LPC1000 2000 3000 4000 based boards that are very low cost and developed for prototyping development as well as for OEM applications Modifications for OEM applications can be done easily even for modest production volumes Contact Embedded Artists for further information about design and production services 2 6 1 Design and Production Services Embedded Artists provide design services for custom designs either completely new or modification to existing boards Specific peripherals and I O can be added easily to different designs for example Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide communication interfaces specific analog or digital I O and power supplies Embedded Artists has a broad and long experience in designing industrial electronics in general and with NXP s LPC1000 2000 3000 4000 microcontroller families in specific Our competence also includes wireless and wired communication for embedded systems For example IEEE802 11b g WLAN Bluetooth ZigBee ISM RF Ethernet CAN RS485 and Fieldbuses 2 6 2 OEM Evaluation QuickStart Boards and Kits Visit Embedded Artists home page www EmbeddedArtists com for information about other OEM Evaluati
135. is then typically set in a status register The subroutine below implements the principles outlined above Study the code and read in the user s manual to understand how the code works and in what way the timer is used f RKCKCKCK kk KK KK KK kk kk kk AK AA X kk K kA X k kk kk KC kk Ck Ck kCk ck k kc k ck k ck ck ck kc k ck k ck ck kk ck ck k ck ck kk ko Function name delayMS Descriptions Start the timer delay in milliseconds until elapsed 32 bit timer 0 is used Parameters Delay value in millisecond Returned value None KK KK KK KK k kk kk ck ck kc kc k ck kk ck kk k ck k kc k ck kc k ck kk ck ck kc kc k kk ck ck k ck ck ck k ck ck kk ck ck k kc k kk ck ck k kc kc k ck kck ck k ck k kk void delayMS uint32 t delayInMs setup timer 0 for delay LPC SYSCON gt SYSAHBCLKCTRL 1 lt lt 9 Enable 32 bit timer 0 clock LPC TMRJ2B0 gt TCR 0x02 reset timer LPC TMR32B0 gt PR 0x00 set prescaler to zero SystemCoreClock LPC SYSCON gt SYSAHBCLKDIV 48000000 gt Timer clock is 48MHz LPC TMR32B0 2MRO delayInMs SystemCoreClock LPC SYSCON gt SYSAHBCLKDIV 1000 LPC TMR32B0 gt IR Oxff reset all interrupts not needed LPC TMR32B0 gt MCR 0x04 stop timer on match LPC TMR32BO gt TCR 0x01 start timer wait until delay time has elapsed while LPC TMR32B0 gt TCR amp 0x01 For how long can the function above delay Create a fu
136. ists AB U 1 C1 O O OP O O O O ieia 0 0 OO Of O O 99 c E LED LED3 cc LED10 LED4 LED6 LED5 R210 mo R220 mc R4Om O R8O mul jam O R260 m0 Ro8O jam O R27 0 FO Ri20 O Ow jOR5 Om OR23 sgO mori 9 HHBBBHBH D OT OC LPCXpresso Experiment Kit User s Guide 7 Experiments This chapter contains the experiments It is recommended to follow the order of the experiments It has been compiled to give you the best learning curve There are multiple small steps in the experiments and they build upon each other Where appropriate some theoretical discussions have been added All experiments are based around the LPCXpresso LPC111x board unless otherwise noted Both LPCXpresso LPC1115 and LPC1114 boards are ok to use Some of the experiments Ethernet and USB at the end of the chapter will use the LPCXpresso LPC1769 board There is also a separate section describing the differences between using the LPCXpresso LPC1115 LPC1114 and the LPC1114 in DIL28 package It is recommended to download the LPC111x User s Manual from NXP and have it handy This document is also called UM10398 Many references into this document will be done and this is also part of the learning how to find the relevant information in a user s manual It is also recommended to have the schematic available It is further recommended to start working with the breadboard as opposed to start
137. just one byte instructions send to the 25LC080 chip Note that the SSEL CS signal must be brought high after the transmissions in order for the instructions to be actually executed The WREN instruction is shown in the picture below The WRDI instruction is similar and not shown FIGURE 2 4 WRITE ENABLE SEQUENCE WREN o 1 High Impedance Figure 53 25LC080 Write Enable Sequence There is also a status register It can be read at any time even during a write operation It is possible to check the status of a write operation and detect when it is ready It is also possible to read the write enable latch state as well as controlling write protection of blocks of the memory region Read the datasheet for details Study the code below It contains an initial framework for reading and writing to the 25L C080 chip SPI E2PROM command set define INST WREN 0x06 MSB A8 is set to 0 simplifying test define INST WRDI 0x04 define INST RDSR 0x05 define INST WRSR 0x01 define INST READ 0x03 define INST WRITE 0x02 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide RDSR status bit definition define RDSR RDY 0x01 define RDSR WEN 0x02 define SSEL GPIO 8 PORT PORT2 define SSEL GPIO 8 PIN 0 define SSEL HIGH 1 define SSEL LOW 0 KKK KKK KKK KK KK KK KK KK K K AAA Z KK K KAZ A KK KK KK KK AK K AAA KK KK KK KK KK KK KK KK KK KK kk Function name spiE2PROMread Descripti
138. k k ck kk Ck kk ck ck kk ck ck k ck ck k kc k ck k kc k ck kk ck kk k ck k ck ck k ck k kA kckck ck kck ck kk k kk void playNote uintl6 t notelnUs uintl6 t durationMs stopPWM initPWM noteInUs Setup to generate a PWM signal with cycle time note updatePWM 0 50 Update MATO to generate a 50 duty cycle startPWM delayMS durationMs Wait for the duration of the tone updatePWM 0 100 Turn the signal off signal constant high We start with a duty cycle of 50 Half time the buffer is on and the other half it is off It is actually possible to adjust the volume by varying the duty cycle The shorter time the buzzer is on the lower the volume is It is not the duty cycle that controls the tone It is the cycle time that controls this Recreate the breadboard setup from Figure 17 with one change Connect the buzzer control to signal GPIO 28 PWM instead of to signal GPIO BUZZ That way you can create a PWM signal with the functions that we created in the previous experiments Create an application that can play a song In a song notes can have different duration and there can be pauses between notes Design a system where you can specify songs in a string Then let the application decode this string and play the song 7 11 3 Lab 10c Control a Servo Motor In order to complete this experiment you need an analog control servo sometimes just called an RC servo and also an external power supply 4 6 vo
139. k k k k k Ck k k Ck k k k Ck k ck ck Static void eonvertCordinateToDegree uint9 t pBuf dne pDegree int len int index 0 int sum int deg int min int div int pow Ne Ne e Ne F OOo O O I b Ne for index len index gt 0 index if pBut index 4d div 1 continues sum pow pBuf index amp Ox0F if index gt 0 pow 10 div 10 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 120 div pow div deg sum div 100 min sum deg div 100 convert to decimal minutes min min 100 60 pDegree deg div 100 min if div gt 10000 normalize minutes to 6 decimal places pDegree div 10000 KKK KKK KKK KK K KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK 2 EuSsctloOms name parseUTC Descriptions Extracts the UTC time string in hhmmss sss XR ignoring the sss part and stores the result TU as a string in data utcTime parameters The buffer Returned value None KCKCKCKCKCKCKCKCK Ck Ck Ck kok Ck K Ck 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 kk k k Ck k k Ck k k Ck Ck k Ck ck static void parseUTC uints t ppBuf int index 0 parse utc hhmmss sss while ppBuf END OF MESSAGE if ppBuf yt Y pointToNextValue ppBuf break reached end of
140. k k kk KK Ck ck k kk kCkCkCk ck k Ck kCkCk Ck ck k kk kCk K kck kk KK K ck ck k kk Ck Ck kck k kk kCkckckck k ck k kckckck ck kk kk kk void pca9532 setLeds uintl16 t ledOnMask uintl6 t ledOffMask turn off leds ledStateShadow amp ledOffMask amp Oxffff ledOnMask has priority over ledoffMask ledStateShadow ledOnMask turn off blinking 7 blinkOShadow amp ledOffMask amp Oxffff Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide blinklShadow amp ledOffMask amp Oxffff setLeds Add functionality to control the PWM generators and functions to direct the PWM signals to specific pins Place the PCA9532 related code in file pca9532 c Create an application that performs a running one pattern on the eight connect LEDs Also create a program that can demonstrate dimming on the LEDs with the help of the PWM generators on the PCA9532 chip Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 100 7 15 Work with a Serial Bus UART In this experiment you will learn how to work with the Universal Asynchronous Receiver Transmitter or UART for short The term asynchronous refers to the fact that no explicit clock signal is transmitted The transmitter and receiver must agree beforehand on the bit rate i e how long time a transmitted bit shall take The idle state no transmission is a high signal Transmis
141. k with the Serial Peripheral Interface Bus or SPI bus for short It is a synchronous bus meaning that there is an explicit clock signal SPI builds on the master slave concept where one unit is a master and controls the communication The other end is the slave Four signals are needed for communication in both directions e SCLK serial clock driven from the master e MOSI data signal Master Output Slave Input driven from the master e MISO data signal Master Input Slave Output driven from the slave e SSEL or SS Slave Select driven from the master Many slaves can co exist if there are many slave select SSEL signals see picture below Master Figure 46 SPI Master and many Slaves The protocol defines four different modes 0 3 which have to do with which SCLK edge the data is clocked on rising or falling and the SCLK inactive state high or low Mode 0 will work fine for the SPI experiments in this section The master and slave connects the shift registers in a ring see picture below The shift registers are 8 bits long in the picture but in principle they can be other lengths also 12 bit and 16 bit lengths are also commonly used The most significant bit MSB is typically sent first on the MOSI MISO data lines Note that this structure results in that the master receives one byte from the slave when one byte is sent Master Slave 1 oja 2 s s s e 7 oj 2 s s s e 7 Figure 47 SPI Master and Sla
142. l the input high It is important to check the datasheet how strong the pull up resistors are so that the external signal can pull the pin low and vice versa that the built in pull up resistor can pull an inactive signal high The series resistor is for protection if the supposedly input pin is an output If that output is pulled high by the microcontroller and the push button is pressed the output could be damaged due to excessive current flowing to ground if a series resistor does not limit the current The situation is not an imaginary Situation Suppose there already is an application running on the microcontroller from a previous experiment That application might very well use the pin as an output Before the correct application has been downloaded the damaged can happen Therefore it is a good practice to add series resistors to all signals that can drive a microcontroller pin the key in this case which can drive the signal low Pin PIO1 5 is controlled by register IOCON_PIO1_5 check chapter 7 LPC1100 LPC1100C LPC1100L series I O configuration in the LPC111x user s manual In the description for this register we can see that there are three alternative pin functions PIO1 5 a general purpose input output port 1 pin 5 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide RIS a control output signal for peripheral block UART CT32B0 CAPO an input signal to 32 bit timer 0 By defa
143. lexibility and nicer looking interfaces 8 9 Retrieve Information from Web Servers A web browser used the HTTP communication protocol on top of TCP IP to retrieve information from web servers More specifically it s the GET request that is used Create an application that connects to a web server typically port 80 and send a HTTP GET request and displays the information in a suitable way for example on the console or a display When the data is received it must be interpreted in order to extract the usable information A typical setup can be a system with a web server that resents the analog values of the two analog inputs on a HTML page If another embedded system shall also retrieve this information it must interpret the HTML data and extract the correct information i e the analog values 8 10 USB Mouse Emulation Create a USB device application that emulates a USB mouse You need to implement a USB HID device HID stands for Human Interface Device which is exactly what a mouse is Study USB related documentation to find out more about this The joystick switches can be used to move the mouse position and in the end move the cursor pointer on a PC screen Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 137 0 11 Registry in E2PROM Create a so called registry which is a non volatile storage that can store values connected to so called keys Non volatile storage is easily created by u
144. ll be of different brands we gilt dini Breadboard Digikey 438 1109 ND Mouser 854 BB400T http en wikipedia org wiki Breadboard Cables male to male Prototype cables can be ordered from Embedded Artists web shop in 50 pcs http en wikipedia org packages EA ACC 017 wiki Jump_wire Connectors for There is another pair of LPCXpresso board headers that looks very similar This pair of connectors has longer pins The other pair has shorter pins 11mm long pins This pair of connectors shall be soldered to an LPCXpresso board to make it experiment friendly make it simple to connect cables to the pins There is no distributor equivalent for this component Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB Tantal capacitor C1 C2 C12 22uF http en wikipedia org wiki Tantalum_capacitor Ceramic capacitor C3 C4 18pF http en wikipedia org wiki Ceramic capacitor Ceramic capacitor C5 C6 C7 C8 C9 C13 100nF http en wikipedia org wiki Ceramic_capacitor Ceramic capacitor C10 C11 100nF SMT http en wikipedia org wiki Ceramic_capacitor This component is polarized One of the two pins is longer than the other This is the positive side There is also a small plus sign printed on the components on the long pin side AVX TAP226K010SCS Digikey 478 1874 ND Mouser 581 TAP226K010SCS The printed nu
145. llustrates the GPS module mounted in RF module interface connector J15 The current consumption is low for the module n the region of a couple of mA so the shorting jumper can be placed in position 1 2 on J12 right position in picture below TOEF E E c LE UNDC AS mm an AC Embedded Figure 65 GPS Module Mounted in J15 The module outputs a number of different messages in the NMEA 0183 format htto en wikipedia org wiki NMEA_0183 Each message starts with a dollar sign and ends with a checksum These are some examples taken from the manufacturer s data sheet SCPGGA 064951 000 2207 1256 N 12016 4439 5b 1 90 0 95 39 9 M 17 98 M Gb S GPGSA A 0 29 21 26 15 18 09 00 10 442222709912 s11 00 95GPGSV 3 1 09 29 36 029 42 21 406 314 43 26 44 020 423 15 21 321 39 7D SGPRMC 064951 000 A 2307 1256 N 12016 4438 E 0 03 165 48 260406 3 05 W A 2C The exact meaning of each of them is found in the data sheet but here we will focus on the one starting with GPGCA as it contains the time and location information Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 118 GPGGA 064951 000 2307 1256 N 12016 4438 E 1 8 0 95 39 9 M 17 8 M 65 Table 2 GGA Data Format Message EGI GGA protocol header E W Indicator E amp East or W west pacar J Satellites Used 8 A Range Oto 14 HDOP 095 Horizontal isi Antenna Altitude above below
146. lt DC about 1 ampere These two parts are not included in the LPCXpresso Experiment kit but can easily be bought from electronic components distributors and RC Radio Control hobby suppliers Servos are used in many different products The smaller ones we focus on in this experiment are found in toys For example in small robots rc cars rc airplanes etc There is no unified color scheme for all servos for the three wires you connect to power 5V ground and control signal PWM signal Check the datasheet of the servo that you will be using so you connect to the correct wires Toms Pra Figure 43 Typical Servo There are many different types and models but in this experiment we will only focus on how to control the position of the servo which is done via a PWM signal The cycle period can vary over a range but 20 ms is an average value that will work on most servos The position of the servo is controlled by the on time of the PWM signal 1 5 ms will place the servo in the middle neutral position Increasing the on time to 2 ms will move the position to the right most position Decreasing the on time to 1 ms will move the position to the left most position Note that the corner values can differ between servos Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Some have 1 25 1 75 ms as the range Others have 0 75 to 2 25 ms Note that it is not the actual duty cycle that controls the positi
147. lution is to connect a 330 ohm pull up resistor between signal PIOO 7 and 3 3V 7 3 4 Lab 2d Toggling LED In this experiment we will introduce a state Pressing the push button shall turn the LED on Pressing again will turn the LED off Another way of expressing it is that the LED is toggled every time the push button is pressed The structure of the program is outlined below When the push button first is pressed the LED is toggled Check the current state of the LED and inverse it The recommended structure for this is to Store the LED state in a separate variable After having toggled the LED the program must wait until the push button has been released If this last step is omitted the LED would constantly toggle at a high rate as long as the push button is pressed That would not be a desirable solution since the LED can be in any state when the push button is finally released declare variables uint8 t stateLED Initialize pins to be inputs and outputs set outputs to defined states enter forever loop while 1 check if push button is pressed if toggle LED wait until push button is released while You will probably notice that the LED will toggle a little more than expected For example when releasing the push button sometimes the LED will not change state This is because of contact bounce inside the push button The microcontroller is so fast so it will detect multiple presses
148. ly the number range they can hold The original C standard was a little vague on the number of bits different variable types have It is specified as at least X number of bits and there is a specified order between different types However in embedded programming the exact number of bits is important to keep track of Therefore it is common to have an include file that have created specified new variable types with the number of bits exactly specified We will use this setup in all experiments Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Include a file called type h in all program files The main content of the file is presented below if defined GNUO 9 finclude lt stdint h gt else exact width signed integer types typedef Signed epa ONE typedef Signed short ane abide lb E typedef signed EEE gt EP typedef signed into intoa t exact width unsigned integer types typedef unsigned enc mM typedef unsigned short duae lala dE ie typedef unsigned mene typedef unsigned untod uint64d t fendif GNUC__ fitnder NULU define NULL void 59105 endif ifndef FALSE define FALSE 0 endif ifndef TRUE define TRUE 1 denda As seen there are four signed and four unsigned variable types of length 1 2 4 or 8 bytes 8 16 32 or 64 bits The file also declares the commonly used constants NULL FALSE and TRUE Code becomes much more portable between differe
149. mbers on this component is 180 This is not a polarized component Murata RPE5C2A180J2P1Z03B Digikey 490 3632 ND Mouser 81 RPE5CA180J2P1Z03B The printed numbers on this component is 104 This is not a polarized component Kemet C320C104K5R5TA Digikey 399 4264 ND Mouser 80 C320C104K5R This is a Surface mounted component and can only be soldered to the pcb i e not used on the bread board This is not a polarized component Murata GRM21BR71E104KA01L Digikey 490 1673 1 ND Mouser 81 GRM40X104K25L LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB Schottky diode D1 D2 1N5817 http en wikipedia org wiki Semiconductor_diode http en wikipedia org wiki Schottky_diode Stand offs H1 H2 H3 H4 Power jack J1 Connectors for LPCXpresso board J2 Debug connector J3 This component is polarized There is a ring on one pin side of the components upper side in the picture This is the cathode of the diode The other side bottom side is the anode Diodes Inc 1N5817 T Digikey 1N5817DICT ND Mouser 621 1N5817 These stand offs are mounted in each corner of the pcb AVC BS 135 Any standard stand off for 4mm holes will work This component and can only be soldered to the pcb i e not used on the bread board CUI Inc PJ 102A Digikey CP 102A ND There is another pair of headers that looks very similar
150. me for one call divide this LED on time with one million Place the function in file gpio c 7 3 3 Lab 2c Logic between inputs and output In this experiment we will introduce logic between the input push buttons and the output a LED and a buzzer Let s begin with connecting two push buttons SW2 which we already have and SW3 According to Figure 11 and Figure 12 SW3 is connected to signal GPIO_16 KEY which in turn is connected to PIO1 4 Figure 13 below illustrates how the connection can be done on the breadboard Create a program that reads the two push buttons and turn on the LED only when both are pressed simultaneous Then change the logic so that the LED is on if only one of the push buttons is pressed but not both The program structure will be the same as in Lab 2a and 2b a forever loop Read both inputs and then calculate the output value and output it Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide U1 LPCXpresso board JCM Pin 8 SSEL eeecee eeeee56e PIOO_2 o0 09090 99029 oe De 4344 1 T H 23920 oa Made with 3 Fritzing org Figure 14 Breadboard Connections for SW2 SW3 and LED Another output device besides a LED is a buzzer A buzzer outputs a single frequency tone when driving current through it A PNP transistor is controlling the current through the buzzer Pulling the base of the transistor low will enable the current through the transistor
151. means 0 if LPC GPIOI FIOPIN amp IUL lt lt 31 0 InReport 0x04 select pressed means 0 Lf OLPC GBIOU gt BIOBIN 1 lt lt 3 0 InReport 0x08 right pressed means 0 if UPC GPIOZ EIOPIN 1 lt lt 7 0 InReport 0x10 down pressed means 0 Set HID Output Report lt OutReport 27 void SetOutReport void static unsigned long led mask d lt lt c IS 17 19915 19516 143 qe3 14208 12297 12 int i for i 0 i lt LED NUM i if OutReport amp 1 lt lt i Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 127 if i i 5 BPC GPIO2 gt FIOPIN amp Led mask Iil else LPC GPIOU gt FIOPIN Lled mask i else if i 4X 5 LPC GPIO2 SFIOPIN led maskIlxl else LPC GPIOD FIOPIN led maski Modify the program to use the 7 segment display to show the hexadecimal value from the PC application Modify the program to read the state of the quadrature encoder to change the value sent to the PC instead of using buttons 7 18 2 Lab 17b USB Device Mouse HID This experiment uses the USB HID class but this time the USB device will act as a computer mouse The buttons on the experiment board will control the mouse pointer on the PC This experiment is based on the code examples that are delivered with the LPCXpresso IDE The code is structured very differently none of the code from the previous exercise
152. mer interrupt before exiting ISR KKK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name main Descriptions The main function Parameters None Returned value None KK Ck A K AA KK KK KK KK KK K KAZ KK KK K AA KK KK KK KK KK KKK KK kCkc kc kck kk kCk KK KK kc kckck k ck kk void main void initialize GPIO as needed setup 32 bit timer 41 to generate continuous interrupts every 200 ms 5 Hz enable 32 bit timer 1 interrupt NVIC EnableIRQ TIMER 32 1 IRQn enter forever loop let interrupt handle processing while 1 Now expand the functionality of the program and design a program that flash with the LED 50 ms milli seconds on 150 ms off 50 ms on and finally and 750 ms off Continuously repeat this 1000 ms cycle The suggested program structure is to set the timer interrupt rate high for example 1000 Hz That is 1 ms between every interrupt Check which state the LED should have inside the timer ISR Define Interrupt Service Routine for 32 bit timer 1 void TIMER32 1 IROHandler void name of function is predefined increment millisecond counter msCnt t keep counter at one second resolution if msCnt gt 1000 msCnt 0 set LED state based on millisecond counter TE 2x2 set LED else if set LED etc clear timer interrupt
153. mini B connector J17 Pin list 1x6 J18 LEDs LED1 LED8 http en wikipedia org wiki Led This component and can only be soldered to the pcb i e not used on the bread board Sullins NPPN101BFCN RC Digikey S5751 10 ND This component and can only be soldered to the pcb i e not used on the bread board Pin 1 is in the top upper left corner in the picture Sullins SBH11 PBPC D07 ST BK Digikey S9170 ND This component and can only be soldered to the pcb i e not used on the bread board Hirose UX60 MB 5ST Digikey H2959CT ND Mouser 798 UX60 MB 5ST Sullins PECOGSAAN Digikey S1012E 06 ND This component is polarized One of the two pins is longer than the other This is the positive side the anode There is also a small cut on the side of the plastic package This is on the short pin side which is the negative side the cathode Any 5mm LED with V around 1 7V and 150mcd at 20mA current will work for example Digikey 1080 1136 ND LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB RGB LED LED10 http en wikipedia org wiki Led f sigment LED dual digit LED9 http en wikipedia org wiki 7 segment_display LEDs LED11 LED18 SMT http en wikipedia org wiki Led This component is polarized There is a small cut on one side of the plastic package In the component picture to the left the cut is on the left side of the package
154. mport archived projects zip 4 Copy projects into workspace C3 Import exisiting projects resso forum gug Import project s from XML Description 73 Import files into 4 J Export projects to archive zip Export projects and references to archive g Smart Import wizard C Build and Settings Figure 76 LPCXpresso IDE Import Archived Project Window All projects are now imported Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 141 9 2 Working with a Project and Compiling Click to select the project to work with Note that there are several projects in the workspace Browse and edit the project files These are typically found under the src sub directly The main window to the right in the LPCXpresso window is a source code editor Build and clean the project from the Quickstart menu Start here see picture below When compiling the console window in the lower right corner of the LPCXpresso Window will give information about the compile and link process When the project compiles and links without any errors it is possible to move to the next step next section and download the code to the LPC111x and begin the debug session ELIT cO X File Edit Navigate Search Project Run Window Help Div e459G E M iu 25 C P Bi A Ev BY F ES X Develop amp 9 qS8 9 9 io o Project Ex 3 1 Core Regi
155. nction for microsecond delays i e delayUS Let the function check so that there is no overflow in time resolution The MRO register has 32 bit resolution Verify that the functions work correctly with a previous experiment for example Lab 7b Place the timer related functions in file delay c This file already has delay functions Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 11 PWM via a Timer In previous experiment PWM signals have been generated via software In this experiment you will learn how to work with a timer to generate PWM signals via hardware It will free up the microcontroller for other tasks since the hardware operates without continuous software control once initialized In section 7 7 Pulse Width Modulation the principles for a PWM signal were presented The signal has a cycle period D frequency 1 D and a duty cycle d D which is the fraction of the cycle the signals is high 0 1 0 100 Have a look in chapter 18 16 bit counter timer CT16B0 1 in the LPC111x user s manual for a description of the how the 16 bit timers works Note that chapter 19 describes the same timer for the LPC1115 the XL device family but for our purposes the timers are identical in the LPC111x family From earlier experiments we know that a timer can be quite complicated since it can be used for many different functions The principle to use a timer to generate a PWM signal is as follows 1
156. nd File wizards Import and Export g 3 Import archived projects zip T Import exisiting projects Ouickstart 23 X Variables 96 Breakpoint o Page 147 LPCXpresso is fully activated Welcome to LPCXpresso The software is now fully activated and can be used for production LPCXpresso can be used to generate and download applications containing up to 128KB of code into an LPC target powered by Aicode red Getting Started Please read the getting started guide for step by step instructions to build your first LPCXpresso project LPCXpresso Getting Started Guide LPCXpresso Resources Check the LPCXpresso Support page for new LPCXpresso software releases more example projects and announcements Visit www nxp com Ipcxpresso support LPCXpresso Forum The LPCXpresso Forum community is exclusively built for LPCXpresso users and is an invaluable resource for getting help and advice on use of the LPCXpresso tools and boards So get connected and join the LPCXpresso community To view the forum and to register so that you can post visit www nxp com Ipcxpresso forum General Information x Visit the NXP LPCXpresso website For information on upgrades etc visit the Code Red Technologies LPCXpresso website Visit the Embedded Artists LPCXpresso website y Ipcxpresso 3 6 pages registered htm gt e n C Build BLDC Sensored x gt t Problems j Memory Red Trace Preview 4 Search
157. ng etc It can be something very small or a big system with remote nodes communication wirelessly and presenting information on the Internet 8 18 Control a Robot Find a suitable mechanical platform and let the LPC111x control the robot hardware 8 19 RS 485 Network Create an RS 485 network and define a protocol for reliable communication for example a token passing protocol 8 20 Interface an FPGA CPLD Chip Create a project that interface a programmable hardware chip FPGA or CPLD There are many small breakout boards ion the market with these kinds of chips Implement some kind of hardware in the programmable chip and then let the microcontroller control this functionality It can be like an additional peripheral to the microcontroller 8 21 Analog Electronic Experiments This is more than just one individual project idea The experiments and kit content address digital electronics There is a whole world of analog electronic also including the interface between the analog world and the digital world Create own experiments to learn areas of interest for example e How to use a comparator to interface an analog signal to a digital input e How to adjust the range of an analog signal before feeding it to an ADC Analog to Digital Converter both gain and offset e How to apply low pass filtering before sampling an analog signal What are the theoretical requirements and practical implications e How to create an analog signal v
158. nt compilers if a common include file like this is used It also becomes more readable 1 2 2 Lab 1b GPIO and Bit Masking There is hardware support in the GPIO peripheral block for accessing selected bits as opposed to accessing all of them This is described in the LPC111x user s manual chapter 12 4 1 Write read data operations In short the GPIOxDATA register can be accessed on many different addresses The address used to access the register determines which bit s that is are accessed Below is a copy of a function from NXP s driver library for the LPC111x As seen it is a general function for manipulating any GPIO output any port any pin The array named MASKED ACCESS is used to get the correct access address to the GPIOxDATA register given which bit s to access Note that the function below only allows one bit at a time to be accessed 1 bitPosi is used to index into array MASKED ACCESS It is possible to create more general access functions where several pins can be controlled simultaneous for example MASKED ACCESS 1 bitPosi1 1 bitPosi2 1 bitPosi3 KKK KKK Ck KK KA AK kA X KAZ K kA AK AA X KAZ KC kk AK AA X KAZ KK kk kk k kA k kA ck ck k ck ck ck k ck ck k ck ck ck k ck ck ko kc ko Function name GPIOSetValue Descriptions Set clear a bitvalue in a specific bit position do in GPIO portX X is the port number c parameters port num bit position bit value R
159. nted components Just search with your favorite search engine P 507 qnn 350000000000000 TIFE SEE O non gm a N dz I NNI peseeuscerssed Figure 56 Surface Mounted Components on the LPCXpresso Experiment Kit PCB Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 14 2 Lab 13b Read LM75 Temperature Sensor In this experiment a temperature sensor LM75 shall be sampled and the temperature presented It is essential to study the LM75 datasheet before writing any code The LM75 has a simple interface and luckily no register initialization is needed before it is possible to read the temperature It is just a matter of reading from the correct register The code below presents two functions One for reading the temperature and one for writing in configuration registers Complete the last statement in function 175a readTemp to calculate the correct temperature Create a semihosting application that samples the temperature every third second and prints the result on the console include i2c h define LM75B I2C ADDR 0x90 define LM75B REG TEMP 0x00 define LM75B REG CMD 0x01 KKK KKK KKK KK KK KKK KKK KK K AA KK KK K KAZ KK KK K AAA A KK K K AXA AK AK KK KK KK KK KK KK KKK KK KK kk Description T Read temperature register of LM75B Params None Returns Temperature I00 in integer format KK Ck kCkCkCk k k kk kCkCk Ck k kk KK Ck ck k kk kCk Ck ck
160. o the default interrupt handler IntDefaultHandler The exact same name of the routines must be used Below is an example of a custom ISR for 16 bit timer 0 My own ISR for 16 bit timer 0 void TIMER16 0 IROHandler void Service the interrupt and finish with clearing interrupt Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 13 1 Lab 12a Generate IRQ via GPIO In this experiment an interrupt will be generated from a GPIO input Rebuild the basic breadboard setup in Figure 13 on page 39 One LED controlled by PIOO_2 and one push button connected to PlO1 5 Let the push button input generate an interrupt on a falling edge pushing the key Toggle the LED every time the push button is pressed Study chapter 12 L PC111x LPC11Cxx General Purpose I O GPIO in the LPC111x user s manual Especially note the GPIO features listed below is an excerpt from user s manual e Each individual port pin can serve as an edge or level sensitive interrupt request e Interrupts can be configured on single falling or rising edges and on both edges e Level sensitive interrupt pins can be HIGH or LOW active Register GPIOnIE where n is the port number controls if a pin generates an interrupt or not If not it is said that the interrupt is masked Default is that all pin interrupts are masked inactive For active interrupts non masked pins register GPIOnIS controls if a pin generates ed
161. o complete Returned value None KK KKK k ck k kk kk ck ck kk k ck k kc k kk k ck KK k ck Ck ck kA X ck ck k kc k kk ck ck k kc k ck k ck ck kk ck ck k ck ck k ck ck ck k kckck ck kck kk kk void UARTSendString uintS t pstr uint8 t blocking KKK KKK KKK KK KK KKK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KKK KK KK KK KK KK kk Function name UARTSendBuffer Descriptions Send a number of bytes chars of data to UART 0 port xk parameters data to send number of bytes and if call is blocking Returned value None KK Ck kCkCkCkck kk Ck kCkCkCk ck kk KK KAZ KK A AK K kck KK KK KK KK KK AK K AAA KK KK kk kCk Ck ck ck k k ck kc kckck k ck kk kk kk void UARTSendButfetr uint8 t pBur uintle t length uintS t blocking Create an application that demonstrates receive and transmit circular buffers The receive overflow problem in the previous experiment can for example be handled to some extent if the buffers are large enough Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 112 7 16 Extra Work with RF module In this experiment you will learn how to work with radio modules Note that the breadboard cannot be used in these experiments The RF module connectors have 2 0 mm pitch as opposed to the 2 54 mm pitch found on breadboards Also note that the radio modules used in these experiments are not included and must be purchased separately The R
162. o control multiple signals especially if the signals have different frequencies The microcontroller is also fully occupied with generating the signals If other work is performed the PWM signals will be affected not correct duty cycle or frequency This is why it is typically simpler to let a timer generate the PWM signal without software intervention other than setup You will investigate this in more detail later on Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 8 Control an RGB LED In this experiment you will learn how to control an RGB LED Inside the package of the component there are three LEDs one red one green and one blue The common anode is connected to the 3 3V supply and series resistors for each LED will limits the current to suitable levels not irritating with matching lamination from each LED Note that the series resistor for the red LED is 1 5 kohm and 220 ohm for the blue and green LEDs Also note that the current levels are quite low compared to what a normal RGB LED would have RGB LED oJ1 SJ2 CLOSED OPEN LED10 KN IN KAP A al B CE m of un Flo e g I cu gLix als gLIS PIO 28 PWM Pi 239 PVVIV A PIC 30 PWM Figure 29 RGB LED LED10 on Schematic Page 4 The anode is connected to 3 3V as shown in Figure 29 The pcb has shorted jumper SJ1 while SJ2 is open There is an option to connect it to 5V instead but the currently used RGB LED
163. o disable an interrupt source disable 16 bit timer 0 interrupt NVIC DisableIRQ TIMER 16 0 IRQn Normally it is good system design practice to keep the execution time in the interrupts as short as possible The actions that are needed immediately are done in the interrupt service routine ISR Actions that can wait should be scheduled for later execution in the normal program flow If it is not possible to keep execution time in an ISR short nested interrupts can be used Nested interrupts means that an interrupt can interrupt another interrupt if it has higher priority Four priority levels 0 3 are supported in the NVIC hardware The lower the number is the higher the priority is Interrupts with the same priority cannot interrupt each other It is possible to set the priority of an interrupt like this set priority of specified interrupt IROn Type p priority 10 9 7 void NVIC S tPriority TIMER 16 0 TROn praossl OxOl Creating an ISR is very simple The ISR can be written entirely as a C routine Have a look in file cr startup lpc11 c tis found in the project s src sub directory Amongst other things this file contains declarations of the ISR s as seen below The functions are called SR handlers but that is just another name for the same thing an interrupt service routine ISR KR KKK KR KKK KKK KK KK KAZ AK kA X KAZ X KK AA X kk kk kk K kA Ck ck ck kc k ck k ck ck ck k ck ckck ck ck ck k ck ckck kk k k kk k
164. of Clean DemoApp Debug gt eer tT Ghat you can post visit www nxp com Ipcxpresso forum 3 Build clean project e Code Red Technologies LPCXpresso website Visit the Embedded Artists LPCXpresso website 3 Quick Settings v Project and File wizards El Console 23 I Problems Memory dil Red Trace Preview M E TFT 7 No consoles to display at this time E DebugandRun y Console window B Extras E tS DemoApp DemoApp NXP LPC11U14 201 C Import and Export Figure 77 LPCXpresso IDE Build Project Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 142 9 3 Debugging a Project and Downloading When the project compiles and links without any errors it is time to start debugging to download the code to the LPC111x and start executing Before starting to debug make sure the LPCXpresso board is connected via USB to the PC The code is downloaded to the board via this cable The LPCXpresso board consists of two parts one is the LPC111x processor and the other is the LPC Link side which is an embedded debug interface Click to select the project to work with Click on debug in the Quickstart menu Start here see picture below E enep Wome pe woe M o NEST File Edit Navigate Search Project Run Window Help we aw ged Bv vy Sv cxpresso pages registered htm v gt E PRESSO readm
165. oid uint8 t pattern uint8 t GPGGA while 1 uints t burilo00 Hinto ch 0 Hines t DEI int index 0 07 Retrieve the first byte if UARTGetChar amp ch continue look for SGPGGA header if ch t 57 4 continue Retrieve the next six bytes for index 0 index lt 6 index buf index UARTGetCharBlock Check if its Global Positioning System fixed Data If hasPattern Uinto 67 8but pattern 0 4 continue Retrieve the data from the GPS module for index 0 index 100 index buf index UARTGetCharBlock if buf index r buf index END OF MESSAGE break ptr amp buf 0 parse UTC time parseUTC amp ptr parse Latitude parseLatitude amp ptr break return amp data int main void Set LEDI LED8 pins as outputs Set SW2 SW3 pins as inputs initialize the UART to 9600bps 8N1 UARTInit 9600 printf unce I nWaiting for GBS datas Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 122 enter forever loop while 1 const gpsData pData GPSRetreiveData displayGpsData pData delayMS 1000 return 0 Base the program on the UART functionality developed in Lab14c and place the GPS related code into gps c and gps h Run the program to see the current time and latitude The latitude settings requires a
166. omponent is polarized MCP1700 330 1 pcs One side of the plastic U1 package is flat and the other side is rounded When mounting this component http en wikipedia org make sure it is turned wiki Low correctly dropout_regulator Microchip MCP1700 3302E TO Digikey MCP1700 3302E TO ND Mouser 579 MCP 1 700 3302E TO Microcontroller This component is polarized LPC1114FN28 1 pcs There is a cut in one end of U2 the plastic package on the short side This indicates where pin 1 is located When mounting this component make sure it is turned correctly NXP LPC1114FN28 102 Digikey LPC1114FN28 102 12 ND Mouser 771 LPC1114FN28 1021 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB Headers for U2 Shift register 74HC595 1 pcs U3 http en wikipedia org wiki Shift_register Temperature sensor MCP9701 1 pcs U4 SPI flash 25LC080 1 pcs U5 http en wikipedia org wiki Flash_memory This pair of connector headers can optionally be soldered to the pcb as a socket for U2 By adding these connectors headers it is possible to either mount the LPCXpresso board in J2 headers or mount U2 in these headers If J2 headers are mounted but these headers are not then it is not possible to mount U2 Sullins PPTC141LFBN RC Digikey S7012 ND This component is polarized There is a cut in one end of th
167. on QuickStart boards kits or contact your local distributor Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 3 LPCXpresso Experiment Kit The LPCXpresso Experiment Kit has been created as a guided tour to learn embedded programming with NXP s LPC1000 microcontroller family with Cortex M0 M3 cores from ARM The experiments can be performed on a breadboard for maximum flexibility and ease of use It is also possible to solder the components to a printed circuit board pcb and learn soldering at the same time Figure 1 illustrates the two ways of working with the kit To the left all components have been soldered to the pcb and the LPCXpresso board is mounted in a socket on the pcb To the right a bread board is used and wires connect directly between the bread board and the LPCXpresso board Note that the LPCXpresso board is not included in the normal LPCXpresso Experiment Kit 4 M Uh 11 ii z D s Ka DIT LA P sow v u e v 2 s Figure 1 Breadboard Experiments and Working with PCB The kit is based on the LPC1000 LPCXpresso evaluation boards which is a whole family of boards All experiments are based around the LPCXpresso LPC1115 1114 board unless otherwise noted The term LPC111x will be used for the rest of the document to indicate both LPC1115 and LPC1114 Some of the experiments Ethernet and USB related are based on the LPCXpresso LPC1769 board It i
168. on It is the on time For a given constant cycle period there is of course a direct relation between the on time and the duty cycle If the cycle period of 20 ms is chosen the duty cycle shall be varied between 5 10 and 7 5 represents the middle neutral position The updatePWM function must be updated to support 0 196 or even 0 0196 resolution 196 will be too coarse Also the PWM block clock prescaler must be set to 19 divide by 20 to handle the 20 ms period Center Right Left ary IU SUL 1 2 ms lt gt 20 ms K gt gt Figure 44 PWM Signal for Servo Control See breadboard setup below Note that an external power supply is needed to power the servo 4 6 volt is a typical suitable level for a servo but always check the datasheet for the specific servo that you Will be using If you have soldered the components to the pcb then there are three servo motor connectors J5 J6 and J8 see page 5 on the schematic U1 LPCXpresso board Connect servo motor cable assemblyto 3 pin male connector pin list on breadboard 4 usjjeg WWW je33eg VYW AAA Battery k AAA Battery Fritzing org Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Figure 45 Breadboard with Servo Motor Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 12 Work with a Serial Bus SPI In this experiment you will learn how to wor
169. ons This function will read bytes from the SPI E2PROM parameters address in memory region buffer pointer and block length Returned value None KCKCKCKCKCKCkCKCK k kok kok k k k k k k k Ck 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 k k Ck k k kk k k Ck k ck ck ck vold Spib2PROMread uintl6 t address uinte t pBuf uint32 t length uinte t but 3 pull SSEL CS low GPIOSetValue SSEL GPIO 8 PORT SSEL GPIO 8 PIN SSEL LOW output read command and address buf 0 INST READ buf 1 address gt gt 8 amp Oxff buf 2 address amp Oxff SSPOSend amp buf 0 3 read bytes from E2PROM SSPOReceive pBuf length pull SSEL CS high GPIOSetValue SSEL GPIO 8 PORT SSEL GPIO 8 PIN SSEL HIGH KKK KKK KKK KK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK k kk Function name SpiE2PROMwrite Descriptions This function will write bytes to the SPI E2PROM parameters address in memory region buffer pointer and block length Returned value None KCKCKCKCKCKCk Ck Ck Ck kok k k k k k k k k k k k k k k k Ck k k k k k Ck k k k k k void SpiEZPBOMwrite uintl6 t address ulpt9 t pBur uint32 t length uinte t but 3 3 Insert code here to break up large write operation into several page write operations Do not forget to add a 5ms delay after each page write operation pull SSEL CS low GPIOSetValue SSEL GPI
170. osting affects code execution performance severely Every time a data transfer takes place the execution of the program stops during the transfer The microcontroller cannot do anything useful whilst waiting on each transfer to complete The blocking time depends on the LPCXpresso IDE and the PC it executes on Do not use printf and Semihosting in time critical loops In the next lab a performance test will be carried out to get a feeling for the transfer rate Adding printf functionality to a small embedded system is a trade off between flexibility and code size The full implementation of printf is very large especially if floating point is supported NXP has created an application note that covers basic techniques to reduce the size of code Many things are covered along with a reduced size printf implementation that is supported in the LPCXPresso IDE The application note is named AN10963 Reducing code size for LPC11XX with LPCXpresso Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 1 5 2 Lab 4b Semihosting Performance Test In this experiment we will investigate the performance of the Semihosting functionality Expand the while 1 loop below to increment a loop counter and print the value if this counter every iteration in the loop Also add a 500ms delay in the loop and verify that the counter increments two times per second by observing the console window in the LPCXpresso IDE Include
171. p Debug For information on upgrades etc visit the Code Red Technologies LPCXpresso website d Clean DemoApp Debug x Visit the Embedded Artists LPCXpresso website 35 Debug DemoApp Debug QS Quick Settings v Project and File wizards S Import and Export E Console 23 NES Problems j Memory Hil Red Trace Preview No consoles to display at this time E Build and Settings amp Debug and Run O m 16 Download Page 0 at 00000C00 1024 bytes DemoApp NXP LPC11U14 201 Figure 88 LPCXpresso IDE Program Flashing in Progress In case flashing fails an error message like below will be displayed This is an indication that the debugger could not connect to the LPC111x The most common reason is that the microcontroller is in a low power mode where the debug connection is disabled Make sure the microcontroller is in ISP bootload mode and try again This is accomplished by pulling pin PIOO 1 low via 100 1000 ohm resistor to ground 02 Failed on connect Ee 07 Bad ACK returned from status wire error Figure 89 LPCXpresso IDE Program Failing to Flash Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 150 There is an alternative way of initiating the program download process From the workspace right click on the axf or bin file found under the Debug subdirectory Then select Binary Utility and Program Flash Develop
172. p address you entered in tcpip h EN C Windows system32 cmd exe ciN ping 192 168 5 2H8H Pinging 192 168 5 2H8 with 32 bytes of data Reply from 192 168 5 208 bytes 32 timetims TTL 64 Reply from 172 168 5 2H8B bytes 32 timeszims TTL 64 Reply from 192 168 5 208 bytes 32 time lt ims TTL 64 Reply from 172 168 5 28H bytes 32 time lt ims TTL 64 Ping statistics for 192 168 5 268 Packets Sent 4 Received 4 Lost H Hx loss gt Approximate round trip times in milli seconds Minimum Hms Maximum Ams Average Pms CIN Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 130 If you get replies as shown above everything is working If not then go back to ethmac h and tcpip h and verify that the addresses you have selected are correct Now open a web browser and enter your selected IP number in the address field You should get a page similar to this Hello from your Experiment Board This is a dynamic website hosted by the embedded Webserver easy WEB Hardware PCXpresso Experiment Kit from Embedded Artists Embedded EMAC Ethernet Controller Variable value 0512 decimal value from val 256 512 768 1024 e Page Count 7 Figure 71 Web Page Screenshot The page is continuously updated page count is increasing and the colored bar is changing value This is accomplished by having a static web page with a couple of fields that are updated before the page is
173. pending on chip version C or D check chip package marking for details the maximum number of bytes to write is 16 or 32 Note that all bytes must be in the same page Physical page boundaries start at addresses that are integer multiples of the page buffer size 16 or 32 bytes It is for example allowed to write 7 bytes from address 4 to 10 It is not allowed to write 7 bytes from address 27 to 33 since a page boundary will then be crossed true for both 16 and 32 byte page versions Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide FIGURE 2 3 PAGE WRITE SEQUENCE 2 3 4 5 6 7 8 9 10 11 21 22 23 24 25 26 27 28 29 30 31 Instruction 16 bit Address Data Byte 1 po c of 1X6 2X AKORTAEKSKANSK2N KD CD 77 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 AuHdulliuiuiL Data Byte 2 Data Byte 3 Data Byte n 16 32 max gt 4748454 443424 19 Figure 52 25LC080 Page Write Sequence The 25LC080 chip contains a write enable latch This latch must be set before any write operations are allowed The WREN instruction sets the latch i e enable a write operation The WRDI operation resets the latch i e block write operations Note that the write enable bit must the set before every write operations It is automatically reset after a successful write operation The WREN and WRDI instructions have no parameters They are
174. r experiment Instead you shall emulate the serial bus with GPIO operations Three signals shall be controlled called SSEL SCK and MOSI These are connected to GPIO 4 GPIO 3 and GPIO 1 respectively Figure 40 illustrates the timing of the signals It is the signal MOSI that outputs the different segment values The SCK signal clocks in the value of the MOSI signal on its rising edge Signal SSEL shall be low during the clock in process When SSEL goes high the value on the shift register is transferred to the outputs of the shift register Check the datasheet of the shift register 74HC595 for details about the shift register operation Note the order of the bits on the MOSI signals First the DP bit shall be output and then segment G etc A zero will turn the segment on and a one will turn it off Figure 40 SPI Shift Register Communication Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide eo eo 5 e O 10 LED i Q1 1K5 BC557B R66 1K5 Shift register to 7 segment LED S u3 LED9 74HC595N LTD 4608JF SPI MOSI PIO 1 MQ 15 c I30F 10 9 i 1 SEGAR RIO 330H 8 330R 8 SPI SCK PIO 3 SCK 2 E R11 330R u D z SPI SSEL PIO 4 LED S z G 7 2E R17 m 330R 2 ne 2 A F B G le U3P C7 E C D i DP Figure 41 7 segment Display LED9 with Shift Register on Schematic Page 4 U1 LPCXpresso board qood E
175. r on First let s have a look how a 7 segment display works The name segment refers to the seven main segments labeled A to G See picture below Sometimes there is also an eighth LED a dot that is typically labeled R DP It is still called a segment LED even though there are actually 8 LEDs DIG 10 8 l 5 3 6 7 2 Figure 32 Dual Digit 7 segment LED The dual digit 7 segment LED that is used in this kit has common anodes and are multiplexed as outlined in Figure 32 With the 7 LEDs it is possible to create digits 0 9 and the six first characters in the alphabet This makes it possible to display hexadecimal numbers With the two digit display included in the kit it is possible to display a byte value in hexadecimal form 0x00 OxFF Nt Be Be S Mitr oje Be Be Es k JE sot bk S m O SET EM EVE Figure 33 All Hexadecimal Digits There are other types of LED displays See the picture below The segment display is the simplest There are also 14 and 16 segment displays With these it is possible to display all letters in the alphabet There are also matrix displays in different sizes The 5x7 formation is the smallest to get reasonable readable digits The benefit with LED matrixes is that graphics can also be displayed Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide I Segment 14 Sexpnert Jo Sexgment phus OP phus DP phus DP Figure 34 Different LED Displays 1 9 1
176. releases In the next experiment you will find one way of dealing with this problem 3 9 Lab 2e Sampling of Inputs In this experiment we will introduce the concept of sampling In the previous experiments the outputs have been controlled as quickly as possible and the inputs have been read as often as possible Although simple it is often desirable to have more detailed control of the system behavior Sampling is a concept where the state of inputs is read at defined points in time the sample period Outputs are also controlled changed at these points in time More advanced systems can have many different rates active at the same time Some inputs are read at high rate for example 1000 Hz once each 1 ms while others are read at lower date say 10 Hz i e once each 100 ms The used rate is a trade off between workload for the microcontroller and how fast the input can change or how fast the Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide outputs must be controlled A fast changing signal must for example be sampled often in order not to miss any important information In this experiment we shall sample the push button with different sample rates The forever loop of the previous experiment Lab 2d is used A delay function is introduced before checking push button state Use the delay function created in Lab 1c for this lf the delay is for example 100 ms the effect is that the push button is sampl
177. resistors are 330 ohm U1 LPCXpresso board IHE m ZEE t 999 4 ii 1i t PE ZIP i CT Made with 9 Fritzing org Figure 18 Breadboard Connections for 8 LEDs and two Push buttons In this experiment the 8 LEDs shall be controlled in a running one pattern First let the running rate be fixed Use the delay function from previous experiments as the time base The program structure is suggested to be as below 1 Wait a fixed time 2 Update the state variable or counter which is technically also a state and 3 set outputs according to state Declare variables Initialize pins to be inputs and outputs set outputs to defined states Enter forever loop while 1 Delay a specified period of time or wait for push button to be pressed Update state counter Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Update LEDs according to state counter Since there are 8 LEDs is would be suitable to define 8 states or having a counter count between 0 7 or 1 8 if that makes more sense The set outputs according to state can be discussed in more detail One method is to first reset all outputs to their inactive state In our case that means setting the 8 LED outputs high which will turn the LEDs off After that the state counter determines which output to set low turn on one LED This structure will save code since the resetting
178. resso Experiment Kit User s Guide Page 103 ME Tera Term disconnected VT File Edit Setup Control Window Help Baud rate Data Cancel Parity stop Help Flow control Transmit delay 0 msec char msecline There are many different settings for how the terminal program shall behave i e interpret received characters Some adjustments might be needed for example when to start displaying received characters on a new line Under menu Setup sub menu Terminal setup it is possible to control these things The screenshot below illustrates the settings possible for when a new line shall be performed on received characters A common setting is LF but it also depends on which character the LPC111x application outputs xu Tera Term disconnected VT File Edit Setup Control Window Help Terminal size 50 x el 4 Term size win size Auto window resize Terminal ID VT100 Answerback Auto switch VT TEK Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 104 Have a look in chapter 13 LPC111x LPC11OCxx UART in the LPC111x user s manual for a description of the how the UART block works The basic principles are the same as for the SPI block it is a serial shift register for transmitting and receiving The difference is that for the UART block it is more complex with for example separate shift registers for transmitting and receiving and more flexibility
179. rogramming real time operating systems program frameworks user interfaces drivers logging field updates boot loader structures factory calibration settings configuration management communication protocols graphical programming security etc 9 Last but not least the domain knowledge the functional that the product under development shall implement When working through the experiments in the LPCXpresso Experiment Kit you will increase your knowledge in the first three areas Enjoy working with the LPCXpresso Experiment Kit Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 4 Kit Content In this chapter we will take a closer look at the different components included in the LPCXpresso Experiment Kit The table below contains photos and a description of all components in order to simplify identification Note that photos are only typical in the sense that they illustrate the components typical visual appearance Exact appearance can differ for the components in the kit that you have received The number of components shown in a picture can also differ from delivered quantity Most components are specified with a Digikey or Mouser equivalent If a component gets damaged a new one can typically be ordered from Digikey Mouser or any preferred component distributor The Digikey Mouser number is just to get the key data of the component The actual components in the component kit might very we
180. rts with pPattern 0 otherwise KK KK KK KK kk KK KK KK kCkCk Ck AXA A KK K ck k KK KK KAZ KK A AK K AAA A kCkCkckck kk KK KK KK kc kckck k ck kk kk kk static uint8 t hasPattern uint8 t pBuf uint8 t pPattern while pBuf END OF MESSAGE amp amp pPattern END OF MESSAGE if pBuf pPattern return 0 pPatternt pBuf return 1 KK k k k k k Ck Ck Ck Ck Ck k Ck k Ck Ck Ck k k k k k Ck k k k k Ck k k k k k Ck k k k Ck k Ck k Ck Ck k Function name pointToNextValue Descriptions Moves past the next divider parameters Pointer to the string to search Returned value None ko a a a a a k o o o EERE o a KO KO KCK KO KO a a CK ha a CK a ho a CK o ho o Ck k ho k EKER A static void pointToNextValue uint8 t ppBuf while ppBuf END OF MESSAGE if ppBuf DIVIDER ppBuf point to the start of next value break ppBuf Kk kk k k CK CK Ck CK CK Ck k k k k k k k k k Kk k k k k k k Kk Ck k k k k k Ck k k k k Ck k Ck Ck k k Ck k Ck k Ck Ck k 58 Function senes convertCordinateToDegree Descriptions Converts the pBuf string which is in the ON ddmm mmmm format into an integer representation parameters The buffer the resulting integer and the NUN length of the buffer Returned value None c KCKCKCKCKCKCKCKCKCk Ck Ck k Ck Ck Ck Ck k Ck k Ck Ck k k k Kk k k k k k k k k k k k k k k k k k k k k k k Ck k k k k k k Ck k k
181. s 7 18 1 Lab 17a USB Device HID The experiment will configure the LPC1769 as a USB Device with the HID Human Interface Device class The HID driver is always present in Windows and does not require any additional device drivers When using the USB Device interface a USB B to USB A cable is needed not included in the kit Connect it to the J9 connector on the experiment board and to the PC This experiment is based on the code examples that are delivered with the LPCXpresso IDE The code is structured very differently none of the code from the previous exercises is used You have to create a new workspace in LPCXpresso and then import the projects from Lab17a zip Run the USBHID project on the LPCXpresso and let the PC discover it Run the HIDClient exe program found in the USBHID folder of Lab17a zip and select LPC17xx USB HID from the list 4 HID Client um Human Interface Device Figure 69 HID Client Screenshot Press the buttons on the experiment board and note what happens in the PC application Click the different output checkboxes or change the value in the text field The reading writing of values are done in these two functions in main c Get HID Input Report gt InReport a void GetInReport void InReport 0x00 if LPC GPIO0 gt FIOPIN amp 1 lt lt 4 0 InReport 0x01 up pressed means 0 if LPC GPIO0 gt FIOPIN amp 1 lt lt 2 0 InReport 0x02 left pressed
182. s Alternatively create your own project based on these ideas 8 1 Interface a Color Sensor Select a color sensor for example one of these http www sparkfun com products 10701 with a digital interface http www sparkfun com products 10904 with an analog interface Create the hardware and software interface to the sensor Output can be on the console the RGB LED or on a display 0 2 Interface a Real time Clock RTC Select an RTC chip and interface Most commonly used interfaces to these chips are 12C or SPI For example NXP PCF8523 with I2C interface or PCF2123 with SPI interface Create an application that displays the real time on a display or via the console It shall be possible to set the current time If a display is used create a small menu system controlled by the joystick push buttons or the rotary switch Implement alarm functionality Implement low power operation where the processor sleep and only wake up once a second to update the time or even once a minute The processor shall also wake up on alarms several enhancements are possible to this project Implement automatic adjustment of the clock once a day Implement automatic adjustment for summer and winter time Ifthe RTC chip does not support leap year add support for leap year compensation 8 3 Interface a GPS Module Interface a GPS module Most modules have a UART interface and communicate with the standard NMEA protocol use google to f
183. s also possible to work with the LPC1114 in DIL28 package which is a breadboard friendly package The suggested work flow is as follows first start with performing the experiments with a group of components on the bread board together with an LPCXpresso board When done with the experiments solder the components to the pcb Continue with the next group of components Some components only work on the pcb simply because they do not fit into the bread board Perform the experiments related to these components when they have been soldered to the pcb There are of course other ways of working for example soldering all components to the pcb at the end of all experiments or work separately with the LPC1114 in DIL28 package instead of an LPCXpresso board Note that in the latter case an LPC Link is needed to program the LPC1114 The LPC Link is the debugger half of an LPCXpresso board The LPC111x is built around a Cortex M0 core from ARM and the LPC1769 has a Cortex M3 V core Most things addressed with the experiments are general to all microcontrollers and embedded systems programming in general The details are however slightly different between different microcontrollers for example the different functionality and registers tin the on chip peripherals After having worked with the LPCXpresso Experiment Kit and completed the experiments you will have gained several competences at basic level e embedded programming e professional debugg
184. s is used You have to create a new workspace in LPCXpresso and then import the projects from Lab17b zip When using the USB Device interface a USB B to USB A cable is needed not included in the kit Connect it to the J9 connector on the experiment board and to the PC Compile and run the program Your board should appear as a HID compatible mouse on the PC when the driver installation has completed Use the buttons on the experiment board to move the mouse pointer The middle button SW3 acts as a left click on the mouse As seen it is not possible to select text or to move the mouse pointer diagonally This is because the following code in main_mouse c only allows one button at a time The reading writing of values are done in these two functions in main_mouse c LE 1 JoystickState JOYSTICK UP 4 MouseInputReport bY 10 MouseInputReport bX 0 MouseInputReport bmButtons 0 else if i JoystickState amp JOYSTICK DOWN MouseInputReport bY 10 MouseInputReport bX 0 MouseInputReport bmButtons 0 else 1 1 JoystickState JOYSTICK LBET 1 MouseInputReport bX 10 MouseInputReport bY 0 MouseInputReport bmButtons 0 else if 1 JoystickState amp JOYSTICK RIGHT 1 MouseInputReport bX 10 MouseInputReport bY 0 MouseInputReport bmButtons 0 else 17 1 JoystickState amp JOYSTICK ChLICK 4 MouseInputReport bX 0 MouseInputReport bY 0 MouselInputReport bmButtons 4 7
185. s processed in the xbeeData function Run the program on both boards and note that pressing the SW2 button on one board lights the LED on the other board Suggested improvements e Extend the protocol to retrieve the temperature reading from the other board e Use one board s quadrature encoder to control the other board s 7 segment display e Read analog values remotely Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 117 e fyou have access to more than two XBee modules test what happens when they are all powered e Change the protocol from broadcast mode to point to point communication by adding the target node s address in the xbee send function call 7 16 2 Lab 15b GPS Receiver The Global Positioning System GPS for short is a satellite navigation system that provides time and location information as long as there is a direct line of sight to at least four satellites GPS is used in a wide range of application including cell phones and car navigation systems In this experiment a GPS module from Embedded Artists with the GPS chip from GlobalTop Technology Inc will be used It is simple to use as there is no initialization of the module and it continuously sends the received information on the UART channel explored in Lab14a c The baud rate is specified by the module to 9600bps Note that the GPS module in not included in the component kit It must be bought separately Figure 65 i
186. setup Figure 94 LPCXpresso IDE Error Failed on chip setup In the console window more detailed information is given It can for example look like this Invalid LPC1114 301 Part ID 0x00050080 Known LPC1114 301 ID s 0x0444102B 0x2540102B 03 Failed on chip setup Ec 01 Invalid mismatched or unknown part The solution is to change the chip type to the correct version Click on the project main folder on in the Project Explorer window to the left and press Alt Enter Alternatively left click on the project folder and select Properties at the end of the list Select the C C Build menu and then the MCU setting menu A list of available chips is presented Select the correct chip in this list Note that it is possible to select the chips that are listed in red There are however restrictions for these chips Typically in how big the code size can be Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 153 10 Further Information The LPC111x microcontroller is a complex circuit and there exist a number of other documents with a lot more information The following documents are recommended as a complement to this document 1 NXP LPC111x Information Datasheet User s Manual and Errata htto ics nxp com products lpc1000 lpc1 100 lpc1 1cxx 2 ARM Processor Documentation Documentation from ARM can be found at http infocenter arm com 3 Information on different ARM Architect
187. sing the E2PROM which is accessible over the 12C bus The keys can be short strings for example strings with lengths between 1 and 16 To make it simple a value connected to a key is always a 32 bit integer If you want to make it more advanced a value can also be a string Typical operations for a registry are e Create entry for a new key e Delete key e Get value of key e Update key e listall keys A registry is always usable to have when creating real world applications There is often a need to store settings from a user Also in the case of Internet communication the following settings must be stored in the system e P address e Subnet mask e Default gateway e fan Ethernet interface is present the MAC address is also needed 8 12 Real Time Dynamic Data with JAVA Applet This is a project that requires a TCP IP stack web server and RTOS By using SSI and CGI EGI technologies in a web server you can create dynamic information in a web server However the information is created at the download moment Anything that happens after that point in time will not be reflected on the client side True real time data visualization is hence not possible with SSI or CGI EGI To create true real time data on the client side the web browser a JAVA applet must be used The JAVA applet connects back to the embedded system opens a communication channel and then received real time data The communication channel can be either
188. sion begins with a start bit which is low The negative edge is detected by the receiver and 1 5 bit periods after this bit sampling begins Eight data bits are sampled The least significant bit LSB is typically transmitted first An optional parity bit is then transmitted for error checking of the data bits Often this bit is omitted if the transmission channel is assumed to be noise free or if there are error checking higher up in the protocol layers The transmission is ended by a stop bit Typically one bit but 1 5 and 2 bits are sometimes also used Most common for inter board communication is 8N1 meaning 8 data bits no parity and one stop bit Start DO D1 D2 D3 D4 D5 D6 D7 Parity Stop i bit Isb msb bit bit Sampling o 1 5 bit 1 0 bit etc Duration of one byte 10 12 bit periods Figure 57 UART Communication On a side note there are methods to determine the bit rate of a received signal but that is out of scope for this experiment An UART channel consists of two signals besides ground e XD transmit data direction from transmitter to receiver This is an output e RXD receive data direction from transmitter to receiver This is an input TXD and RXD are crossed between transmitter and receiver i e TXD is connected to RXD and vice versa For more information about asynchronous serial communication see http en wikipedia org wiki Universal asynchronous receiver transmitter and http
189. ster value 100 wanted duty cycle 100 Note the term 100 wanted duty cycle This is because the PWM signal starts each period as low and is set when a match occurs We will work with 16 bit timer 1 to generate two PWM signals The MATO and MAT signals are pinned out and will be our PWM signals In the LPC111x user s manual chapter 18 we find the following important sentence In PWM mode three match registers on CT16B0 and two match registers on CT16B1 can be used to provide a single edge controlled PWM output on the match output pins It is recommended to use the match registers that are not pinned out to control the PWM cycle length Since MATO and MATT of 16 bit timer 1 is pinned out and used as external PWM signals we select match register 2 as the cycle period register The subroutines below implements the principles outlined above Study the code and read in the user s manual to understand how the code works and in what way the timer is used to generate the two PWM signals KR KK KK K KKK KKK KK KAZ KK KK K AAA A KK K KA KK KK K KAZ KK KK KK KK KK KK AK KK KK KK KK KK KK kk Function name initPWM k Descriptions Initialize 16 bit timer 1 for PWM generation Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide kx Parameters cycleLength set PWM cycle length in microseconds Returned value None XK KCKCKCKCKCKCkCk Ck Ck Ck k k k Ck k Ck Ck k k k k k k k k k
190. t 10 1024 where offset 0 5 1024 10 0 1023 ADC input value Figure 37 Conversion Function It would be a good program structure to place the conversion function in a separate subroutine 1 9 4 Lab 8d Control Dual Digit 7 segment Display In this experiment you will create a time multiplexed control of the two digits On the schematic there are two PNP transistors to control the anodes of the two digits A microcontroller output cannot supply enough current to directly drive the anodes Therefore the PNP transistors are needed Pulling the respective GPIO pins connected to the base via series resistors low will open the transistors and hence supply current to the anodes In this experiment we ignore the shift register control of the segments Instead we continue using the direct GPIO control of each segment from the previous experiments In the following experiment the shift register will be used Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide eo eo amp amp sz Q1 1K5 BC557B R66 2 D fA Q2 KS BC557B Shift register to 7 segment LED S u3 LED9 74HC595N LTD 4608JF SPI MOSI GPIO 1 MO i SPI SCK PIC SPI SSEL GPIO 4 LED S DP GND D Figure 38 7 segment Display LED9 on Schematic Page 4 U1 LPCXpresso board i a Figure 39 Breadboard Connections for Dual Digit 7 segment Display Bin nou n uj ee 59 e e e e e e
191. t main c line ini Lio 8 ty FL A if uartlRead UARTSendString uint8 t XrXnReading data from this UART r n uart2 sendString uint8 t r nWriting data from UART1 to this UART r n else 1 uart2 sendString uint8 t r nReading data from this UART r n UARTSendStringe uint8 t Y NrMnWriting data from UART2 to this UART rin Figure 82 LPCXpresso IDE Set Breakpoint Pressing the Start button or F8 will start execution Hitting a breakpoint will stop execution Figure 83 below illustrates what the call stack looks like after stopping at line 34 in main Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 145 Debug tnd 4 uart2 Debug C C MCU Application DSF 4 gf uart2 axf 4 a Thread 1 lt main gt Suspended Breakpoint J Gall stack which indicates the call main at main c 34 0x198 JE gdb structure to get to the point where the program is currently stopped Currently stopped at line 34 in main c main c c stdio h c uart c c er startup Ipcll c c timer32 c d Welcome ic main c 3 18 include type h 11 include uart h 12 include stdio h 13 include timer32 h 14 include gpio h 15 include i2c h 16 17 include uart2 h 18 19 28 21 int main void uint8 t data 8 uint8 t uartlRead uint32 t recvd 8 uint32 t len 8 GPIOInit init timer32 8 18 I2CInit I2CMASTER 8 UARTInit 115280 uar
192. t 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 149 Develop Welcome page LPCXpresso File Edit Navigate Search Project Run Window Help DO HBB B 29 58 RK D Q ee 42 Svor rs Project Ex PX ifii Core Regi E Periphera EP Welcome 3 E Er eig Bi lt file C nxp LPCXpresso 4 0 5 123 Ipcxpresso pages registered htm gt E tS Accel systick irg wakeup E CMSISv2p00 LPC11Uxx 45 DeepPowerDown P Binaries powered by Aicode red ia Includes CB src LPCXpresso 4 is fully activated amp Debug DemoApp Debug launch Welcome to LPCXpresso 4 The software is now fully activated and can be used for production LPCXpresso can be used to get s DemoApp Release launch n mam FlashApp id LCD ADC temp wdt wakeup o Writing 24524 bytes to 0000 in Flash assumed clock 48 0MHz IE PCXpresso project LCD graphics cS lib LPC11U14Dev e lib OryxDev 5 ProductionTest example projects and announcements 15 RTC irg wakeup Semihosting ADC temperature sleep Quick 23 di RedC Varia 9o Br Details gt gt an invaluable resource for getting help and Start here j New project Import project s Build all projects Debug So get connected and join the LPCXpresso community To view the forum and to register so that you can post visit www nxp com Ipcxpresso forum General Information x Visit the NXP LPCXpresso website amp Build DemoAp
193. t SW2 button pin as inputs Use systick to get an interrupt every 10ms SysTick Config SystemCoreClock 100 if CFG ACT AS COORDINATOR 1 printf XBee demo COORDINATORNr n err xbee init XBEE COORDINATOR amp callbacks felse printf XBee demo NODE r n err xbee init XBEB END DEVICE amp oallbacks fendif if err t ERR OR 1 printer Failed to initialize Xbee Error code gd Aborting n err while 1 wait forever while 1 xbee task if devIsReady 0 check button state state GPIOGetValue SW2 PORT SW2 PIN if oldState state oldState state printf Button Su r nan state sendSetLedRequest state return 0 The XBee driver is provided four callbacks during initialization The callbacks will be called when the driver has completed initialization of the XBee module xbeeUp when a new node is discovered xbeeNode a transfer is completed xbeeTxStatus and when data is received xbeeData The driver s xbee task function must be repeatedly called in order for the Xbee module to work correctly The CFG ACT AS COORDINATOR define should be set to 1 for the controller and 0 for the nodes Look at the implementation of the xbee init function to see how they are treated differently The last thing to note about the program is the RFPT SET LED command that is sent when a button is pressed The command is received by another node and i
194. t least four satellites so if the latitude remains 0 after a minute then move closer to a window or perhaps take the board outside Extend the program by implementing the functions to at least extract longitude and number of satellites Verify your result by entering the coordinates in for example Google Maps or http www findlatitudeandlongitude com find address from latitude and longitude Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 123 7 17 Extra Work with Serial Expansion Connector In this experiment you will learn how to work with the Serial Expansion Connector It is a 14 pin connector with SPI UART and I2C communication interfaces and a couple of GPIOs The purpose of the connector is to provide a simple expansion connector for smaller expansion modules Such modules are typically sensors of different kinds and communication modules but can also be smaller displays Figure 67 illustrates the interface in the schematics serial Expansion Connector O a 10 12C SDA bidirectional 11 GPIO bidirectional 12 GPIO bidirectional 13 AINO GPIO input 14 AINS AOUT GPIO input Figure 67 Serial Expansion Connector on Schematic Page 7 In preparation for the exercise define all the pins in the Serial Expansion Connector SEC connector like below in file board h define SEC14 PIN3 PORT PORT2 define SEC14 PIN3 PIN 11 define SEC14 PIN4 PORT PORTO define SEC14 PIN4
195. t2 init 115200 CHANNEL A if uartlRead UARTSendString uint t r nReading data from this UART r n ose mam dC eu amm a tO SER zh eet ean Ants uum IIARTI fe Shae TART Rt oh Figure 83 LPCXpresso IDE Run to Breakpoint Figure 84 below illustrates what the call stack can look like when the call depth is a little deeper 6 levels in this case It also illustrates that it is possible to hover the mouse cursor over a variable A variable window will then pop up showing the current variable value Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 146 Debug 23 4 Fc uart2 Debug C C MCU Application DSF 4 qf uart2 axf 4 gf Thread 1 main Suspended Signal SIGINT Interrupt BCStart at i2c 187 xabc mI o o Call stack which indicates the call LEWntel at idc c 324 0xc76 writeReg at uart2 c 71 0x2e0 structure to get to the point where the uart2_setBaudRate at uart2 c 131 0x3c0 program is currently stopped wart init at uart2 c 111 0x392 main at main c 35 Oxlae Currently stopped at line 34 in main p l gdb main c c stdio h c uart c c timer32 c lc main c i2c c 33 dg Welcome 176 171 Issue a start condition 172 LPC_T2C gt CONSET I2CONSET STA Set Start flag f 173 174 f Wait until START transmitted 175 while 1 176 1 177 if I2CMasterState I2C STARTED 178 179 retV
196. tails R2 should not be mounted in this case The LPCXpresso board can supply up to about 100 mA on the 3 3V supply Note that by turning on all LEDs and activating all features on the board it is possible to consume more than 100 mA Note that the voltage is not exactly 3 3V but a Schottky diode forward voltage drop less so around 3 15V e Incase the LPCXpresso board is not powered via its USB connector an external 5V DC supply is needed Connect the external supply to J1 or J17 as described below fthe internal 3 3V voltage regulator on the LPCXpresso board is used R2 shall not be mounted Else R2 shall be mounted and U1 is the 3 3V regulator in use e f current consumption on the 3 3V supply is higher that the LPCXpresso board can provide an external 5V DC supply is needed This is typically true when working with wireless RF modules and or with the USB Host interface J10 connector When working with servo motors an external 5V supply is absolutely needed An external 5V DC supply can connect to J1 which is a 2 1mm power jack with positive center pin Note that there is no overvoltage protection in the design Make sure that the connected power supply does not supply more than 5V DC The current capability of the external 5V DC supply should be in the region of 1 2 Ampere Connector J17 mini B USB connector on the back side of the pcb can also be used to supply an external 5V DC supply via the USB
197. ten MISO FIFO counter increments Clear FIFO on MISO Otherwise when SSPOReceive is called previous data byte is left in the FIFO Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide dummy LPC SSPO gt DR KKKEKK KK Ck CkCkck ch kCk k KK AK K RRR KA kCkCkck Ck kCkck K KA kCkCk kCk KCKCk Ck kcCk KK KA k kCKCkCk Ck k Ck CkckCk Ck kCk kk Ck KERR ERE Function name SSPOReceive Descriptions the module will receive a block of data from Sm the SSP the 2nd parameter is the block length parameters buffer pointer and block length Returned value None KK Ck kCKCkCk k k kk kCkCk Ck k kk KK Ck ck k kk KK K ck k kk KK Ck ck k kk CkCkc K AA kk kCkCk kck kk kCk Ck ck ck k k ck kc kckck k ck KK kk vold SSP Receive uint t pBur uint32 t length Hinto b for i 0 i lt length i Write dummy output byte OxFF to shift in new byte LPC SSP0 gt DR OXFF Wait until the Busy bit is cleared while LPC SSPO gt SR amp SSPSR BSY SSPSR RNE SSPSR RNE pBur LPC SSPU SDE pBuf Place the SPI related functions in file spi c 1 12 1 Lab 11a Access Shift Register In this experiment a shift register the 74HC595 chip shall be connected to the SPI bus A byte will be transmitted to the shift register and then read back The external shift register can be seen as a one byte memory Not very cost effective or high performance but
198. th 5Hz rate Whenever the push button is pressed enter a 2 second delay loop of the old type in the interrupt service routine First observe the LED flashing Press the push button What happens Yes the LED will stop toggle for 2 seconds whenever the push button is pressed It is exactly what can be expected since the push button port 1 ISR will block the timer interrupt This is an excellent illustration that time spent in an ISR should be kept to a minimum in order not to block other ISR s from being executed Now explicitly set the priority of both ISR s Set the priority of the timer ISR higher than for the GPIO ISR Remember that a lower number range is 0 3 means higher priority Verify that the LED now continues flashing whenever the push button is pressed What is the default priority for all interrupts There is a function call for reading the priority also Search in the file core cm0 h after this function Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide 7 13 5 Lab 12e Control Dual Digit segment Display This experiment revisits Lab 8d Control Dual Digit 7 segment Display and Lab 11b Control 7 segment Display By combining the knowledge from all previous experiments it is now possible to create a system that is quite close to a how this would have been solved in a real system Setup a repetitive timer interrupt say 500 Hz 2 ms between each interrupt Let the timer ISR update the
199. the alternative pin functions can be controlled Pin PIOO 2 is controlled by register IOCON PIOO 2 In the description for this register we can see that there are three alternative pin functions PlO0 2 a general purpose input output port 0 pin 2 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide SSELO a control signal for peripheral block SSP CT16B0 CAPO an input signal to 16 bit timer 0 Note that only one functional signal can be connected to the pin at any given point in time It is however possible to change during program execution By default after reset the register is initialized to PIOO 2 have a pull up resistor enabled input hysteresis disabled and to be a standard push pull GPIO output if defined as an output Another register controls the direction of the general purpose digital input output and this register initialize PIOO_2 to be an input after reset Hence after a reset PIOO 2 is an input with pull up resistor enabled The pin is pulled high weakly but cannot source any larger current That means that LED1 will be off after reset because the LED will turn on when PIOO 2 is pulled low and if enough current can sink into the pin All LPC111x registers are defined in file LPC11xx h Itis part of the framework needed to program the LPC111x Have a look in file LPC11xx h It is found in the CMSIS library in the inc sub directory What address is register IOCON PIOO
200. the value data utcTime index ppBur if index index 5 Add divider data utcTime index ppBuf data utcTime index 0 KKK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK Function name parseLatitude k Descriptions Extracts the latitude information and stores the result as an integer an dat latitude parameters The buffer Returned value None KK Ck kCKCkCk AA kk KK KK KK KK Ck AAA A kCk Ck kck kk KK KAZ kk A K kck k kk KCkCk Ck k kk k Ck Ck kck kk ck kckckck k ck kk kk kk Static void parseLat itude usntS t ppBur lint index 0 while ppBuf l END OF MESSAGE if ppBuf DIVIDER ppBuf reached end of the value break data bufLatitude index ppBuf ppBuf convertCordinateToDegree uint8 t amp data bufLatitude amp data latitude 8 KKK KK KKK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KK KAZ KK KK KK k kk Function name GPSRetreiveData Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 121 Descriptions Reads and parses the next set of GPS data parameters None Returned value The parsed information KR KK Ck kCKCkCk AA kk KK KK KK KK K Ck ck k kk kCk K kck KK KK Ck ck k kk kCkcCkckck kk kCkCkckck kk kCk KK KK kc kckck k ck kk kk kk const gpsData GPSRetreiveData v
201. tly ON Semiconductor BC557BRL1G Digikey BC557BRL1GOSCT ND Mouser 863 BC557BRL1G Color Brown Green Black Red This is not a polarized component Yageo MFR 25FBF 52 15K0 Digikey 15 0K XBK ND Color Black This is not a polarized component Yageo ZOR 25 B 52 0R Digikey 0 0ABK ND Color Orange Orange Black Black This is not a polarized component Yageo CFR 25JB 52 330R Digikey 330QBK ND LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB Trimming potentiometer 22 Kohm 2 pcs R7 R20 http en wikipedia org wiki Potentiometer Photo resistor 1 pcs R24 http en wikipedia org wiki Photo_resistor Resistor 220 ohm 2 pcs R27 R28 http en wikipedia org wiki Resistor Resistor 1 5 Kohm 8 pcs R26 R39 R40 R60 R61 R65 R66 R67 http en wikipedia org wiki Resistor 10Kohm equivalent from Bourns Inc 3352E 1 103LF Digikey 3352E 103LF ND This is not a polarized component Advanced Photonix PDV P9002 1 Digikey PDV P9002 1 ND Color Red Red Black Black This is not a polarized component Yageo FMP100JR 52 220R Digikey 220WCT ND Color Brown Green Black Brown This is not a polarized component Yageo FMP100JR 52 1K5 Digikey 1 5KWCT ND LPCXpresso Experiment Kit User s Guide Copyright 2013 Embedded Artists AB Resistor 2 Kohm 16 pcs R43 R44 R45 R46 R47 R48 R49 R50 R51 R52 R5
202. to default state is done only once Another method also outlined below is to set all outputs to correct levels in each state This will duplicate much code but the program can possibly be easier to understand and maintain Reset all outputs Set only the active output switch 24 Set active output Set active output Set active output default Set and reset the switch active output and reset all others active output and reset all others break active output and reset all others default It is also possible to experiment with other patterns then the running one For example having 3 LEDs on simultaneous When the fixed running rate is working adjust the program so that a push button press is advancing the running LEDs instead of time Simply replace the delay function with a while loop that waits for a push button press A little twist on above is to add a timeout functionality If the push button is not pressed for 5 seconds the running LEDs should be advanced one step How to implement that Tip sample the push button at a fixed known rate Count how many times sampling is done If too many samples without detecting a press then a timeout has occurred Define the timeout with a constant define 1 4 2 Lab 3b Control of Running One Pattern The experiment can only be done partially on the breadboard The goal is to generalize the program from Lab 3a Use two push buttons for increasin
203. ult after reset the register is initialized to PIO1 5 have a pull up resistor enabled and disabled input hysteresis As we know from the previous experiment there is another register that controls the direction of the general purpose digital input output and this register initialize PIO1 5 to be an input after reset Hence after a reset PIO1 5 is an input with pull up resistor enabled The pin is pulled high weakly which is exactly what we need When pressing the push button the pin will be pulled low The input will be read high when no push button is pressed and low when it is pressed In Experiment 1b a function called GPTOSetDir was created Even thought the direction of PIO1 5 is correct from reset it is good programming practice to initialize the pin according to need It is simpler for other programmers to read and understand an application if there are no hidden assumptions Register LPC GPIO1 gt DATA holds the current state of the pins in port 1 Bit 5 in this register reflects the state of pin PIO1 5 Since the register reflects all pins in the port the bit of interest must be masked out Use the same principle as presented in Lab 1a i e AND with 1 bitNumber Create a program that reads the state of the pin and hence the push button and copy the result to a LED Turn on the LED when the push button is pressed Below is the skeleton of the program that you shall create Create defines for simpler access of LED1 def
204. umber of NOPs delayNops uint32 t nops volatile int32 t U for i 0 i lt nops i asm volatile nop About how many NOPs are needed for a 1 second delay What does this tells you about the execution speed of the LPC111x Note that delay loops like this should never be used in real programs All processor execution time is lost in the loop and no other useful work is done Also the delay can vary depending on what other parts of the system do for example how much time is spent in interrupt routines which will be introduced later on Later on we will explore other method of creating exact delay functions so for now the loop method will have to do Create a function that delays execution a specified number of milliseconds as input parameter Place the function in a separate file delay c After that create the program that double flash the LED according to the specification above Now can be a good time to get acquainted a bit more with the debugger specifically single stepping This means that the debugger let the microcontroller execute one statement at a time and stops after every line Note that for this to work the compiler optimization most not be turned on too heavily O0 and O1 is typically what work More optimization will rearrange the code so there are no clear boundaries between the source code statements 7 rows in the source code Instead of pressing the Start Resume button it is possible to
205. up its own list of pins depending on needs For the OLED module it will be define OLED SSEL PORT SECI4 PIN6 PORT define OLED SSEL PIN SEC14 PIN6 PIN define OLED RESET PORT SEC14 PIN12 PORT define OLED RESET PIN SEC14 PIN12 PIN define OLED DC PORT SEC14 PIN11 PORT define OLED DC PIN SEC14 PIN11 PIN define OLED SD PORT SEC14 PIN14 PORT define OLED SD PIN SEC14 PIN14 PIN The advantage of this approach is that if the LPCXpresso LPC111x board is replaced with a different one then the pin port information only has to be changed for the SEC14 defines the connected modules will remain unchanged The SSD1315 controller chip is complex and creating a driver from scratch is out of scope for this exercise Instead a number of ready drivers are give see list below These files must be copied imported into the project e draw c h basic graphical drawing primitives e oled c h OLED initialization function e Ssd1315 c h OLED controller driver Below a code segment is given that serves as base for the program in this experiment static void rainbow draw lcd t lcd White gt 0 15 draw fillRectangle led 0 0 15 127 OXEIEEE Yellow gt 16 31 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Page 125 Purple gt 32 47 Cyan gt 48 63 Red gt 64479 Green gt 80 95 Blue gt 96 111 Black gt 112 127 int main void dr
206. ures http www arm com products processors technologies instruction set architectures php 4 ARMv7 M Architecture Reference Manual Document identity DDI 0403D http infocenter arm com help index jsp topic com arm doc ddi0403c index html 5 ARMv6 M Architecture Reference Manual Document identity DDI 0419B http infocenter arm com help index jsp topic com arm doc ddi0419b index html 6 Cortex M0 Technical Reference Manual Revision rOp0 http infocenter arm com help index jsp topic com arm doc ddi0432c index html 7 LPCXpresso IDE NXP s low cost development platform for LPC families which is an Eclipse based IDE http ics nxp com Ipcxpresso 8 LPC1000 Yahoo Group A discussion forum dedicated entirely to the NXP LPC1xxx series of microcontrollers http tech groups yahoo com group Ipc1000 9 LPC2000 Yahoo Group A discussion forum dedicated entirely to the NXP LPC2xxx series of microcontrollers This group might be more active than the LPC1000 group http tech groups yahoo com group lpc2000 10 LPCware NXP s community for developers http www lpcware com Note that there can be newer versions of the documents than the ones linked to here Always check for the latest information version Copyright 2013 Embedded Artists AB
207. ve Connection Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide There is no specific upper frequency for the SCLK frequency It depends on the SPI peripheral block in the microcontroller the external SPI slave chip s and how far away the master and slaves s is are For breadboard experiments the SCLK frequency should typically not exceed 1MHz With proper pcb layout a frequency up to 20 30 MHz should not be a problem assuming the chips involved support this frequency For more information about SPI see http en wikipedia org wiki Serial Peripheral Interface Bus There are some so called decoupling capacitors that are not shown on the breadboard setups Decoupling capacitors are added to reduce voltage dips on the supply voltage to integrated circuits In the LPCXpresso Experiment Kit decoupling capacitors are used on five different locations in the schematic U3 C7 U4 C8 U5 C9 U6 C10 U7 C11 A standard value of 100nF has been selected for the capacitor When working on breadboard signal frequencies cannot be too high A good rule of thumb is to keep signal frequencies below 1MHz A breadboard is simply not a good place for high frequency electronics The decoupling capacitors can typically be ignored on the breadboard When soldering the components to the pcb it is however recommended to also solder the decoupling capacitors Have a look in chapter 14 LPC111x LPC11Cxx SPIO 1 with SSP in the LPC
208. x5002 3FFC GPIOSDATA address 0x5003 0000 to 0x5003 3FFC bit description Bit Symbol Description Reset Access value 11 0 DATA Logic levels for pins PlOn_0 to PlOn_11 HIGH 1 LOW na RAN 0 31 12 Reserved Figure 9 GPIO Data Register There are also several registers related to interrupt functionality We will not work with that right now In later experiments we will return to this Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide Note that registers GPIOODIR and GPIOODATA are accessed as LPC_GPIO0 gt DIR and LPC GPIO0 gt DATA respectively Below is the two statements needed to first set PIOO 2 to an output and then pull the output low This will turn the LED on Set PIOO 2 as an output LPC GPIO0 gt DIR LPC GPIO0 gt DIR 0x1 lt lt 2 Turn LEDIL on LPC GPIO0 DATA set BIOU 2 pin ow i 90 Clear bit LPC GPIO0 gt DATA amp 0x1 lt lt 2 As seen each of the registers is first read and then bit 2 is manipulated In the first statement bit 2 is set which makes PIOO 2 an output In the second statement bit 2 is set to zero This pulls PIO0 2 low Note that all bits in the registers must be read and only the bit of interest shall be manipulated The shift operation 0x1 2 is a good way of writing code The 2 part indicates clearly that it is bit 2 that is manipulated It is simpler for a reader of the code to quickly see this than to write the
209. xecuting this code Include needed libraries d1include stdio b int main void printf knThis is a first test n printf that semihosting and printf works and it does while 1 return 0 Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide E Console 33 5 oblems emco 64 Instruction Trace M Red Trace Previe Search mj Ex BB amp amp r4 E ri O Lab Test Semihosting Debug C C MCU Application DSF Lab Test Semihosting axf This is a first test that semihosting and printf works and it does T j NXP LPC1115 303 Lab Test ihostina Figure 22 Semihosting Console Output Create a program that determines the Endianness of the microcontroller and prints the result Assume we have a 32 bit number OxOACOFFEE in hexadecimal notation The table below illustrates how the bytes are stored differently between a big and little Endian system Now think of a solution how to test this Tip Create an unsigned int pointer and an unsigned char pointer Let these pointers point to the same unsigned int variable Write a value in the unsigned int variable with the unsigned int pointer Then read out the four parts via the unsigned char pointer What Endian does the LPC111x has little or big endian The printf function works like normal It is possible to output strings and general expressions Verify that this works Note that Semih
210. you start soldering e Temperature regulated soldering iron in the 30 80 Watt region e Thin 0 5 0 75 mm 20 30 mil solder with rosin core and non corrosive flux e Damp sponge or brass sponge e Wire cutter e Safety glasses It is also recommended to have a soldering fume extractor or work in a well ventilated space and have a fan that simply blows away the soldering fumes In either case be aware of the health issues with soldering fumes 6 1 Component Placement The picture below illustrates the component placement on the pcb The picture is also available as a PDF where it is possible to search for the component designators Copyright 2013 Embedded Artists AB LPCXpresso Experiment Kit User s Guide o J14 o R3 R35O O R380 am R310O mm O vno hedded Arti SW6 O rev PA4 R370 m O gt Em R290 m Oo OO R300 m O ojoloxojolo he O J7 J18 Oom mores LED1 LPCXpresso Experiment Board CC Embedded Artists AB 2012 www EmbeddedArtists com Om mm ORE7 Om mm ORI0 jn yg oleje EOM ETE GTOTOIOJOJOJO O OJOIOTOTOYO O J2 00 010 1O10 0 OJO1O1O01O0JOJO1OYOYOJO OTOYO OJOJO TOTO bottom side e D ES 63 O Qv n D J17 on l a 94951 O W o re C o gt Figure 2 LPCXpresso Experiment Kit PCB with Component Designators GND 5V_3 3V L O O Copyright 2013 Embedded Art

Download Pdf Manuals

image

Related Search

Related Contents

P4X Pico Projector - AAXA Technologies    Vantec NexStar HX  Présentation générale - Epsilon  Instruction Manual  Toshiba Satellite C675-S7200  1785-2.41, Using a PLC-5 Processor in a Heat Application  Contents Introduction  Manual del usuario del sistema  Perixcope User Manual 1.0  

Copyright © All rights reserved.
Failed to retrieve file