SPI 100 bits word

98 views
Skip to first unread message

Charles Censier

unread,
Nov 6, 2020, 6:11:56 AM11/6/20
to bcm2835
Hello,

I'm developing a C interface to control a SPI device that accept 100 bits words. This is my first project using SPI but I think I understood the basic.
I'm using the bcm2835 library in 1.68 version on a Raspberry Pi 4, but unfortunately, I am not authorized to disclose specific informations or documents related to the SPI device.

I created a 13 bytes buffer and stored the 100 bits word inside but as 100 is not a multiple of 8, i have 4 extra bits. 

So my question is, if I send the 13 bytes word using bcm2835_spi_transfernb() what should happen ? 
I don't quite understand if the transfer will be stopped by the slave when the 100 bits will be received or if the last 4 bits will override the first 4 bits or simply be lost.

Thank in advance !

Arjan van Vught

unread,
Nov 6, 2020, 6:24:35 AM11/6/20
to bcm...@googlegroups.com
Hi Charles,

When you send 13 bytes using  bcm2835_spi_transfernb() then these 13 bytes are transferred using the SPI protocol by the host (the Raspberry Pi SoC). 

It depends on the SPI slave implementations what happens with the remaining 4 bits.

- Arjan

--
You received this message because you are subscribed to the Google Groups "bcm2835" group.
To unsubscribe from this group and stop receiving emails from it, send an email to bcm2835+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/bcm2835/4aeecb9f-8c51-41f5-b743-ead29f0daef5n%40googlegroups.com.

Charles Censier

unread,
Nov 6, 2020, 7:02:17 AM11/6/20
to bcm2835
Hi Arjan,

Thank you for your quick response.

As I understand the device functionnement, the MSB (that should be bit 99) is read first, so... this means that the 7th bit of the 13th byte buffer is read first ? 
Which mean I should shift my entire buffer and leave the first 4 bits blank and expect them to be ignored ?

From the point of view of the library, it alway send bytes in ascending order, starting from byte 0, then 1, to byte x ?

Eric Marzec

unread,
Nov 6, 2020, 11:37:59 AM11/6/20
to bcm...@googlegroups.com
Hi Charles,
You may already be aware of this, but in case you're not, the BCM2835's auxiliary SPI interface allows for arbitrary length SPI transactions. If I recall correctly the max length for a single transaction is 24-bits. So a 100-bit write/read could be accomplished with five 20-bit transactions. Or four 24-bit and one 4-bit transactions if that's easier. The auxiliary SPI interface has a few downsides compared to the primary SPI interface, so it may not be the right fit for you. But I thought I'd mention it as a possibility regardless.

- Eric M

Charles Censier

unread,
Nov 9, 2020, 4:35:41 AM11/9/20
to bcm2835
Hi Eric,

Thank you for your response. I looked into the auxiliray SPI interface but the resolution seems to be byte as well and not bit :
void bcm2835_aux_spi_transfernb( const char * tbuf, char * rbuf, uint32_t  len  )  --> in the documentation len refers to the number of bytes.

I understood that the auxiliary interface use SPI1 meanwhile the default one use SPI0.
If I didn't understand what you meant talking about the auxiliary SPI interface, please explain it to me (as I said I'm a beginner in SPI protocol).

I also saw there is a low level GPIO register access but it seems a bit complicated...
Reply all
Reply to author
Forward
0 new messages