spi.c
Source file: spi.c
Function: spi_init
int spi_init(unsigned int speed_hz)
Initialize the SPI bus.
Parameters:
| Name | Type | Description |
|---|---|---|
speed_hz |
unsigned int |
Clock speed in Hz. |
Returns: 0 on success.
Function: spi_transfer
int spi_transfer(const void *tx, void *rx, int len)
Example
uint8_t tx[] = {0x01, 0x02};
uint8_t rx[2];
spi_transfer(tx, rx, 2);Example 2
uint8_t rx[4];
spi_transfer(NULL, rx, 4);Transfer data over SPI (full duplex).
Sends and receives data simultaneously on the SPI bus.
For read-only transfers, pass NULL for tx:
Parameters:
| Name | Type | Description |
|---|---|---|
tx |
const void * |
Pointer to transmit buffer. |
rx |
void * |
Pointer to receive buffer. |
len |
int |
Number of bytes. |
Returns: 0 on success, negative on error.