Inputs: Dynamic based on SPI sequence configuration
| Port Name | Data Type | Description | Optional |
|---|---|---|---|
| Write N | uint8/uint16/uint32 (vector) | Data to transmit | Yes |
Outputs: Dynamic based on SPI sequence configuration
| Port Name | Data Type | Description | Optional |
|---|---|---|---|
| Out N | uint8/uint16/uint32 (vector) | Data received from slave device | Yes |
Block inputs and outputs are created based on the SPI sequence you configure:
| I/O Type | Data Type | Range | Description |
|---|---|---|---|
| 8-bit Data | uint8 | 0-255 | Standard byte transfer |
| 16-bit Data | uint16 | 0-65535 | Word transfer mode |
| 32-bit Data | uint32 | 0-4294967295 | Extended transfer (device-dependent) |
| Family | Series | SPI Modules | DMA Support | Notes |
|---|---|---|---|---|
| dsPIC30F | All | SPI1-2 | Yes | Legacy SPI peripheral |
| dsPIC33F/E | All | SPI1-3 | Yes | Standard SPI with Enhanced Buffer |
| dsPIC33C | CK, CH | SPI1-3 | No | DOS-01482 peripheral |
| dsPIC33A | AK | SPI1-4 | Yes | DOS-01482 I2S variant |
| PIC32 | MZ | SPI1-6 | Yes | DOS-01329 32-bit SPI |
| PIC32 | MK, MX | SPI1-4 | Yes | Standard PIC32 SPI |
| SAM | E5x, C2x, D2x | SERCOM0-7 | Partial | SPI via SERCOM peripheral |
| SAM | E70, S70, V71 | SPI0-1 | Yes | Dedicated SPI peripheral |
| Parameter | Description | Options |
|---|---|---|
| SPI Module | Hardware SPI peripheral to use | SPI1, SPI2, … (device dependent) |
The SPI block uses a graphical sequence builder accessed by double-clicking the block. Available actions:
| Action | Description | Parameters |
|---|---|---|
| Initial Configuration | Set SPI mode, clock, and options | Frequency, CPOL, CPHA, data width, master/slave |
| Update Configuration | Change settings mid-sequence | Same as initial |
| Write Data | Transmit data bytes | Byte count, constant or block input |
| Read Data | Receive data bytes | Byte count, output port name |
| Write/Read | Full-duplex transfer | Data to write, read output |
| Set Pin | Control GPIO (SS, etc.) | Pin, state (0/1/toggle) |
| Delay | Insert timing delay | Delay in seconds |
| Interrupt | Trigger user interrupt | Interrupt name |
| Parameter | Options | Description |
|---|---|---|
| Blocking Mode | On/Off | On: Block waits for transfer completion. Off: Non-blocking operation |
| Master/Slave | In configuration | Master generates clock, Slave responds to external clock |
| Parameter | Description | Direction |
|---|---|---|
| SDI Pin | Serial Data In (MISO for Master) | Input |
| SDO Pin | Serial Data Out (MOSI for Master) | Output |
| SCK Pin | Serial Clock | Output (Master) / Input (Slave) |
| SS Pin | Slave Select | Output (Master) / Input (Slave) |
Pin assignment uses PPS (Peripheral Pin Select) on supported devices.
| Parameter | Range | Description |
|---|---|---|
| Interrupt Priority | 1-7 | SPI interrupt priority level |
SPI supports four clock modes based on clock polarity (CPOL) and phase (CPHA):
| Mode | CPOL | CPHA | Clock Idle | Data Sample Edge |
|---|---|---|---|---|
| 0 | 0 | 0 | Low | Rising |
| 1 | 0 | 1 | Low | Falling |
| 2 | 1 | 0 | High | Falling |
| 3 | 1 | 1 | High | Rising |
Select the mode matching your slave device’s requirements. Mode 0 and Mode 3 are most common.
Clock frequency is configured in the Initial Configuration action. The actual frequency depends on:
dsPIC (Standard):
FSCK = FCY / (Primary × Secondary)dsPIC33C/A (DOS-01482):
FSCK = FSPI / (2 × BRG)PIC32 (DOS-01329):
FSCK = FSPI / (2 × (BRG + 1))SAM (SERCOM):
FSCK = GCLK / (2 × (BAUD + 1))Master Mode:
Slave Mode:
DMA availability varies by device:
| Family | DMA Status | Notes |
|---|---|---|
| dsPIC30F/33F/33E | Available | Ping-pong buffers supported |
| dsPIC33CK/CH | Not Available | Interrupt-driven only |
| dsPIC33A | Available | Enhanced DMA controller |
| PIC32 | Available | High-throughput transfers |
| SAM E5x/C2x | Partial | SERCOM DMA support |
| SAM E7x | Available | Full DMA support |
Many SPI peripherals support enhanced buffer mode:
SAM SERCOM peripherals have specific PAD constraints for SPI:
| Function | Valid PADs |
|---|---|
| SDI | PAD0, PAD1, PAD2, PAD3 |
| SDO | PAD0, PAD3 (or PAD0, PAD2, PAD3) |
| SCK | PAD1 (or PAD1, PAD3) |
| SS | PAD2 (or PAD1, PAD2) |
The block validates pin combinations and warns if incompatible PADs are selected.
Read JEDEC ID from SPI Flash:
1. Initial Configuration (10 MHz, Mode 0, Master)
2. Set Pin: SS → 0 (assert)
3. Write Data: 0x9F (JEDEC ID command)
4. Read Data: 3 bytes → Output "FlashID"
5. Set Pin: SS → 1 (deassert)
Write 16-bit value to DAC:
1. Initial Configuration (5 MHz, Mode 0, 16-bit)
2. Set Pin: SS → 0
3. Write Data: [Config | Value] (from block input)
4. Set Pin: SS → 1
Simultaneous write command and read result:
1. Initial Configuration (1 MHz, Mode 0)
2. Set Pin: CS → 0
3. Write/Read: Write 0x00, Read 2 bytes → "ADCValue"
4. Set Pin: CS → 1
Communicate with multiple SPI devices:
1. Initial Configuration (Mode 0)
2. Set Pin: SS1 → 0
3. Write/Read with Device 1
4. Set Pin: SS1 → 1
5. Update Configuration (Mode 3) // Different device needs different mode
6. Set Pin: SS2 → 0
7. Write/Read with Device 2
8. Set Pin: SS2 → 1
Problem: No data on SPI bus.
Solutions:
Problem: Data received is incorrect or shifted.
Solutions:
Problem: “Pin mapping issue” warning.
Solutions:
Problem: DMA mode selected but transfers fail.
Solutions:
Problem: Actual frequency differs from requested.
Solutions: