- Features supported:Before start using SPI master, appropriate module or both modules need to be enabled
- Two SPI modules, SPI0 and SP01 are currently supported.
- The driver can used to use only one or both of the SPI modules.
- Configuration of each SPI module.
- Interface to transmit and receive data on each of the modules.
SPI Module Initialization and Configuration
The SPI modules need to be initialized and configured before they can be used for data exchange. All configuration options need to be configure in structure spi_master_config_t.
Before the configure SPI master, appropriate module (or both modules) need to be enabled by defined:
- #define SPI_MASTER_0_ENABLE
- #define SPI_MASTER_1_ENABLE
- PINs configuration (PIN numbers from 0 to 31):
- Serial clock polarity configuration
See spi_master_config_t::SPI_CONFIG_CPOL.
Supported serial clock polarities:
- Active high
- Active low
- Serial clock phase configuration
See spi_master_config_t::SPI_CONFIG_CPHA.
Supported serial clock phases:
- Data endian-ness configuration.
See spi_master_config_t::SPI_CONFIG_ORDER.
Supported data endian-ness:
- Least significant bit shifted out first.
- Most significant bit shifted out first.
- SPI master frequency configuration.
See spi_master_config_t::SPI_Freq.
Supported SPI master frequencies:
- 125 kbps
- 250 kbps
- 500 kbps
- 1 Mbps
- 2 Mbps
- 4 Mbps
- 8 Mbps
- Interrupt priority configuration.
See spi_master_config_t::SPI_PriorityIRQ.
If SoftDevice is enabled available interrupt priorities (values 3 and 1):
If SoftDevice isn't enabled available interrupt priorities (values from 0 to 3):
- Lowest
- Low
- High
- Highest
- Disable all IRQs during realization critical region inside the driver.
See spi_master_config_t::SPI_DisableAllIRQ.
- Disable all interrupts.
- Disable only SPI interrupt.
- Quick start
- Configure SPI master PINs.
- Following sample snippet initializes SPI_MASTER_0 with default values.
#define SPI_MASTER_0_ENABLE
{
{
transmission_completed = true;
break;
default:
break;
}
}
void spi_master_init(void)
{
{
}
}
SPI Master Data Exchange API
Once successfully initialized, data can be exchanged serially on the module. Data transmission is synchronous and any data that the slave wants to transmit is fetched during the master transmission.
uint16_t buf_len = TX_RX_MSG_LENGTH;
uint8_t rx_buffer[TX_RX_MSG_LENGTH];
uint8_t tx_buffer[TX_RX_MSG_LENGTH];
volatile bool transmission_completed = false;
int index;
for (index = 0; index < TX_RX_MSG_LENGTH; index++)
{
tx_buffer[index] = index;
}
{
}