ABSTRACT

Modern embedded systems generally demand quite a bit from a single piece of silicon. For example, in the 1990s, cell phones were used for making phone calls and little else. Today, their uses range from checking e-mail to watching your favorite movie. The industry also geared up to include GPS on smartphones, so that when you miss that turn while driving down the road (probably because you were arguing with your smartphone), you can also ask it for directions. To build such systems, the hardware has to include more features in silicon, and the software has to learn to talk to those new features. SoC designs are packing ever more devices onto one die. Even off-the-shelf microcontrollers are getting more elaborate, with small, 32-bit processors built to control different types of serial interfaces, e.g., UARTs, I2C, and CAN; analog devices like temperature sensors and analog comparitors; and motion controllers for motors and servos. How are all of these attached to a single processor? In this chapter, we’re going to look at three particular microcontrollers, the LPC2104 and the LPC2132 from NXP, and the TM4C123GH6PM from TI, along with three very useful peripherals, the UART, general-purpose I/O (GPIO), and the digital-to-analog converter (DAC). The UART is a relatively simple serial interface, and we’ll program it to send character data to a window in the simulator. The DAC takes a 10-bit value and generates an output relative to a reference voltage. To show off our coding skills, the DAC will generate a sine wave from the sine table we created in Chapter 12. The last example uses an inexpensive evaluation module, the Tiva Launchpad, to continuously change the color of a flashing LED. In writing the three programs, we’re going to tie all of the elements from previous chapters into the code, including

• Subroutines and how they are written • Passing parameters • The ARM Application Procedure Call Standard (AAPCS) • Stacks • Q notation • Arithmetic • The ARM and Thumb-2 instruction sets

The best place to start is at the highest level-the SoC, or in our case, the microcontroller. Figure 16.1 shows the block diagram of the LPC2104 from NXP. You can

see the ARM7TDMI core at the top, and two main busses in the system: the AHB, a high-speed bus designed to have only a few bus masters attached to it, and the VPB, a slower bus designed to have many peripherals attached to it. Between the two busses is a bridge. Fortunately for the programmer, you don’t have to focus too much on the internal hardware design, but it is important to know how the peripherals are attached and what type of interface they have (i.e., what pins go with which peripheral). The LPC2104 includes a few different serial interfaces, along with some timers, some general-purpose I/O, two UARTs, and some on-chip memory. Specifically, we’re going to use UART0 to write some character data out of the part.