beginSPITransmission()

[Serial Peripheral Interface]
void beginSPITransmission(unsigned short chip_select, bool polarity = false);

Description

Begins an SPI transmission from a Leader Device.

Parameters

chip_select: the pin for the chip select line.

polarity: the polarity of the chip select line.

Returns

Nothing.

Example Code

The code initializes the SPI communication with the clock pin connected to pin 13, the data in pin connected to pin 12, and the data out pin connected to pin 11.

The code then begins an SPI transmission to the follower chip with the chip select pin connected to pin 10, and the polarity of the chip select line set to LOW.

void setup() {
    beginSPI(13, 12, 11);  // initializes the SPI communication with the clock pin connected to pin
                           // 13, the data in pin connected to pin 12, and the data out pin connected
                           // to pin 11
}

void loop() {
    beginSPITransmission(10, LOW);  // begins an SPI transmission to the follower chip with the chip
                                    // select pin connected to pin 10, and the polarity of the chip
                                    // select line set to LOW
                                    
    writeSPI(42);                   // sends the value 42 to the follower chip
    endSPITransmission(10, LOW);    // ends the SPI transmission
}

Notes and Warnings

The beginSPITransmission() function should be called before sending data to the follower chip.