This video presentation is the sixteenth installment of the Essentials of MQX RTOS Application Development training course. In this session, you will be introduced to the SPI Driver.
This training was created by Embedded Access Inc., a Freescale sponsored training provider and proven partner.
|Session 16 Course Line||Lab Outline|
First, watch the video for Session 16: SPI Driver.
Then, follow through with the interactive lab assignment below.
In this lab the SPI port is used to talk to an external ADC that is on the Analog Tower Board. You will notice some similarities to using the I2C bus, but you will also notice some differences. The Input Task will read the external ADC at the same time that it reads the internal ADC and it will print out the read value in order to verify that the code is operating correctly.
The objective of this lab is to learn how the SPI driver is set up and used for communicating with a common peripheral. As well, understanding the differences between SPI and I2C, and having experience using both, will hopefully give you some insight as to which one might suit your application best if you are given the option to select one over the other.
0x80 | ((channel & 0x7)<<4) | 0x4This will set ADC for a single input (as opposed to a differential input), set the channel number to the passed in channel, and it will turn on the gain. Set the second byte of the write buffer to 0x00.
Param.READ_BUFFER = read_buffer; Param.WRITE_BUFFER = write_buffer; Param.BUFFER_LENGTH = sizeof(write_buffer);
return ( read_buffer <<8 | read_buffer );
Need more help? The full source code for this lab can be found in the 'Lab Source Code' folder here.