239
Explanation
HW_SPI.h and HW_SPI.c files describe the functionality of USCI-SPI hardware.
void HW_SPI_init(void);
void SPI_write(unsigned char tx_data);
unsigned char SPI_read(void);
unsigned char SPI_transfer(unsigned char tx_data);
The first function as shown above initiates the USCI-SPI hardware. The initialization is generated using
Grace. Note the Grace screenshot below:
These settings describe which pins are being used, their purposes, communication speed, SPI mode,
clock polarity and so on. Note the slave select pin is not shown here as we have used a different pin
for that purpose.
SPI_read, SPI_write and SPI_transfer functions do their job as per their naming.
Now let’s get inside the read and write function of USCI-SPI
void SPI_write(unsigned char tx_data)
{
while(!(IFG2 & UCA0TXIFG));
UCA0TXBUF = tx_data;