spi(3)
π spi β SPI access π
okay bestie, so this is the spi(3) page from the Library Functions Manual β¨ and it's literally all about making your Raspberry Pi talk to external SPI devices. it's giving hardware-girlie energy, no cap π¦
πΈ NAME πΈ
spi β SPI access π
β¨ SYNOPSIS β¨
π Functions π
int bcm2835_spi_begin (void)
void bcm2835_spi_end (void)
void bcm2835_spi_setBitOrder (uint8_t order)
void bcm2835_spi_setClockDivider (uint16_t divider)
void bcm2835_spi_set_speed_hz (uint32_t speed_hz)
void bcm2835_spi_setDataMode (uint8_t mode)
void bcm2835_spi_chipSelect (uint8_t cs)
void bcm2835_spi_setChipSelectPolarity (uint8_t cs, uint8_t active)
uint8_t bcm2835_spi_transfer (uint8_t value)
void bcm2835_spi_transfernb (char *tbuf, char *rbuf, uint32_t len)
void bcm2835_spi_transfern (char *buf, uint32_t len)
void bcm2835_spi_writenb (const char *buf, uint32_t len)
void bcm2835_spi_write (uint16_t data)
int bcm2835_aux_spi_begin (void)
void bcm2835_aux_spi_end (void)
void bcm2835_aux_spi_setClockDivider (uint16_t divider)
uint16_t bcm2835_aux_spi_CalcClockDivider (uint32_t speed_hz)
void bcm2835_aux_spi_write (uint16_t data)
void bcm2835_aux_spi_writenb (const char *buf, uint32_t len)
void bcm2835_aux_spi_transfern (char *buf, uint32_t len)
void bcm2835_aux_spi_transfernb (const char *tbuf, char *rbuf, uint32_t
len)
uint8_t bcm2835_aux_spi_transfer (uint8_t value)
π¦ Detailed Description π¦
ok so these functions let you use SPI0 (Serial Peripheral Interface) to interface with an external SPI device. that's the whole vibe. that's the whole point. β¨
π Function Documentation π
int bcm2835_aux_spi_begin (void) [extern]
Starts AUX SPI operations, bestie π« it forces the RPi AUX SPI pins P1-38 (MOSI), P1-38 (MISO), P1-40 (CLK) and P1-36 (CE2) to alternate function ALT4, which is what actually enables those pins for the SPI interface.
(yes, the original really does say P1-38 twice up there, i'm just the messenger π)
Returns
1if successful,0otherwise β perhaps because you are not running as root π
uint16_t bcm2835_aux_spi_CalcClockDivider (uint32_t speed_hz) [extern]
Calculates the input for
See also
bcm2835_aux_spi_setClockDivider
Parameters
speed_hzβ A value between
See also
BCM2835_AUX_SPI_CLOCK_MINandBCM2835_AUX_SPI_CLOCK_MAX
Returns
- Input for
See also
bcm2835_aux_spi_setClockDivider
ngl this section is a lil bit of a cliffhanger, i'm just telling you what it says π
void bcm2835_aux_spi_end (void) [extern]
Ends AUX SPI operations π the SPI1 pins P1-38 (MOSI), P1-38 (MISO), P1-40 (CLK) and P1-36 (CE2) get returned to their default INPUT behaviour. so they go back to being regular lil pins π
void bcm2835_aux_spi_setClockDivider (uint16_t divider) [extern]
Sets the AUX SPI clock divider, which is basically the same thing as setting the AUX SPI clock speed π₯
Parameters
dividerβ The desired AUX SPI clock divider.
uint8_t bcm2835_aux_spi_transfer (uint8_t value) [extern]
Transfers one byte to and from the AUX SPI slave β¨ it clocks the 8 bit value out on MOSI, and simultaneously clocks in data from MISO. then it returns the read data byte from the slave. two-way street, main character energy π«Ά
Parameters
valueβ The 8 bit data byte to write to MOSI
Returns
- The 8 bit byte simultaneously read from MISO
See also
bcm2835_aux_spi_transfern()
void bcm2835_aux_spi_transfern (char * buf, uint32_t len) [extern]
Transfers any number of bytes to and from the AUX SPI slave, using bcm2835_aux_spi_transfernb under the hood. the returned data from the slave replaces the transmitted data in the buffer β so yeah, your buffer gets rewritten, that's the whole trick π
Parameters
bufβ Buffer of bytes to send. Received bytes will replace the contentslenβ Number of bytes in the buffer, and the number of bytes to send/received
See also
bcm2835_aux_spi_transfer()
void bcm2835_aux_spi_transfernb (const char * tbuf, char * rbuf, uint32_t len) [extern]
Transfers any number of bytes to and from the AUX SPI slave π« it asserts the CE2 pin during the transfer. clocks the len 8 bit bytes out on MOSI, and simultaneously clocks in data from MISO. the data read from the slave gets placed into rbuf.
warning bestie βrbufmust be at leastlenbytes long or you're gonna have a bad time π
Parameters
tbufβ Buffer of bytes to send.rbufβ Received bytes will by put in this bufferlenβ Number of bytes in thetbufbuffer, and the number of bytes to send/received
void bcm2835_aux_spi_write (uint16_t data) [extern]
Transfers half-word to the AUX SPI slave πΈ it asserts the currently selected CS pins during the transfer.
Parameters
dataβ The 8 bit data byte to write to MOSI
Returns
- The 16 bit byte simultaneously read from MISO
See also
bcm2835_spi_transfern()
void bcm2835_aux_spi_writenb (const char * buf, uint32_t len) [extern]
Transfers any number of bytes to the AUX SPI slave (no reading back this time, it's a one-way moment π ). asserts the CE2 pin during the transfer.
Parameters
bufβ Buffer of bytes to send.lenβ Number of bytes in thetbufbuffer, and the number of bytes to send
int bcm2835_spi_begin (void) [extern]
Starts SPI operations, periodt β¨ it forces RPi SPI0 pins P1-19 (MOSI), P1-21 (MISO), P1-23 (CLK), P1-24 (CE0) and P1-26 (CE1) to alternate function ALT0, which enables those pins for the SPI interface.
you should call bcm2835_spi_end() when all SPI functions are complete, so the pins go back to their default functions. clean up after yourself, queen π
See also
bcm2835_spi_end()
Returns
1if successful,0otherwise β perhaps because you are not running as root π
void bcm2835_spi_chipSelect (uint8_t cs) [extern]
Sets the chip select pin(s) π when a bcm2835_spi_transfer() is made, the selected pin(s) will be asserted during the transfer.
Parameters
csβ Specifies the CS pin(s) that are used to activate the desired slave. One ofBCM2835_SPI_CS*, seebcm2835SPIChipSelect
void bcm2835_spi_end (void) [extern]
Ends SPI operations π SPI0 pins P1-19 (MOSI), P1-21 (MISO), P1-23 (CLK), P1-24 (CE0) and P1-26 (CE1) are returned to their default INPUT behaviour.
void bcm2835_spi_set_speed_hz (uint32_t speed_hz) [extern]
Sets the SPI clock divider by converting the speed parameter into the equivalent SPI clock divider. ( see
See also
bcm2835_spi_setClockDivider
Parameters
speed_hzβ The desired SPI clock speed in Hz
void bcm2835_spi_setBitOrder (uint8_t order) [extern]
Sets the SPI bit order π it sets the bit order used for transmit and receive. the bcm2835 SPI0 only supports BCM2835_SPI_BIT_ORDER_MSB, so if you pick BCM2835_SPI_BIT_ORDER_LSB, the bytes get reversed in software instead. the library defaults to BCM2835_SPI_BIT_ORDER_MSB.
Parameters
orderβ The desired bit order, one ofBCM2835_SPI_BIT_ORDER_*, seebcm2835SPIBitOrder
void bcm2835_spi_setChipSelectPolarity (uint8_t cs, uint8_t active) [extern]
Sets the chip select pin polarity for a given pin β¨ when a bcm2835_spi_transfer() occurs, the currently selected chip select pin(s) will be asserted to the value given by active. when transfers are not happening, the chip select pin(s) return to the complement (inactive) value. so it flips back on its own, cute π
Parameters
csβ The chip select pin to affectactiveβ Whether the chip select pin is to be active HIGH
void bcm2835_spi_setClockDivider (uint16_t divider) [extern]
Sets the SPI clock divider, and therefore the SPI clock speed π₯
Parameters
dividerβ The desired SPI clock divider, one ofBCM2835_SPI_CLOCK_DIVIDER_*, seebcm2835SPIClockDivider
void bcm2835_spi_setDataMode (uint8_t mode) [extern]
Sets the SPI data mode β that's the clock polarity and phase π
Parameters
modeβ The desired data mode, one ofBCM2835_SPI_MODE*, seebcm2835SPIMode
uint8_t bcm2835_spi_transfer (uint8_t value) [extern]
Transfers one byte to and from the currently selected SPI slave π« it asserts the currently selected CS pins (as previously set by bcm2835_spi_chipSelect) during the transfer. clocks the 8 bit value out on MOSI, and simultaneously clocks in data from MISO. returns the read data byte from the slave. uses polled transfer as per section 10.6.1 of the BCM 2835 ARM Peripherls manual π
Parameters
valueβ The 8 bit data byte to write to MOSI
Returns
- The 8 bit byte simultaneously read from MISO
See also
bcm2835_spi_transfern()
void bcm2835_spi_transfern (char * buf, uint32_t len) [extern]
Transfers any number of bytes to and from the currently selected SPI slave, using bcm2835_spi_transfernb. the returned data from the slave replaces the transmitted data in the buffer π«Ά
Parameters
bufβ Buffer of bytes to send. Received bytes will replace the contentslenβ Number of bytes in the buffer, and the number of bytes to send/received
See also
bcm2835_spi_transfer()
void bcm2835_spi_transfernb (char * tbuf, char * rbuf, uint32_t len) [extern]
Transfers any number of bytes to and from the currently selected SPI slave β¨ it asserts the currently selected CS pins (as previously set by bcm2835_spi_chipSelect) during the transfer. clocks the len 8 bit bytes out on MOSI, and simultaneously clocks in data from MISO. the data read from the slave gets placed into rbuf.
bestie listen βrbufmust be at leastlenbytes long π
uses polled transfer as per section 10.6.1 of the BCM 2835 ARM Peripherls manual π
Parameters
tbufβ Buffer of bytes to send.rbufβ Received bytes will by put in this bufferlenβ Number of bytes in thetbufbuffer, and the number of bytes to send/received
See also
bcm2835_spi_transfer()
void bcm2835_spi_write (uint16_t data) [extern]
Transfers half-word to the currently selected SPI slave π
it asserts the currently selected CS pins (as previously set by bcm2835_spi_chipSelect) during the transfer. clocks the 8 bit value out on MOSI, and simultaneously clocks in data from MISO. uses polled transfer as per section 10.6.1 of the BCM 2835 ARM Peripherls manual π
Parameters
dataβ The 8 bit data byte to write to MOSI
See also
bcm2835_spi_writenb()
void bcm2835_spi_writenb (const char * buf, uint32_t len) [extern]
Transfers any number of bytes to the currently selected SPI slave πΈ it asserts the currently selected CS pins (as previously set by bcm2835_spi_chipSelect) during the transfer.
Parameters
bufβ Buffer of bytes to send.lenβ Number of bytes in thebufbuffer, and the number of bytes to send
π Author π
Generated automatically by Doxygen for bcm2835 from the source code. the robots wrote this one, not me πβ¨
and that's the whole page bestie, you ate it π
this was spi(3) from bcm2835, Version 1.75 π go forth and clock some bits, ily π«ΆπΈ
π¦ where this page comes from
- debian trixie: libbcm2835-dev 1.75+ds-1 Β· GPL-3.0-only
- ubuntu noble: libbcm2835-dev 1.75+ds-1 Β· GPL-3.0-only
- ubuntu questing: libbcm2835-dev 1.75+ds-1
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms