LPCXpresso Experiment Kit - User’s Guide Copyright 2013 © Embedded Artists AB LPCXpresso Experiment Kit User’s Guide Learn embedded programming with NXP’s LPC1000 family of Cortex-M0/M3 microcontrollers! EA-USG-1206 Rev A
LPCXpresso Experiment Kit - User’s Guide Page 2 Embedded Artists AB Davidshallsgatan 16 211 45 Malmö Sweden info@EmbeddedArtists.com http://www.EmbeddedArtists.com Copyright 2013 © Embedded Artists AB. All rights reserved.
LPCXpresso Experiment Kit - User’s Guide Page 3 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 2.6.2 OEM / Evaluation / QuickStart Boards and Kits 3 LPCXpresso Experiment Kit 3.
LPCXpresso Experiment Kit - User’s Guide Page 4 7.6 53 7.6.1 Lab 5a: Read Trimming Potentiometer 53 7.6.2 Lab 5b: Event Threshold 56 7.6.3 Lab 5c: Read Light Sensor 56 7.6.4 Lab 5d: ADC Noise Test 57 Pulse Width Modulation 58 7.7 7.7.1 Lab 6a: PWM Control of a LED 58 7.7.2 Lab 6b: PWM Control of a LED, cont. 1 59 7.7.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.
LPCXpresso Experiment Kit - User’s Guide Page 5 7.17 7.17.1 7.18 Extra: Work with Serial Expansion Connector 123 Lab 16a: 128x128 OLED Graphical Display 123 Extra: Work with USB Device 126 7.18.1 Lab 17a: USB Device – HID 126 7.18.2 Lab 17b: USB Device – Mouse HID 127 7.19 7.19.1 7.20 Extra: Work with USB Host Lab 18a: USB Host Extra: Work with Ethernet Interface 128 129 7.20.1 Lab 19a: easyWeb Web Server 129 7.20.2 Lab 19b: lwIP TCP/IP Stack, Web Server and FreeRTOS 130 7.
LPCXpresso Experiment Kit - User’s Guide Page 6 10 Further Information Copyright 2013 © Embedded Artists AB 153
LPCXpresso Experiment Kit - User’s Guide Page 7 1 Document Revision History Revision Date Description PA1 2012-07-16 Work in progress. PA2 2013-01-14 Work in progress. PA3 2013-01-25 First version to be released. All experiments are still not complete. PA4 2013-01-29 Minor corrections/clarifications. PA5 2013-02-25 Completed section 7.9 - 7.10. PA6 2013-03-19 Completed section 7.11-7.14. Cleanup in variable declarations in code fragments.
LPCXpresso Experiment Kit - User’s Guide Page 8 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.
LPCXpresso Experiment Kit - User’s Guide 2.2 Page 9 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.
LPCXpresso Experiment Kit - User’s Guide Page 10 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.
LPCXpresso Experiment Kit - User’s Guide Page 11 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.
LPCXpresso Experiment Kit - User’s Guide electronic design in general how to work with a breadboard how to solder Page 12 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.
LPCXpresso Experiment Kit - User’s Guide Page 13 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.
LPCXpresso Experiment Kit - User’s Guide Page 14 Tantal capacitor C1, C2, C12 22uF http://en.wikipedia.org/ wiki/Tantalum_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: 581TAP226K010SCS Ceramic capacitor C3, C4 18pF The printed numbers on this component is “180”. http://en.wikipedia.
LPCXpresso Experiment Kit - User’s Guide Page 15 Schottky diode D1, D2 1N5817 This component is polarized. There is a ring on one pinside of the components (upper side in the picture). This is the cathode of the http://en.wikipedia.org/ diode. The other side wiki/Semiconductor_diode (bottom side) is the anode. http://en.wikipedia.org/ wiki/Schottky_diode Stand-offs H1, H2, H3, H4 Diodes Inc: 1N5817-T Digikey: 1N5817DICT-ND Mouser: 621-1N5817 These stand-offs are mounted in each corner of the pcb.
LPCXpresso Experiment Kit - User’s Guide Page 16 equivalent for this component. RJ45, Ethernet connector J4 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 Pin list, 1x3 J5, J6, J8, J12 Sullins: PEC03SAAN Digikey: S1012E-03-ND Pin list, 2x3 J7 and J11 combined This component and can only be soldered to the pcb (i.e., not used on the bread board).
LPCXpresso Experiment Kit - User’s Guide Page 17 socket connector for wireless module J15 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 Shrouded pin list, 2x7 J16 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.
LPCXpresso Experiment Kit - User’s Guide Page 18 RGB-LED LED10 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. 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 Vf (around 3.2V) will work.
LPCXpresso Experiment Kit - User’s Guide Page 19 PNP transistor, BC557B Q1, Q2, Q3 http://en.wikipedia.org/ wiki/Bjt_transistor 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. ON Semiconductor: BC557BRL1G Digikey: BC557BRL1GOSCT-ND Mouser: 863-BC557BRL1G Resistor, 15 Kohm, 7 pcs R1, R3, R35, R36, R41, R42, R59 Color: Brown, Green, Black, Red http://en.wikipedia.
LPCXpresso Experiment Kit - User’s Guide Page 20 Trimming potentiometer, 22 Kohm, 2 pcs R7, R20 10Kohm equivalent from Bourns Inc.: 3352E-1-103LF Digikey: 3352E-103LF-ND 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 Copyright 2013 © Embedded Artists AB This is not a polarized component.
LPCXpresso Experiment Kit - User’s Guide Page 21 Resistor, 2 Kohm, 16 pcs R43, R44, R45, R46, R47, R48, R49, R50, R51, R52, R53, R54, R55, R56, R57, R58 This is a surface mounted component and can only be soldered to the pcb (i.e., not used on the bread board). http://en.wikipedia.org/ wiki/Resistor Panasonic: ERJ-6ENF2001V Digikey: P2.00KCCT-ND Piezo buzzer, 1 pcs SP1 This component is polarized. One pin is longer than the other. The longer pin is the positive side.
LPCXpresso Experiment Kit - User’s Guide Page 22 Rotary encoder, 1 pcs SW6 This component and can only be soldered to the pcb (i.e., not used on the bread board). Below is without center switch. Panasonic: EVEGA1F1724B Digikey: P10859-ND Mouser: 667-EVEGA1F1724B Voltage regulator, MCP1700-330, 1 pcs U1 http://en.wikipedia.org/ wiki/Lowdropout_regulator Microcontroller, LPC1114FN28, 1 pcs U2 This component is polarized. One side of the plastic package is flat and the other side is rounded.
LPCXpresso Experiment Kit - User’s Guide Page 23 Headers for U2 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 Shift register, 74HC595, 1 pcs U3 http://en.wikipedia.
LPCXpresso Experiment Kit - User’s Guide Page 24 Temperature sensor, LM75, 1 pcs U6 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.
LPCXpresso Experiment Kit - User’s Guide Page 25 5 Powering Options There are a couple of different options how to power the experiments.
LPCXpresso Experiment Kit - User’s Guide Copyright 2013 © Embedded Artists AB Page 26 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.
LPCXpresso Experiment Kit - User’s Guide Page 27 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.
LPCXpresso Experiment Kit - User’s Guide Figure 2 – LPCXpresso Experiment Kit PCB with Component Designators Copyright 2013 © Embedded Artists AB Page 28
LPCXpresso Experiment Kit - User’s Guide Page 29 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.
LPCXpresso Experiment Kit - User’s Guide 7.2.1 Page 30 Lab 1a: Control LED We will start with controlling LED1 in the schematic, which is 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 PIO0_2 on the LPCXpresso LPC1115 board.
LPCXpresso Experiment Kit - User’s Guide Page 31 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 Figure 6 – Breadboard Connections for LED1 (breadboard view) Figure 7 below illustrates how it can look like in reality.
LPCXpresso Experiment Kit - User’s Guide Page 32 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 I = (Vsupply – Vleddrop) / R.
LPCXpresso Experiment Kit - User’s Guide - SSEL0, a control signal for peripheral block SSP - CT16B0_CAP0, an input signal to 16-bit timer #0 Page 33 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 PIO0_2, have a pull-up resistor enabled, input hysteresis disabled and to be a standard push/pull GPIO output (if defined as an output).
LPCXpresso Experiment Kit - User’s Guide Page 34 Note that registers GPIO0DIR and GPIO0DATA are accessed as LPC_GPIO0->DIR and LPC_GPIO0->DATA, respectively. Below is the two statements needed to first set PIO0_2 to an output and then pull the output low. This will turn the LED on. // Set PIO0_2 as an output LPC_GPIO0->DIR = LPC_GPIO0->DIR | (0x1<<2); // Turn LED1 on = set PIO0_2 pin low, i.e.
LPCXpresso Experiment Kit - User’s Guide Page 35 Include a file called type.h in all program files. The main content of the file is presented below: #if defined ( __GNUC__ ) #include
LPCXpresso Experiment Kit - User’s Guide Page 36 * (or bits) within the GPIO data register. See the LPC11/13 user manual * for more details. * * (1<
LPCXpresso Experiment Kit - User’s Guide Page 37 /* * Delay by executing a given number of NOPs. */ void delayNops(uint32_t nops) { volatile uint32_t i; for (i = 0; i < 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.
LPCXpresso Experiment Kit - User’s Guide 7.3 Page 38 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 reflects 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_17-KEY.
LPCXpresso Experiment Kit - User’s Guide Page 39 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 Experiment Kit - User’s Guide - RTS, a control output signal for peripheral block UART - CT32B0_CAP0, an input signal to 32-bit timer #0 Page 40 By default, 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.
LPCXpresso Experiment Kit - User’s Guide 7.3.2 Page 41 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 LPC111x user’s manual, chapter 12.4.1 – Write/read data operations. In short, the LPC_GPIOx->DATA register can be accessed on many different addresses. The address used to access the register determines which bit(s) that is/are accessed.
LPCXpresso Experiment Kit - User’s Guide Page 42 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 (and hence the buzzer).
LPCXpresso Experiment Kit - User’s Guide Page 43 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).
LPCXpresso Experiment Kit - User’s Guide Page 44 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 PIO0_7 is also connected to a LED on the LPCXpresso board.
LPCXpresso Experiment Kit - User’s Guide Page 45 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.
LPCXpresso Experiment Kit - User’s Guide 7.4 Page 46 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. 7.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.
LPCXpresso Experiment Kit - User’s Guide Page 47 //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).
LPCXpresso Experiment Kit - User’s Guide Page 48 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. 7.4.
LPCXpresso Experiment Kit - User’s Guide 7.5 Page 49 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.
LPCXpresso Experiment Kit - User’s Guide Page 50 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: 0x0AC0FFEE in hexadecimal notation. The table below illustrates how the bytes are stored differently between a big and little Endian system. Memory address n n+1 n+2 n+3 Big-endian 0x0A 0xC0 0xFF 0xEE Little-endian 0xEE 0xFF 0xC0 0x0A Now think of a solution how to test this.
LPCXpresso Experiment Kit - User’s Guide 7.5.2 Page 51 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 needed libraries #include
LPCXpresso Experiment Kit - User’s Guide Page 52 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.
LPCXpresso Experiment Kit - User’s Guide 7.6 Page 53 Read an Analog Input In this experiment you will learn how to convert an analog signal 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.
LPCXpresso Experiment Kit - User’s Guide Page 54 Figure 23 – Trimming Potentiometer on Schematic Page 4 Begin with building the breadboard circuit below. 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.
LPCXpresso Experiment Kit - User’s Guide Page 55 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. //Include needed libraries #include ... //Define constants #define AIN0 0 ...
LPCXpresso Experiment Kit - User’s Guide 7.6.2 Page 56 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 AIN0 in the console whenever the change in value s large than 2% of the full scale.
LPCXpresso Experiment Kit - User’s Guide Page 57 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 AIN0 and sort these values according to frequency in occurrence.
LPCXpresso Experiment Kit - User’s Guide 7.7 Page 58 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.
LPCXpresso Experiment Kit - User’s Guide Page 59 possible by increasing the number of iterations but the trade-off is lower frequency 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<100; loopCounter++) { if (loopCounter == wantedDutyCycle) //Set output low ...
LPCXpresso Experiment Kit - User’s Guide Page 60 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? __________________________ 7.7.4 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.
LPCXpresso Experiment Kit - User’s Guide 7.8 Page 61 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.
LPCXpresso Experiment Kit - User’s Guide Page 62 Figure 30 – Breadboard Connections for RGB-LED Testing 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.
LPCXpresso Experiment Kit - User’s Guide 7.9 Page 63 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 further on. First, let’s have a look how a 7segment display works. The name 7-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.
LPCXpresso Experiment Kit - User’s Guide Page 64 Figure 34 – Different LED Displays 7.9.1 Lab 8a: Test 7-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.
LPCXpresso Experiment Kit - User’s Guide Page 65 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 LED5: LED1 (GPIO_4-LED-SSEL) corresponds to segment A LED2 (GPIO_8-LED-SSEL) corresponds to segment B LED3 (GPIO_9-LED-SSEL) corresponds to segment C GPIO_36 controls segment D GPIO_37 controls segment E LED6 (GPIO_23-LED) corresponds to segment F LED7 (GPIO_22-LED) correspond
LPCXpresso Experiment Kit - User’s Guide 7.9.3 Page 66 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.
LPCXpresso Experiment Kit - User’s Guide Figure 38 – 7-segment Display, LED9, on Schematic Page 4 Figure 39 – Breadboard Connections for Dual Digit 7-segment Display Copyright 2013 © Embedded Artists AB Page 67
LPCXpresso Experiment Kit - User’s Guide Page 68 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 ...
LPCXpresso Experiment Kit - User’s Guide Figure 41 – 7-segment Display, LED9, with Shift Register on Schematic Page 4 Figure 42 – Breadboard Connections for Dual Digit 7-segment Display with Shift Register Copyright 2013 © Embedded Artists AB Page 69
LPCXpresso Experiment Kit - User’s Guide Page 70 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 ) { uint8_t bitCnt; //Pull SCK and MOSI low, pull SSEL low ... //wait 1us ...
LPCXpresso Experiment Kit - User’s Guide Page 71 7.10 Work with a Timer In this experiment you will learn how to work with a hardware timer. 7.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.
LPCXpresso Experiment Kit - User’s Guide Page 72 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.
LPCXpresso Experiment Kit - User’s Guide Page 73 ** ** Parameters: cycleLength: set PWM cycle length in microseconds ** ** Returned value: None ** *****************************************************************************/ void initPWM(uint16_t cycleLengthInUs) { LPC_SYSCON->SYSAHBCLKCTRL |= (1<<8); /* Enable timer #1 (enable clock to block) */ //setup I/O pins to LPC_IOCON->PIO1_9 LPC_IOCON->PIO1_9 LPC_IOCON->PIO1_10 LPC_IOCON->PIO1_10 be MAT-outputs &= ~0x07; |= 0x01; &= ~0x07; |= 0x02; /* 16-bit t
LPCXpresso Experiment Kit - User’s Guide Page 74 uint32_t matchValue; matchValue = (LPC_TMR16B1->MR2 * (100 – value)) / 100; if (channel == 0) LPC_TMR16B1->MR0 = matchValue; else if (channel == 1) LPC_TMR16B1->MR1 = matchValue; } 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.
LPCXpresso Experiment Kit - User’s Guide Page 75 ** Function name: playNote ** ** Descriptions: Initialize 16-bit timer #1 for PWM generation ** ** Parameters: noteInUs: Period time (in microseconds) for tone ** durationMs: Length of tone (in milliseconds) ** ** Returned value: None ** *****************************************************************************/ void playNote(uint16_t noteInUs, uint16_t durationMs) { stopPWM(); initPWM(noteInUs); /* Setup to generate a PWM signal with cycle time = note *
LPCXpresso Experiment Kit - User’s Guide Page 76 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 position. 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.
LPCXpresso Experiment Kit - User’s Guide Figure 45 – Breadboard with Servo Motor Copyright 2013 © Embedded Artists AB Page 77
LPCXpresso Experiment Kit - User’s Guide Page 78 7.12 Work with a Serial Bus – SPI In this experiment you will learn how to work 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 masterslave concept where one unit is a master and controls the communication. The other end is the slave.
LPCXpresso Experiment Kit - User’s Guide Page 79 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.
LPCXpresso Experiment Kit - User’s Guide Page 80 /***************************************************************************** ** Function name: SSP0Init ** ** Descriptions: SSP port #0 initialization routine ** Note that GPIO control of SSEL signal is not done, must ** be done separately.
LPCXpresso Experiment Kit - User’s Guide Page 81 dummy = LPC_SSP0->DR; } } /***************************************************************************** ** Function name: SSP0Receive ** Descriptions: the module will receive a block of data from ** the SSP, the 2nd parameter is the block length.
LPCXpresso Experiment Kit - User’s Guide Page 82 MISO 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 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.
LPCXpresso Experiment Kit - User’s Guide Page 83 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.
LPCXpresso Experiment Kit - User’s Guide Page 84 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.
LPCXpresso Experiment Kit - User’s Guide Page 85 /* RDSR status bit definition */ #define RDSR_RDY 0x01 #define RDSR_WEN 0x02 #define #define #define #define SSEL_GPIO_8_PORT SSEL_GPIO_8_PIN SSEL_HIGH SSEL_LOW PORT2 0 1 0 /***************************************************************************** ** Function name: spiE2PROMread ** Descriptions: This function will read bytes from the SPI E2PROM ** parameters: address in memory region, buffer pointer and block length ** Returned value: None ** *******
LPCXpresso Experiment Kit - User’s Guide Page 86 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.
LPCXpresso Experiment Kit - User’s Guide Page 87 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.
LPCXpresso Experiment Kit - User’s Guide Page 88 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_IRQn); It is also possible to 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.
LPCXpresso Experiment Kit - User’s Guide 7.13.1 Page 89 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 PIO0_2 and one push-button connected to PIO1_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.
LPCXpresso Experiment Kit - User’s Guide 7.13.2 Page 90 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).
LPCXpresso Experiment Kit - User’s Guide 7.13.3 Page 91 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). Study the code framework below.
LPCXpresso Experiment Kit - User’s Guide Page 92 /***************************************************************************** ** Function name: main ** Descriptions: The main function ** Parameters: None ** Returned value: None ** *****************************************************************************/ void main (void) { /* initialize GPIO as needed */ ...
LPCXpresso Experiment Kit - User’s Guide 7.13.5 Page 93 Lab 12e: Control Dual Digit 7-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).
LPCXpresso Experiment Kit - User’s Guide Page 94 7.14 Work with a Serial Bus – I2C 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 I2C bus for short. It is a multi-master bus for (relatively) low-speed peripherals.
LPCXpresso Experiment Kit - User’s Guide Page 95 I2CRead() – this function perform a read operation. The function has three parameters. The first is the slave address to communicate with. The second is a buffer pointer to where the read data is copied. The third parameter is the number of bytes to read. I2CWrite() – this function perform a write operation. The function has three parameters. The first is the slave address to communicate with.
LPCXpresso Experiment Kit - User’s Guide 7.14.2 Page 96 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.
LPCXpresso Experiment Kit - User’s Guide Page 97 *****************************************************************************/ void main (void) { /* initialize I2C as needed */ I2CInit( I2CMASTER, 0 ); /* enter forever loop */ while(1) { /* read temperature and print result */ ... /* wait 3 seconds */ ... } } Place the LM75 related code in file lm75.c. 7.14.3 Lab 13c: Control LEDs via PCA9532 In this experiment a GPIO expansion chip, PCA9532, shall be used.
LPCXpresso Experiment Kit - User’s Guide Page 98 #define LS_MODE_ON 0x01 #define LS_MODE_BLINK0 0x02 #define LS_MODE_BLINK1 0x03 /****************************************************************************** * Local variables *****************************************************************************/ static uint16_t blink0Shadow = 0; static uint16_t blink1Shadow = 0; static uint16_t ledStateShadow = 0; /****************************************************************************** * Local Functions **
LPCXpresso Experiment Kit - User’s Guide Page 99 blink1Shadow &= (~(ledOffMask) & 0xffff); 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.
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.
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.
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 terminal applications: TeraTerm (which is recommended), http://sourceforge.jp/projects/ttssh2/files PuTTY, http:///www.chiark.greenend.org.uk/~sgtatham/putty/ Terminal by Bray, http://sites.google.
LPCXpresso Experiment Kit - User’s Guide Page 103 Figure 61 – TeraTerm Configuration Step 2 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.
LPCXpresso Experiment Kit - User’s Guide Page 104 Have a look in chapter 13 - LPC111x/LPC11Cxx 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 in setting the bit rates.
LPCXpresso Experiment Kit - User’s Guide Page 105 ** Function name: UARTSendChar ** ** Descriptions: Send a byte/char of data to the UART 0 port ** ** parameters: byte to send ** Returned value: None ** *****************************************************************************/ void UARTSendChar(uint8_t toSend) { /* THRE status, contain valid data */ while ( !(LPC_UART->LSR & LSR_THRE) ) ; LPC_UART->THR = toSend; } /***************************************************************************** ** Functi
LPCXpresso Experiment Kit - User’s Guide 7.15.1 Page 106 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, uint16_t length) functions. Create a small program that makes use of these transmission functions. Also let the program echo every received character.
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.
LPCXpresso Experiment Kit - User’s Guide Page 108 { uint32_t Fdiv; uint32_t regVal; NVIC_DisableIRQ(UART_IRQn); LPC_IOCON->PIO1_6 LPC_IOCON->PIO1_6 LPC_IOCON->PIO1_7 LPC_IOCON->PIO1_7 &= |= &= |= ~0x07; 0x01; ~0x07; 0x01; /* UART I/O config */ /* UART RXD */ /* UART TXD */ /* Enable UART clock */ LPC_SYSCON->SYSAHBCLKCTRL |= (1<<12); LPC_SYSCON->UARTCLKDIV = 0x1; /* divided by 1 */ LPC_UART->LCR = 0x83; /* 8 bits, no Parity, 1 Stop bit */ regVal = LPC_SYSCON->UARTCLKDIV; Fdiv = (((SystemCoreClock/LPC_
LPCXpresso Experiment Kit - User’s Guide Page 109 /* Read LSR will clear the interrupt */ Dummy = LPC_UART->RBR; //Dummy read on RX to clear interrupt, then bail out return; } if (LSRValue & LSR_RDR) /* Receive Data Ready */ { /* If no error on RLS, normal ready, save into the data buffer.
LPCXpresso Experiment Kit - User’s Guide Page 110 uint32_t tmpHead; //calculate head index tmpHead = (txHead + 1) & TX_BUFFER_MASK; //wait for free space in buffer while(tmpHead == txTail) ; //disable TX IRQ LPC_UART->IER &= ~IER_THRE; if(txRunning == TRUE) { txBuf[tmpHead] = toSend; txHead = tmpHead; } else { txRunning = TRUE; /* Extra check - should not be needed: THRE status, contain valid data */ while ( !(LPC_UART->LSR & LSR_THRE) ) ; LPC_UART->THR = toSend; } //enable TX IRQ LPC_UART->IER |= IER_THR
LPCXpresso Experiment Kit - User’s Guide Page 111 Place the UART related 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).
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 RF module interface is found on schematic page 7, also replicated in the picture below.
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 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.
LPCXpresso Experiment Kit - User’s Guide Page 114 volatile uint32_t ms_ticks = 0; /***************************************************************************** ** Function name: SysTick_Handler ** ** Descriptions: Interrupt handler. Updates the ms_ticks variable to hold ** the number of milliseconds since start. This will be ** reasonably accurate and is used by the Xbee driver to ** handle timeouts.
LPCXpresso Experiment Kit - User’s Guide Page 115 ** Function name: xbeeTxStatus ** ** Descriptions: Received data callback. Called when data has been received ** by the Xbee node.
LPCXpresso Experiment Kit - User’s Guide Page 116 //Set LED1 pin as output ... //Set 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 - COORDINATOR\r\n"); err = xbee_init(XBEE_COORDINATOR, &callbacks); #else printf("XBee demo - NODE\r\n"); err = xbee_init(XBEE_END_DEVICE, &callbacks); #endif if (err != ERR_OK) { printf("Failed to initialize Xbee. Error code %d. Aborting...
LPCXpresso Experiment Kit - User’s Guide Page 117 If you have access to more than two XBee modules test what happens when they are all powered. 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.
LPCXpresso Experiment Kit - User’s Guide Page 118 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.
LPCXpresso Experiment Kit - User’s Guide Page 119 /***************************************************************************** ** Function name: hasPattern ** ** Descriptions: Tests if pBuf starts with pPattern.
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 > 10000) { // normalize minutes to 6 decimal places *pDegree /= (div / 10000); } } /***************************************************************************** ** Function name: parseUTC ** ** Descriptions: Extracts the UTC time string in hhmmss.sss, ** ignoring the .
LPCXpresso Experiment Kit - User’s Guide Page 121 ** ** Descriptions: Reads and parses the next set of GPS data.
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.
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.
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. 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 setup its own list of pins depending on needs.
LPCXpresso Experiment Kit - User’s Guide Page 125 // Purple => 32~47 ... // Cyan => 48~63 ... // Red => 64~79 ... // Green => 80~95 ... // Blue => 96~111 ... // Black => 112~127 ...
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 boards. 7.18.
LPCXpresso Experiment Kit - User’s Guide Page 127 if (i == 4 || i == 5) LPC_GPIO2->FIOPIN &= ~led_mask[i]; else LPC_GPIO0->FIOPIN &= ~led_mask[i]; } else { if (i == 4 || i == 5) LPC_GPIO2->FIOPIN |= led_mask[i]; else LPC_GPIO0->FIOPIN |= led_mask[i]; } } } 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.
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. 7.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.
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. 7.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.
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. Figure 71 – Web Page Screenshot The page is continuously updated - page count is increasing and the colored bar is changing value.
LPCXpresso Experiment Kit - User’s Guide Page 131 4) Remove the call to vStartSPIInterfaceToSDCardTask() from main() in FreeRTOS-Plus-Demo2\Source\main.c. This is needed to prevent the demo from crashing as a result of a missing SD card. 5) Modify the FreeRTOS-Plus-Demo-2\Source\FreeRTOSConfig.h to get unique addresses: /* MAC address configuration.
LPCXpresso Experiment Kit - User’s Guide Figure 73 – Telnet Server Screenshot Test the three available commands: help, task-stats and run-time-stats.
LPCXpresso Experiment Kit - User’s Guide Page 133 7.21 Differences between LPCXpresso LPC111x and LPC1114 in DIL28 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).
LPCXpresso Experiment Kit - User’s Guide Page 134 5 push-buttons, signals GPIO_17-KEY, GPIO_18-KEY and GPIO_35-KEY are only connected 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.
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.
LPCXpresso Experiment Kit - User’s Guide 8.6 Page 136 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.
LPCXpresso Experiment Kit - User’s Guide Page 137 8.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 using the E2PROM, which is accessible over the I2Cbus. 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.
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.
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], http://www.nxp.
LPCXpresso Experiment Kit - User’s Guide Page 140 1) Browse and select archived project file 2) Select all subprojects in list 3) Import projects Figure 76 – LPCXpresso IDE Import Archived Project Window All projects are now imported.
LPCXpresso Experiment Kit - User’s Guide 9.2 Page 141 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.
LPCXpresso Experiment Kit - User’s Guide 9.3 Page 142 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.
LPCXpresso Experiment Kit - User’s Guide Page 143 When the 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 Target Start/Resume Execution (F8) Pause Execution Stop debug session 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).
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. Double-click in left margin to set breakpoint. Double-click again to remove.
LPCXpresso Experiment Kit - User’s Guide Page 145 Call stack, which indicates the call structure to get to the point where the program is currently stopped. Currently stopped at line #34 in main() 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.
LPCXpresso Experiment Kit - User’s Guide Page 146 Call stack, which indicates the call structure to get to the point where the program is currently stopped. Currently stopped at line #34 in main() Variable view Hover cursor over variable and a variable window will pop up, showing the current value. 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.
LPCXpresso Experiment Kit - User’s Guide Page 147 Program Flash Icon 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.
LPCXpresso Experiment Kit - User’s Guide Page 148 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. 2) Find project top directory 3) Find “Debug” subdirectory Figure 87 – Browse to File to Download Copyright 2013 © Embedded Artists AB 4) Select either *.axf or *.
LPCXpresso Experiment Kit - User’s Guide Page 149 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.
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”. 1) Right click on *.axf or *.bin file 2) Select “Binary Utility” 3) Select “Program Flash” Figure 90 – LPCXpresso IDE Binary Utility 9.
LPCXpresso Experiment Kit - User’s Guide Page 151 1) Right-click on project to copy and select “Copy”. Figure 91 – Copy Existing Project 2) Right-click on empty space in Project Explorer and select “Paste”. Figure 92 – Paste Project 3) Give a name for the new project. Note, no spaces in project name. That can give problems later on when compiling and linking. Figure 93 – Copy Project and Rename 9.5 Common Problems In this section a number of common problems are listed.
LPCXpresso Experiment Kit - User’s Guide 9.5.1 Page 152 Error message: Failed on chip 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.
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) http://ics.nxp.com/products/lpc1000/lpc1100/lpc11cxx/ [2] ARM Processor Documentation Documentation from ARM can be found at: http://infocenter.arm.com/.