EE 308 - Homework 11
Due April 12, 2000

1.
A serial eight-channel 12-bit A/D converter communicates over the SPI with the following specifications:

\epsfig{file=hw11_fig1.eps,width=6.5in}

The $\overline{\rm {CS}}$ 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.
The following will help you prepare for Lab 9.

(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 set up Expanded Port A as input, and generate a TOF interrupt about 4 times a second. In the TOF interrupt service routine, read the values on Expanded Port A, and write them to Channel A of the D/A converter, and to the slave HC12.

(c)
Write some C code to set up the slave HC12. Set up the SPI as a slave, with interrupts enabled, and set up Expanded Port A as output.

(d)
Write some C code for the slave interrupt service routine -- in the interrupt service routine, read the value sent by the master and write it to Expanded Port A.



Bill Rison
1999-04-13