librpipSpiConfigWrite

uint32_t librpipSpiConfigWrite(uint32_t id, uint32_t cs, uint32_t spi_mode, uint32_t max_speed, uint32_t spi_flags);

Description

Configures an SPI master. Note that the linux spidev driver allows for more configuration option than are presented here such as ‘Bits per Word’ and ‘LSB first’. This is because the current spi_bcm2835 kernel module only supports a single value for these additional parameters and hence there is nothing for the user to config.

Parameters

  • uint32_t id
    The SPI device id to configure. The SPI device needs to have been detected during the librpipInit().
  • uint32_t cs
    The client select line to configure. SPI0 has two – 0 and 1, SPI1 has three 0,1,2. Yes each client has it’s own discrete config.
  • uint32_t spi_mode
    One of the LIBRPIP_SPI_MODE_* constants. Actual mode required will depend on the device.
  • uint32_t max_speed
    The maximum clock speed to use with the client. It is not possible to know the actual speed the chip actually uses without measuring it with an oscilloscope. Valid range is 8kHz to 125mHz. Default is 1mHz.
  • uint32_t spi_flags
    Additional SPI flags as per the LIBRPIP_SPI_FLAG_* constants. These can be or’d together as required.

Returns

0 on failure or 1 on success.

Example

Set SP0, client 0 to use mode 0 and 100kHz clock.
Set SP0, client 1 to use mode 3, 2mHz clock and no CS line.

uint32_t feature_set;
feature_set = librpipInit(LIBRPIP_BOARD_DETECT, LIBRPIP_FLAG_DEBUG_ON, 0);
if(feature_set & LIBRPIP_FEATURE_SPI0) {
        librpipSpiConfigWrite(0, 0, LIBRPIP_SPI_MODE_0, 100000, 0);
        librpipSpiConfigWrite(0, 1, LIBRPIP_SPI_MODE_3, 2000000, LIBRPIP_SPI_FLAG_NO_CS);
}