29

CHAPTER

Microcontrollers

A MICROCONTROLLER IS A SINGLE IC THAT CONTAINS WHAT WOULD HAVE PASSED FOR MOST OF A home computer in the 1980s. It includes a simple 8-bit (sometimes more) microprocessor, nonvolatile flash memory that holds a program to be run, and random access memory (RAM) to hold temporary data and values. Many microcontrollers also have some electrically erasable programmable read-only memory (EEPROM) that is used for nonvolatile storage of program data. That is, unlike normal RAM, the contents are not lost when the microcontroller is not powered. A microcontroller also has numerous general-purpose input/output (GPIO) pins that you can use to interface with sensors, switches, LEDs, displays, etc. It is essentially a computer on a chip.

Benefits

The benefit of having a single microcontroller chip instead of many separate logic chips is cost savings. You will find microcontrollers in almost any item of consumer electronics that you care to mention. You will find them in everything from an electric toothbrush to a car (which probably has tens of microcontrollers in it).

Figure 29-1 shows how a typical microcontroller chip is organized. The central processing unit (CPU) fetches instructions one at a time from the flash memory. These instructions together form the program running on the microcontroller and include things such as:

images

29-1   Essential components of a microcontroller.

•   Add numbers together

•   Compare numbers

•   Jump to another part of the program depending on a comparison

•   Read a digital input

•   Write a digital output

Microcontrollers perform things one step at a time and use a clock to trigger each step. The clock is an oscillator of generally 1 MHz to 20 MHz for a low-power microcontroller. Each time the clock ticks over, another instruction is performed.

Microcontrollers interact with the world through their general-purpose input/output (GPIO) pins. These can be configured to be inputs or outputs, just like the inputs and outputs to logic gates described in Chap. 28 “Digital Basics.” However, because what links the pins is software rather than, say, a hardware AND gate, the microcontroller is almost infinitely flexible, limited only by its speed, memory, and the ability of you, the programmer, to write the program that controls it.

Microcontrollers generally have a method of converting between continuous analog signals and the on/off world of digital electronics. This means that their use is not restricted to just the digital, but they can also be pressed into service for some analog electronic applications.

A special subspecies of microcontroller called the digital signal processing (DSP) microcontroller is optimized for such analog activities. An echo effects box for a guitar or even tone controls for audio amplifiers are often implemented by digitizing an analog signal, doing some math, and then converting the digital value back into an analog signal again.

The downside of all this flexibility is that the microcontroller is not made knowing how to perform all this magic; it must be programmed, and so the person wanting to use it has to learn a little computer programming as well as electronics. The programs for a microcontroller are generally short and simple, and you will learn a lot more about this in the next chapter in which we look at the extremely popular microcontroller board, the Arduino.

Microcontroller boards, such as the Arduino, combine a microcontroller chip with supporting components like voltage regulators and a USB programming interface so that you can get programs onto your microcontroller without having to have separate programming hardware.

All Shapes and Sizes

Microcontrollers are available in all sorts of package sizes, from 3 pins to hundreds of pins, so you can pick a device with the features, performance, price, and number of GPIO pins that you need for your design. In fact, there are so many different devices that it is not easy to navigate the vast array of devices on offer. To simplify things a little, devices are often grouped into families of microcontrollers that have the same basic structure and programming instructions, but have different numbers of pins and different quantities of flash memory for program storage.

The ATtiny family of microcontrollers from the Atmel chip manufacturer are typical of low-end microcontrollers. Table 29-1 shows the features of these common microcontrollers. The guide prices are somewhat arbitrary but are based on the price for one chip at the time of writing.

Table 29-1.    ATtiny Microcontrollers

images

General-Purpose Input/Output (GPIO) Pins

The clever part of a GPIO pin is the “general purpose” part. This means that your program running on the microcontroller can decide whether the pin should be an input or an output and also, if it is an input, whether or not to enable a built-in resistor to pull the input up to the positive supply of the microcontroller.

Figure 29-2 is a simplified schematic diagram for a typical GPIO pin. The output drive is push-pull. This means that when configured as an output, the pin can either sink (receive) or source current, although generally only between 10 mA and 40 mA in each direction. In addition, control logic allows the whole output to be disabled so that the pin can act as a digital input.

images

29-2   Simplified schematic of a GPIO pin.

Microcontrollers often have some pins that can be used as analog inputs. This requires the pin to be connected to a comparator; by comparing the voltage at the input to a series of different voltages generated within the microcontroller, the pin can be used to measure a voltage.

Digital Outputs

The most common thing to do with a GPIO pin is to have it act as a digital output. That is, to turn something on and off. This could be something connected directly to the GPIO pin, like an LED, or it could use a transistor or relay to provide more current or voltage, or both, to whatever is being controlled.

Figure 29-3 shows how you would typically connect the GPIO pin of a microcontroller to an LED. The series resistor is necessary because GPIO pins can typically supply only a few tens of milliamps.

images

29-3   Lighting an LED with a digital output.

Setting the digital output HIGH will set the pin at the supply voltage for the microcontroller (5 V or 3.3 V) and setting it LOW will set it to 0 V.

Most microcontrollers can operate at 5-V or 3.3-V logic levels (5-V micros will nearly always work with 3.3-V ones, but the reverse is not always true). In this case, if you assume that the microcontroller is operating at 5 V, the resistor has a value of 470 ohms, and the LED has a forward voltage of 2 V, then I = E/R = (5 – 2 )/470 = 6.28 mA. That’s enough for the LED to light reasonably brightly.

Digital Inputs

When you configure a GPIO pin to be a digital input, it is because you want the microcontroller to do something in response to that input. So the digital input might be connected to a push switch or a motion detector sensor that has a digital output.

When a microcontroller “reads” a digital input, the input will either be HIGH or LOW. HIGH usually means over half of the microcontroller’s supply voltage (2.5 V for a 5-V microcontroller and 1.65 V for a 3.3-V microcontroller) and LOW is below that threshold.

It’s fine to connect a 3.3-V digital output to a 5-V input, as the 3.3-V HIGH voltage will still be above the 2.5-V input threshold, but you must not connect a 5-V digital output to a 3.3-V digital input unless the input is described as “5-V tolerant.” It is not uncommon for a 3.3-V microcontroller to have some 5-V-tolerant inputs just to make it easier to interface them in systems with multiple supply voltages.

Because microcontrollers can implement all sorts of complex logic, there is usually no need to connect a switch to a microcontroller that is any more complex than a simple momentary action, push-to-make switch. Such switches are arranged to switch to ground, using a pull-up resistor that keeps the input high until it is connected to ground by the switch. Figure 29-4A shows a switch connected to a digital input using the internal pull-up resistor of the microcontroller, and Fig. 29-4B shows a similar switch using an external pull-up resistor.

images

29-4   Connecting a switch to a digital input.

To avoid the need for an external pull-up resistor, the pin logic for a microcontroller normally includes a built-in pull-up resistor that can be enabled or disabled from the program running on your microcontroller. The value of this resistor is often specified as a range rather than an exact value, and this might typically be 30 kilohms to 50 kilohms. Under most circumstances this will work just fine, but if you have a long lead to your switch, then you may need to supply your own external and much smaller value of resistor, say, 270 ohms. In this case, the resistor should be connected as shown in Fig. 29-4B.

Switch contacts tend to bounce. That is, when you press the button, you do not get a single clean closure of the contacts, but rather the contacts close and open a number of times in quick succession. For some applications, this does not matter, but if, say, alternate presses of the switch button are used by the microcontroller to turn something else on and off, then if the digital input receives an even number of bounces in rapid succession, it could seem like nothing happened when the button was pressed.

Debouncing switches for use in digital circuitry without a microprocessor requires hardware debouncing; however, if the switch is connected to a microcontroller, then it can be debounced using software without the need for any extra components. You will see an example of how to do this with an Arduino microcontroller board in Chap. 30.

An ordinary digital input normally requires the program running on the microcontroller to repeatedly read the value of the digital input until it changes. This means that some very short pulses on a digital input might be missed because they went high then low again before the program on the microcontroller could register the change. This won’t matter for pressing a button, but for such very short-pulsed inputs (microseconds), then some of the microcontroller’s GPIO pins can be designated as “interrupts.” These are guaranteed to be registered by the microcontroller and cause your program to stop whatever it was doing and instead run an interrupt service routine.

PWM Outputs

A few microcontrollers provide true analog outputs. These allow the output to be varied in a large number of steps (often 1024 or 4096) between 0 and the microcontroller supply voltage. These microcontrollers are the exception though, and in general, microcontrollers use a technique called PWM (see the section “The Class D Amplifier” in Chap. 26 and the section “Pulse-Width Modulation” in Chap. 27) to provide something that approximates an analog output.

Rather than using PWM to transmit a signal, as described in Chap. 27, or to amplify an audio signal, as described in Chap. 26, a microcontroller uses low-frequency PWM to control the power to, say, a motor or LED, controlling its speed or brightness by altering the duration of the pulses powering the output device.

Figure 29-5 shows how PWM works. If the pulses are short (say, high for just 5% of the time), then only a small amount of energy is delivered with each pulse. The longer the pulse, the more energy is supplied to the load. When powering a motor, this will control the speed at which the motor rotates. When driving an LED using PWM, the brightness appears to change. In fact, an LED can turn on and off millions of times per second, and so the PWM pulses will become pulses of light. The human eye and brain do the averaging trick for us, making the brightness of the LED vary with the pulse length.

images

29-5   How PWM works.

Most microcontrollers have hardware PWM available on some, or all, of their pins. If they do not, then PWM can be implemented in software quite easily. The pulse frequency of the PWM outputs is generally around 500 Hz but is also configurable to be higher or lower, depending on the application.

Analog Inputs

Converting a voltage (between 0 and the microcontroller supply voltage) to a number for use by the program running on the microcontroller requires the use of an A/D converter (analog-to-digital converter), perhaps more often called an ADC these days.

Nearly all microcontrollers use a technique called successive approximation to convert the analog voltage to a digital value. This technique uses a digital-to-analog converter (DAC), which converts a digital value to an analog voltage, and a comparator, as shown in Fig. 29-6.

images

29-6   Successive approximation ADC.

The GPIO pin being used as an analog input is connected to one input of a voltage comparator. The other input of the comparator is connected to the output of a DAC. The DAC generates an analog voltage depending on the binary number on D0 to D9 supplied by the microcontroller. So, if this value is 0 (D0 to D9 all low) then the output voltage of the DAC will be 0. If, on the other hand, D0 to D9 are all high (the maximum value), then the output voltage from the DAC is the microcontroller supply voltage.

It’s the comparator’s job to provide feedback to the microcontroller in a game of “higher/lower” to gradually home in on a number input to the DAC that just balances the input from the GPIO pin. This takes a number of steps. In fact, the number of steps is equal to the number of bits input to the DAC (10 in Fig. 29-6).

The trick is to start with the highest value bit (D9) in Fig. 29-6. Assuming a 5-V microcontroller, then if bit D9 is high and all the other bits are low, then the output voltage of the DAC will be 2.5 V (half of 5 V). If the GPIO input voltage is above this, then the comparator output will be high. If it is less, then the output of the comparator will be low. So, if the output of the comparator (Result in Fig. 29-6) is high, the microcontroller leaves bit D9 set and moves on to the next bit D8, and applies the same test using the comparator. This is repeated for the other bits of the DAC.

Microcontrollers have different bit resolutions of ADC. The example here is 10 bits, which is typical of many microcontrollers and is what is used in the ATmega328 microcontroller used by the Arduino. Some microcontrollers have 8- or 12-bit resolutions. The more bits of resolution, the more precise the reading, but the longer it takes to make.

An 8-bit resolution ADC gives a value between 0 and 255 (28 – 1). So, a voltage of 3 V at the GPIO pin of a 5-V microcontroller would result in a reading of 3/5 × 255 = 153. For a microcontroller with 10-bit ADC, the range of value would be 0 to 1023 (210 – 1).

Figure 29-7 shows how you can attach a potentiometer to the analog input of a microcontroller so that the position of the potentiometer’s knob can be read by the program running on the microcontroller.

images

29-7   Attaching a potentiometer to the analog input of a microcontroller.

The resistance of the potentiometer needs to be much lower than the input impedance of the comparator. Most microcontroller comparators will have an input impedance in the megohm range, so a potentiometer of perhaps 10 k should be fine.

Dedicated Serial Hardware

Most microcontrollers have one or more serial data interfaces. At least one such interface is needed to program the microcontroller, and generally this is the Serial Peripheral Interface (SPI). This can be used both for programming the microcontroller and also as an interface to other peripheral chips or microcontrollers, once the microcontroller has been programmed.

Although you can simulate (sometimes called “bit-banging”) all of the serial communication mechanisms described below using software, microcontrollers will provide hardware implementations of some of the interface types that make programming the microcontroller easier and higher speed communication possible.

Serial Peripheral Interface (SPI)

SPI uses four data lines for communication. Figure 29-8 shows how a number of peripherals can be connected to the data “bus.” Note that there can be only one master device that is responsible for controlling the other devices.

images

29-8   SPI allows two or more peripherals to be connected to the data “bus.”

Each of the slave devices has a dedicated slave select (SS) line, and the master enables just the device it wants to communicate with. Two data lines are needed because separate lines are used for each direction of communication. Master Out Slave In (MOSI) carries the data from the master to the slave device, and Master In Slave Out (MISO) the reverse. A separate clock signal synchronizes the data transmission.

I2C

Inter-Integrated Circuit (I2C), also sometimes known as two-wire interface (TWI), serves much the same purpose as SPI, although it has two wires for data rather than the four of SPI. I2C is often used by displays and other peripheral modules that are designed to be connected to a microcontroller.

The two data lines of I2C are open-drain connections that operate as both inputs and outputs at the microcontroller. They need pull-up resistors so that when not being driven low as an output, they are high. The protocol that controls the direction of data flow also ensures that the situation never occurs in which one end of the bus is connected to a digital output that is low and the other end to a digital output that is high.

Figure 29-9 shows how two microcontrollers might communicate with each other using I2C.

images

29-9   Microcontroller-to-microcontroller communication using I2C.

I2C devices are either masters or slaves, and there can be more than one master device per bus. In fact, devices are allowed to change roles, although this is not usually done.

The Serial Clock Line (SCL) data line is a clock and the other, the Serial Data Line (SDA), carries the data. The timing of these pins is shown in Fig. 29-10.

images

29-10   Timing diagram for I2C.

The master supplies the SCL clock. When there is data to be transmitted, the sender (master or slave) takes the SDA line out of tri-state and sends data as logic highs or lows in time with the clock signal. When transmission is complete, the clock can stop, and the SDA pin is taken back to tri-state.

Serial

Many microcontrollers include hardware for yet another type of interface called Serial. This is an old standard with its roots dating back to the days of teletypes. Some computers can still be found that have Serial ports. In the “old days,” people attached modems to them for communicating over phone lines with other computers.

The normal voltages used in the signals for Serial ports conform to the RS232 standard and use voltages that swing both positive and negative with respect to GND. This is not terribly convenient when using microcontrollers. For this reason, microcontrollers often use the same communication protocol, but at logic levels. This is called TTL Serial, or often just Serial. Let’s use a capital S to distinguish this type of communication from general serial communication.

Electrically, TTL Serial uses two data pins, Transmit (Tx) and Receive (Rx). It is not a bus, and the connection is point to point, so there are no problems of addressing different devices. If you want to connect more than one Serial device to your microcontroller, then the microcontroller will need more than one Serial port.

Another remnant from early computer history is the nomenclature around the bandwidth of serial connections. A serial connection has to be set to the same baud rate at both ends of the connection. The baud rate (see also Chap. 28) is the number of times that the signal can change state per second. This is taken to be the same as the bits transmitted per second of the data payload, but that does include start, stop, or possible parity bits, so the actual transmission of data in bits per second is a little slower than the baud rate. To simplify matching up the baud rates at each end of the connection, a set of standard baud rates is used: 110, 300, 600, 1200, 2400, 4800, 9600, 14,400, 19,200, 38,400, 57,600, 115,200, 128,000, and 256,000.

Of these, 1200 is probably the slowest baud rate commonly in use and many TTL Serial devices will not go as high as 115,200. Perhaps the most common rate is 9600 baud. Devices often default to this rate, but can be configurable to other rates.

As well as the baud rate, other parameters that define a Serial connection are the number of bits per word, the type of parity bit, and the number of start and stop bits. Almost universally, these are defined as 8, none, and 1 respectively, which often gets abbreviated to 8N1.

Bits are simply sent as high or low logic levels (Fig. 29-11). As there is no separate clock signal, timing is critical, so after the start bit, the receiver will sample at the appropriate rate until it has read the eight data bits and the one stop bit. The least significant bit of the data is sent first.

images

29-11   An example of TTL Serial.

When connecting two Serial devices together, you connect the Tx pin of one device to the Rx pin of the other and vice-versa. For some devices, such as GPS receivers, only one-way communication is needed, as the device just repeatedly transmits data. In this case, the link needs to be established in only one direction.

Most microcontrollers have built-in hardware for TTL Serial called a Universal Asynchronous Receiver Transmitter (UART).

USB

While electrically similar to RS232, Universal Serial Bus (USB) is one of the most complex interfaces around in terms of software and communication protocols. This complexity is because it can be used with full-sized computers with a vast array of peripherals, from keyboards and mice to printers and cameras. Fortunately, its use with microcontrollers is generally simplified.

While microcontrollers generally do not have USB hardware built in, most families of microcontrollers will have a member with USB hardware that allows the microcontroller to communicate with a PC or emulate a mouse or keyboard. In fact, even if the microcontroller does not have hardware USB support, a Serial interface and some slick software will normally allow the microcontroller to “talk” USB.

Microcontrollers are often used to implement USB peripherals, such as keyboards and mice. The USB connector has two power pins (GND and 5 V as well as two data pins D+ and D−). The USB standard dictates that a USB host (usually your computer) must supply 5 V and at least 500 mA on its supply terminals.

An Example—The ATtiny44

Figure 29-12 shows the pin connections of the ATtiny44 microcontroller taken from its datasheet. As you can see, each pin has a variety of roles. This is typical of a modern microcontroller in which flexibility is paramount.

images

29-12   The pinout of an ATtiny44.

Looking at Fig. 29-12, you can see that the only two pins that do not have multiple roles are pin 14 (GND) and pin 1 (VCC, the positive supply). The other pins are theoretically all available to be used as GPIO pins. The supply voltage can be anything between 2.7 V and 5.5 V.

The GPIO pins on the ATtiny44 are grouped into two ports, port A (PA) and port B (PB). Starting with the right side of the chip, pins 13 to 8 are labelled PA0 to PA5. These pins are all available for use as GPIO pins on port A. The other functions for those pins are indicated in parentheses. The pins PA0 to PA5 are also marked as ADC0 to ADC5. This indicates that all of those pins can be used as analog inputs.

Note that the SPI pins needed for programming (MOSI, MISO and USCK) can also be configured for use as GPIO pins.

On the left of the IC, you can see that pins 2 and 3 have the second function of XTAL1 and XTAL2. This allows you to connect a crystal between those pins to set the clock frequency of the microcontroller, which produces a much more accurate clock frequency than that provided by the internal resonator circuit of the microcontroller. This particular microcontroller will work with clock frequencies up to 20 MHz.

The choice between using the internal resonator circuit of the microcontroller for the clock frequency or sacrificing two GPIO pins for a more accurate clock frequency is made during the programming of the microcontroller chip.

Programming Languages

The machine code of a microcontroller is a series of instructions that tell it what to do. The instructions are not intended to be used directly by humans. Instead, the human programmer creates a text file containing a program written in a so-called high-level language on his/her main computer. This text file is then fed into a program called a compiler, which converts the high-level language into a machine code file that is installed into the flash memory of the microcontroller.

There are many programming languages that are used to program microcontrollers. The most common of these is the C programming language. C has the advantage that it is fairly easy to use, while still being relatively “close to the metal,” so that programs written with it generally compile down to be compact and efficient. This is something that you need when programming a microcontroller with its limited memory.

In the next chapter, you will learn a little C programming on a microcontroller.

Programming a Microcontroller

There are various ways of getting a program onto a microcontroller, and they all involve the use of a regular computer, and often specialized programming hardware, such as the AVR Dragon programmer shown in Fig. 29-13.

images

29-13   The AVR Dragon programmer.

This board has a zero insertion force (ZIF) socket on the left that holds the microcontroller IC while it is being programmed. On the right of Fig. 29-13, you can see the USB interface that is used to connect the programmer to your computer.

During programming, the microcontroller’s SPI pins are used to allow access to the microcontroller’s flash memory.

Programming hardware, like the AVR Dragon, can also be used to program microcontrollers that are already soldered into place on a PCB, using a method called In-Circuit Serial Programming (ICSP). Here, the SPI pins of the microcontroller are connected to header pins on the PCB so that they can be connected to programming hardware using a “programming cable.”

Another approach to programming microcontrollers is to program the microcontroller with a bootloader, using one of the methods described above. The bootloader runs each time that the microcontroller is restarted. It pauses for a fraction of a second to see if its Serial interface is being used to send it a new program. If it is, then it copies the received data into its flash memory and then restarts itself. Note that the bootloader is not destroyed in this process, so it can be used the next time a program needs to be uploaded.

Allowing the microcontroller to be programmed over Serial rather than SPI means that it can be programmed using hardware no more complex than a USB or Serial adaptor. The Arduino actually includes such a converter on board, so that all the hardware that you need to program an Arduino is a USB cable.

Quiz

Refer to the text in this chapter if necessary. A good score is 18 correct. Answers are in the back of the book.

1.  What’s the main purpose of flash memory in a microcontroller?

(a)  To store program variables

(b)  To store program code

(c)  To store charge

(d)  To interface with GPIO pins

2.  What’s the main purpose of RAM in a microcontroller?

(a)  To store program variables

(b)  To store program code

(c)  To store charge

(d)  To interface with GPIO pins

3.  Which of the following statements about GPIO pins is true?

(a)  Once a GPIO pin has been set to be an input or output, it cannot subsequently be changed.

(b)  GPIO pins can usually source and sink large currents.

(c)  GPIO pins can be switched between acting as an input to acting as an output while a program is running on the microcontroller.

(d)  GPIO pins normally operate at 10 V.

4.  Which of the following connections is not allowed because it could damage a microcontroller?

(a)  Connecting a 3.3-V digital output to a 5-V input

(b)  Connecting a 5-V digital output to a 3.3-V input

(c)  Connecting one digital output pin of a microcontroller to a digital input on the same microcontroller

(d)  Connecting a 1.5-V cell between GND and a digital input of a microcontroller

5.  Under which of the following circumstances would you use an external pull-up resistor on a digital input?

(a)  Every time you connect a switch to a digital input.

(b)  Whenever the lead between the digital input and the switch is long.

(c)  Whenever you connect a digital output from one microcontroller to the digital input of another.

(d)  When the digital input is on a 3.3V microcontroller.

6.  Which of the following voltages at a digital input is most likely to result in a logical HIGH being registered by the microcontroller?

(a)  2 V on a 5-V microcontroller

(b)  0 V on a 5-V microcontroller

(c)  2 V on a 3.3-V microcontroller

(d)  None of the above

7.  What current would flow through an LED with a forward voltage of 2 V and a series resistor of 1k (1000 ohms) driven by a 5-V digital output?

(a)  1 mA

(b)  2 mA

(c)  3 mA

(d)  4 mA

8.  Debouncing of switches is

(a)  only possible using hardware.

(b)  usually done using software.

(c)  never necessary.

(d)  None of the above

9.  How are interrupt inputs different from regular inputs?

(a)  They aren’t; they’re the same thing!

(b)  They use faster logic.

(c)  They use slower logic.

(d)  When interrupt inputs change signal level, they trigger an interrupt service routine.

10.  Which of the following statements about PWM is true?

(a)  PWM is the only method for producing an analog output from a microcontroller.

(b)  Microcontrollers generally use high frequencies for PWM (over 100 kHz).

(c)  A duty cycle of 100% in a PWM output from a 5-V microcontroller will produce an output voltage of 0 V.

(d)  A duty cycle of 100% in a PWM output from a 5-V microcontroller will produce an output voltage of 5 V.

11.  PWM control of an LED

(a)  changes the actual brightness of the LED.

(b)  changes the peak voltage across the LED.

(c)  changes the peak current through the LED.

(d)  changes the apparent brightness of the LED as interpreted by the human eye/brain.

12.  An 8-bit analog input to a microcontroller will be digitized into a number in the range

(a)  0 to 256.

(b)  0 to 1023.

(c)  0 to 4096.

(d)  0 to 255.

13.  What would be the digitized value of a 1-V input to an analog input of a 5-V microcontroller with an 8-bit ADC?

(a)  1

(b)  51

(c)  48

(d)  127

14.  Which of the following statements about SPI is true?

(a)  SPI is used as the programming interface for most microcontrollers.

(b)  SPI can only be used to connect one device to a microcontroller.

(c)  SPI is not clocked and requires accurate time for data transmission.

(d)  SPI is never used as the programming interface for a microcontroller.

15.  Which of the following statements about I2C is true?

(a)  I2C is used as the programming interface for most microcontrollers.

(b)  I2C can only be used to connect one device to a microcontroller.

(c)  I2C is not clocked and requires accurate time for data transmission.

(d)  I2C is never used as the programming interface for a microcontroller.

16.  Which of the following statements about TTL Serial is true?

(a)  TTL Serial is always used as the programming interface for microcontrollers.

(b)  A single TTL Serial connection can be connected to only one device at a time.

(c)  TTL Serial uses voltages that swing above and below 0 V.

(d)  TTL Serial is never used as the programming interface for a microcontroller.

17.  Which of the following baud rates is not commonly used with serial interfaces?

(a)  100

(b)  300

(c)  1200

(d)  9600

18.  Which of the following statements about USB is true?

(a)  Some microcontrollers include a hardware USB interface.

(b)  USB host devices provide 3-V power.

(c)  The USB standard states that USB peripherals can draw a maximum of 100 mA from the USB power connections.

(d)  None of the above

19.  The C programs that you write for a microcontroller are

(a)  directly copied into the flash memory of a microcontroller.

(b)  converted into a form suitable for storing in the microcontroller’s flash memory using software called an interpreter.

(c)  converted into a form suitable for storing in the microcontroller’s flash memory using software called a compiler.

(d)  stored in the microcontroller’s RAM.

20.  What’s the purpose of a bootloader?

(a)  To allow a microcontroller to be programmed using SPI

(b)  To allow a microcontroller to be programmed using I2C

(c)  To allow a microcontroller to be programmed using Serial and USB

(d)  None of the above

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset