Using the Serial Peripheral Interface (SPI) for the QE Microcontrollers
QE128 Quick Reference User Guide, Rev. 1.0
11-6
Freescale Semiconductor
NOTE
This example is developed using the CodeWarrior IDE version 6.0 for the
HCS08 and V1 families. It is expressly made for the MCF51QE128 and
MC9S08QE128 (80-pin package). There may be changes needed in the
code to initialize another MCU.
Figure 11-1
, shows the hardware connections used for the SPI project, for
detailed information about the MCU hardware needed, please refer to the
Pins and Connections chapter in the Reference Manual. It can be found at
www.freescale.com.
11.3
SPI project for Demo board
11.3.1
Code Example and Explanation
This example code for the Master and Slave project is available from the Freescale Web site
www.freescale.com.
This Section explains the differences of codes used in the EVB and Demo board. The codes are the same.
11.3.1.1
SPI Master Project
The project SPI_Master configures the SPI module in master mode. The main functions are:
•
main — A byte is sent by the SPI.
•
MCU_Init – MCU initialization, watchdog disable and bus clock to the SPI clock module enabled.
•
GPIO_Init – Configure PTC-PTC5, PTE6 and PTE7 pins as outputs, configure PTD4 as output (
signal).
•
SPI_Init – SPI module configuration.
•
SPI_ISR — Clear module flags.
This is the General Purpose Input/Output configuration. These code lines configure the pin directions for
the PTD port. The SPI protocol can communicate various slaves with one master. To communicate with a
specific slave the
signal must be low. The PTD3 pin is configured as output and the
signal must
be changed by software using a GPIO. These code lines configure the direction for the PTC port. Only six
LEDs from the demo board are connected to the PTC port. The other two LEDs are connected to the E
port. In this example the PTC0 to PTC6, and PTE6, PTE7 are configured as outputs in order to drive LEDs.
void GPIO_Init(void) {
PTDDD = 0x04; // The SS signal must be generated by software using a GPIO
PTCDD = (UINT8) (PTCD | 0x3F); // Configure PTC0-PTC6 as outputs
PTEDD = (UINT8) (PTED | 0xC0); // Configure PTE6 and PTE7 pins as outputs
PTCD = 0x3F; // Put 1's in port C in order to turn off the LEDs
PTED = 0xC0; // Put 1's in port E port in order to turn off the LEDs
}
This is the main function, described are the above functions are called, and all the interrupts are enabled.
Within the enless loop a byte is sent by SPI and the next byte is sent after a delay. For detailed information
about SPI module, refer to the QE MCU reference manual. It can be found at www.freescale.com.
SS
SS
SS