Different variants exist. Usually SPI refers to the Motorola Serial Peripheral Interface. Other variants are the Texas Instruments Serial protocol (SSP) and the National Instruments Microwire.
Most significant bit first
There are 4 Modes. Defied by the two settings “clock polarity” CPOL and “clock phase” CPHA.
“clock polarity” CPOL = 0:
“clock polarity” CPOL = 1:
“clock phase” CPHA = 0:
“clock phase” CPHA = 1:
mode | CPOL | CPHA | write bit | read bit |
---|---|---|---|---|
0 | 0 | 0 | clock goes low, and when /CS activates | clock goes high |
1 | 0 | 1 | clock goes high | clock goes low |
2 | 1 | 0 | clock goes high, and when /CS activates | clock goes low |
3 | 1 | 1 | clock goes low | clock goes high |
This group defines all used Serial Peripheral Interface (SPI) interfaces.
Each SPI interface is a sub group with the SPI name as the group name.
"SPI": { "encoder_spi": { "pad_sck": "PA5", "pad_miso": "PA6", "pad_mosi": "PA7", "pad_ncs": "PA15", "peripheral" : "SPI0", "role": "master", "communication_mode": "duplex", "frame_format": "motorola", "clock_polarity": "idle_low", "clock_phase": "sample_on_leading_edge", "bit_order": "msb_first", "baud_rate": "10 MHz", } }
Serial Clock.
type: String
“Master Out Slave In” data signal.
type: String
“Master In Slave Out” data signal.
type: String
Chip Select signal (Low active).
type: String
name of the SPI peripheral to use.
type: String
Is either master(host) or slave(device).
type: enum
default: master
Describes the communication. Possible values are:
type: enum
default: duplex
Describes the communication. Possible values are:
type: enum
default: motorola
Also often called CPOL. Describes the communication. Possible values are:
type: enum
default: idle_low
Also often called CPHA. Describes the communication. Possible values are:
type: enum
default: sample_on_leading_edge
Sometimes the documentation talks about a SPI Mode with the value of 0 to 3. This mode maps to the phase and polarity as described in the following table:
Mode | CPOL | CPHA | description |
---|---|---|---|
0 | 0 | 0 | clock: idle_low, phase: sample_on_leading_edge |
1 | 0 | 1 | clock: idle_low, phase: sample_on_trailing_edge |
2 | 1 | 0 | clock: idle_high, phase: sample_on_leading_edge |
3 | 1 | 1 | clock: idle_high, phase: sample_on_trailing_edge |
Describes the communication. Possible values are:
type: enum
default: msb_first
Is the number of bits per second exchanged on the data lines. Expressed as frequency of the clock line.
type: int (Hz)
The part “signal_name” in the described functions will be replaced by the name of the signal. E.g. if your signal is called “audio” then the API function “signal_name_transfer” will become “audio_transfer”.
void signal_name_transfer(const uint8_t *data_send, const uint8_t *data_receive, const uint32_t length )
Will send “length” bytes from the buffer “data_send” out on MOSI and will receive the same amount of bytes from MISO into the buffer “data_receive”.