In this use case, the SPI on extension header 1 of the Xplained Pro board will be configured with the following settings:
- Master Mode enabled
- MSB of the data is transmitted first
- Transfer mode 0
- SPI MUX Setting E (see Master Mode Settings)
- 8-bit character size
- Not enabled in sleep mode
- Baudrate 100000
- GLCK generator 0
Setup
Prerequisites
There are no special setup requirements for this use-case.
Code
The following must be added to the user application:
A sample buffer to send via SPI.
static uint8_t buffer[BUF_LENGTH] = {
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09,
0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x10, 0x11, 0x12, 0x13
};
Number of entries in the sample buffer.
GPIO pin to use as Slave Select.
#define SLAVE_SELECT_PIN CONF_MASTER_SS_PIN
A globally available software device instance struct to store the SPI driver state while it is in use.
A globally available peripheral slave software device instance struct.
A function for configuring the SPI.
void configure_spi_master(void)
{
slave_dev_config.ss_pin = SLAVE_SELECT_PIN;
config_spi_master.mux_setting = CONF_MASTER_MUX_SETTING;
config_spi_master.pinmux_pad0 = CONF_MASTER_PINMUX_PAD0;
config_spi_master.pinmux_pad1 = CONF_MASTER_PINMUX_PAD1;
config_spi_master.pinmux_pad2 = CONF_MASTER_PINMUX_PAD2;
config_spi_master.pinmux_pad3 = CONF_MASTER_PINMUX_PAD3;
spi_init(&spi_master_instance, CONF_MASTER_SPI_MODULE, &config_spi_master);
}
Add to user application main()
.
Workflow
- Initialize system.
- Set-up the SPI.
- Create configuration struct.
- Create peripheral slave configuration struct.
- Create peripheral slave software device instance struct.
- Get default peripheral slave configuration.
- Set Slave Select pin.
slave_dev_config.ss_pin = SLAVE_SELECT_PIN;
- Initialize peripheral slave software instance with configuration.
- Get default configuration to edit.
- Set MUX setting E.
config_spi_master.mux_setting = CONF_MASTER_MUX_SETTING;
- Set pinmux for pad 0 (data in (MISO)).
- Set pinmux for pad 1 as unused, so the pin can be used for other purposes.
- Set pinmux for pad 2 (data out (MOSI)).
- Set pinmux for pad 3 (SCK).
- Initialize SPI module with configuration.
spi_init(&spi_master_instance, CONF_MASTER_SPI_MODULE, &config_spi_master);
- Enable SPI module.
Use Case
Code
Add the following to your user application main()
.
Workflow
- Select slave.
- Write buffer to SPI slave.
- Deselect slave.
- Light up.
- Infinite loop.