SPI Master

Functions for using Serial Peripheral Interface (SPI) peripheral. More...

Modules

Types
Hardware SPI data types.
 
Macros
Hardware SPI macros.
 

Functions

zos_result_t zn_spi_stream_configure (zos_gpio_t ss_gpio, uint16_t flags, uint32_t clock_rate)
 Configure SPI stream for communication with SPI slave. More...
 
zos_result_t zn_spi_stream_open (uint32_t *handle, uint16_t rx_buffer_size)
 Open SPI stream to slave device. More...
 
zos_result_t zn_spi_stream_write (uint32_t handle, const void *data, uint32_t size)
 Write data to slave device. More...
 
zos_result_t zn_spi_stream_read (uint32_t handle, void *data, uint32_t max_size, uint32_t *bytes_read)
 Read data from slave device. More...
 
zos_result_t zn_spi_stream_read_with_buffer (uint32_t handle, zos_buffer_t *buffer)
 Read SPI stream data into buffer. More...
 
zos_result_t zn_spi_stream_close (uint32_t handle)
 Close SPI stream. More...
 
zos_result_t zn_spi_stream_set_slave_select (uint32_t handle, zos_gpio_t ss_gpio)
 Switch SPI stream's slave device. More...
 
zos_result_t zn_spi_transfer (const zos_spi_device_t *spi, const zos_spi_message_t *messages, uint16_t message_count)
 Transfer data messages to SPI slave. More...
 
zos_result_t zn_spi_master_lock_bus (const zos_spi_device_t *spi, uint32_t timeout)
 Lock the SPI bus's mutex. More...
 
zos_result_t zn_spi_master_unlock_bus (void)
 Unlock the SPI bus's mutex. More...
 
zos_result_t zn_spi_master_deassert (void)
 De-assert the SPI slave select GPIO. More...
 

Detailed Description

Functions for using Serial Peripheral Interface (SPI) peripheral.

Function Documentation

zos_result_t zn_spi_master_deassert ( void  )

De-assert the SPI slave select GPIO.

This de-selects the slave-select signal. The signal-select can remain asserted based on the supplied flags.

Returns
zos_result_t result of api call
zos_result_t zn_spi_master_lock_bus ( const zos_spi_device_t spi,
uint32_t  timeout 
)

Lock the SPI bus's mutex.

If the SPI bus is shared with the extended flash, the mutex ensures exclusive access to the bus.

Note
Use zn_spi_master_unlock_bus() to release the lock.
Parameters
[in]spiSPI bus to lock
[in]timeoutMaximum amount of time to wait for the lock
Returns
zos_result_t result of api call
zos_result_t zn_spi_master_unlock_bus ( void  )

Unlock the SPI bus's mutex.

See zn_spi_master_lock_bus() for more info.

Returns
zos_result_t result of api call
zos_result_t zn_spi_stream_close ( uint32_t  handle)

Close SPI stream.

See ZentriOS Command API documentation: stream_close.

Parameters
[in]handleHandle of stream to close
Returns
zos_result_t result of api call
zos_result_t zn_spi_stream_configure ( zos_gpio_t  ss_gpio,
uint16_t  flags,
uint32_t  clock_rate 
)

Configure SPI stream for communication with SPI slave.

See ZentriOS Command API documentation: spi_master_config.

Parameters
[in]ss_gpioSlave-select gpio
[in]flagsConfiguration flags, see SPI_FLAG macros
[in]clock_rateSPI master clock
Returns
result of api call, see zos_result_t
Examples:
basic/spi_stream/spi_stream.c.
zos_result_t zn_spi_stream_open ( uint32_t *  handle,
uint16_t  rx_buffer_size 
)

Open SPI stream to slave device.

See ZentriOS Command API documentation: spi_master_open.

Parameters
[out]handleStream handle
[in]rx_buffer_sizeSize of RX buffer
Returns
result of api call, see zos_result_t
zos_result_t zn_spi_stream_read ( uint32_t  handle,
void *  data,
uint32_t  max_size,
uint32_t *  bytes_read 
)

Read data from slave device.

See ZentriOS Command API documentation: spi_master_open, stream_read.

Parameters
[in]handleStream handle returned by API call
[out]dataBuffer to hold read data
[in]max_sizeMaximum amount of data to read
[out]bytes_readPointer to hold actual amount of data read (set NULL if not used)
Returns
zos_result_t result of api call
Examples:
basic/spi_stream/spi_stream.c.
zos_result_t zn_spi_stream_read_with_buffer ( uint32_t  handle,
zos_buffer_t buffer 
)

Read SPI stream data into buffer.

See zn_read_with_buffer() for more information.

Parameters
handleStream handle
bufferBuffer to specify how much data to read, then return how much data was read with pointer to data
Returns
zos_result_t result of api call
zos_result_t zn_spi_stream_set_slave_select ( uint32_t  handle,
zos_gpio_t  ss_gpio 
)

Switch SPI stream's slave device.

A SPI stream can be associated with multiple SPI slaves. A SPI slave is configured with zn_spi_stream_configure() The configured SPI slave is then selected with this API

Parameters
[in]handleSPI stream handle
[in]ss_gpioGPIO of configured SPI slave
Returns
zos_result_t result of api call
zos_result_t zn_spi_stream_write ( uint32_t  handle,
const void *  data,
uint32_t  size 
)

Write data to slave device.

See ZentriOS Command API documentation: spi_master_open, stream_write.

Parameters
[in]handleStream handle returned by API call
[in]dataData to write to stream
[in]sizeSize of data in bytes to write
Returns
zos_result_t result of api call
zos_result_t zn_spi_transfer ( const zos_spi_device_t spi,
const zos_spi_message_t messages,
uint16_t  message_count 
)

Transfer data messages to SPI slave.

This API is separate from the 'spi stream' APIs. This API directly writes the SPI master driver. The driver is automatically configured based on the settings in zos_spi_device_t upon calling this API.

Parameters
[in]spiSPI driver configuration, see zos_spi_device_t
[in,out]messagesArray of messages to read/write data, see zos_spi_message_t
[in]message_countNumber of messages to transfer to SPI slave device
Returns
zos_result_t result of api call