The Serial Peripheral Interface (SPI) Master synchronous driver provides a communication interface to read/write the data from/to the slave device.
Refer SPI Drivers for more detailed calendar basics.
Initialize and deinitialize the driver and associated hardware
Register I/O descriptor
Enable or disable SPI master
Data transfer: transmission, reception, and full-duplex
Select character size
Set SPI baudrate
Which clock source is used
After SPI hardware initialization, the spi_m_sync_get_io_descriptor function is needed to register an I/O descriptor. Then enable the SPI hardware. At the end, control the slave select (SS) pin, and start the read/write operation.
The slave select (SS) is not automatically inserted during read/write/transfer, user must use I/O to control the devices' SS.
The following shows a simple example of using the SPI master. The SPI master must have been initialized by spi_m_sync_init. This initialization will configure the operation of the SPI master.
/** * Example of using SPI_0 to write "Hello World" using the I/O abstraction. */static uint8_t example_SPI_0[12] = "Hello World!";void SPI_0_example(void){ struct io_descriptor *io; spi_m_sync_get_io_descriptor(&SPI_0, &io); spi_m_sync_enable(&SPI_0); /* Control the slave select (SS) pin */ //gpio_set_pin_level(SPI_0_SS, false); io_write(io, example_SPI_0, 12); /* Control the slave select (SS) pin */ //gpio_set_pin_level(SPI_0_SS, true);}
SPI master peripheral and its related I/O lines and clocks