EE 308 - Homework 11
Due April 20, 1999

1.
A serial eight-channel 12-bit A/D converter communicates over the SPI with the following specifications:
• Select the chip by bringing low.
• Send an eight-bit number with the channel you want to convert in the lower three bits. The upper 5 bits are ignored.
• Read sixteen bits from the A/D converter. The four most significant bits are zeros. The twelve least-significant bits are the A/D voltage of the channel you requested.
• Deselect the chip by bringing high.
• The maximum SCLK frequency is 750 kHz. The timing diagram looks like this:

The line of the A/D converter is connected to the PP4 pin of the HC12.

(a)
Write some C code to set the the HC12 to communicate with the A/D converter. Be sure to make PP4 an output, deselct the A/D, set the SPI clock rate, clock polarity, and clock phase to work with the A/D. The SPI should be set up to use polling rather than interrupts.
(b)
Write some C code to tell the A/D to convert Channel 3. Read the value returned from Channel 3 and store it in a 16-bit number called channel_3.
(c)
The A/D converter has a range from 0 V to 5 V. The value returned from the A/D is 0x7A3. What analog voltage is on the Channel 3 input pin?

2.
The following problem deals with the SPI flag.
(a)
How do you clear the SPI flag (SPIF bit of SP0SR register)?
(b)
Write some C code to clear the SPI flag.

3.

(a)
Write some C code to set up the HC12 SPI to communicate with the MAX522 D/A converter chip. Again, be sure to set up the chip select line, the clock rate, the clock phase and the clock polarity. The SPI should work in polled rather than interrupt mode.

(b)
Write some C code to put 1.15 V on the OUTA pin of the MAX522.

(c)
Write some C code to put 3.57 V on the OUTB pin of the MAX522.

Bill Rison
1999-04-13