Microchip® Advanced Software Framework

Transmitting using the FreeRTOS SPI driver in

standard mode

This example demonstrates using the FreeRTOS SPI driver to send data using the standard operation mode. See Initializing the FreeRTOS SPI driver

The example below implements a function that simply writes a block of data to an SPI port.

Refer to the FreeRTOS peripheral control projects in the Atmel ASF distribution for complete working examples, and the FreeRTOS web site for information on getting started with FreeRTOS.

// Write number_of_bytes from data_buffer to freertos_spi.
//
// This examples assumes freertos_spi has already been set by a successful
// call to freertos_spi_master_init(), and that freertos_spi_master_init()
// configured the FreeRTOS SPI driver to use the standard operation mode.
static void write_to_eeprom(freertos_spi_if freertos_spi,
uint8_t data_buffer size_t number_of_bytes)
{
const portTickType max_block_time_ticks = 200UL / portTICK_RATE_MS;
// Attempt to write number_of_bytes from data_buffer to the port
// referenced by the freertos_spi handle. Wait a maximum of 200ms to
// get exclusive access to the port (other FreeRTOS tasks will execute
// during any waiting time).
if(freertos_spi_write_packet(freertos_spi, data_buffer,
number_of_bytes, max_block_time_ticks) != STATUS_OK)
{
// The data was not written successfully, either because there was
// an error on the SPI bus, or because exclusive access to the SPI
// port was not obtained within 200ms.
}
}