Author Topic: Arbitrary SPI Register Length?  (Read 4191 times)

0 Members and 1 Guest are viewing this topic.

Offline kfnightTopic starter

  • Regular Contributor
  • *
  • Posts: 71
Arbitrary SPI Register Length?
« on: January 26, 2018, 05:11:49 pm »
I think I know the answer to this, but am looking for additional opinions. I'm designing an SPI slave device whose shift register length is 11. I'm concerned that some IO chips and their drivers won't be able to properly handle a register length that is not a multiple of 8 bits. In the spirit of engineering for the lowest-common-demoninator, am I better off making it 16 bits totals with 5 dead bits?

Thanks
 

Offline spudboy488

  • Regular Contributor
  • *
  • Posts: 136
Re: Arbitrary SPI Register Length?
« Reply #1 on: January 26, 2018, 05:17:50 pm »
Yes. All SPI in hardware that I've worked with uses 8-bit transfers.

 There are many A/D (10-bit, for example) that either state the unused bits are don't care or they may have channel info, etc.
 

Online JPortici

  • Super Contributor
  • ***
  • Posts: 3452
  • Country: it
Re: Arbitrary SPI Register Length?
« Reply #2 on: January 26, 2018, 05:40:20 pm »
I'd make it a multiple of 8 bits (with the MSB as "don't care" or "reserved for future use"). While there are microcontrollers that support an arbitrary number of bits, the vast majority will support 8/16 bits transfers and you don't want that people have to bit-bang SPI in order to use your device..
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Arbitrary SPI Register Length?
« Reply #3 on: January 26, 2018, 05:58:06 pm »
As long as the device only latches the shift register when the chip select is deasserted, it doesn't matter.

Online SiliconWizard

  • Super Contributor
  • ***
  • Posts: 14309
  • Country: fr
Re: Arbitrary SPI Register Length?
« Reply #4 on: January 26, 2018, 06:15:31 pm »
You will probably not find many (if any) SPI master controllers which can handle word sizes not multiples of 8 bits.

Since your device is a slave, you just need to make sure to ignore any incoming bit after the 11th. The master can then send 16-bit words.

The design issue you will face is about framing (typically handled with the Chip Select signal). If you want to be able to support what is sometimes called "burst transfers" (ie. being able to transfer more than one word in a frame), the master will have to pack words in a very annoying way if you want to avoid losing 5 bits every 16 bits. On the other hand, if all you support is one word per frame, you can just ignore any clock pulse after the 11th. (Just keep in mind that if you don't support burst transfers, the average data throughput will suffer a lot. Don't know if it matters or not in your application.)

 

Offline dgtl

  • Regular Contributor
  • *
  • Posts: 183
  • Country: ee
Re: Arbitrary SPI Register Length?
« Reply #5 on: January 26, 2018, 07:38:19 pm »
Non-8-bit multiple size is not very portable. If you want to have 11 bits, then support 16-bit transfers in some kind of fallback mode.
Either use only 11 bits and drop the rest on the device side (trigger on the 11-th clock etc) or trigger on CS rising edge (ignore the first 5 incoming bits and transmit 5 trailing garbage bits).
 

Offline kfnightTopic starter

  • Regular Contributor
  • *
  • Posts: 71
Re: Arbitrary SPI Register Length?
« Reply #6 on: January 26, 2018, 10:05:10 pm »
I will make it 16 bits. Thanks for the insights.
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5840
  • Country: de
Re: Arbitrary SPI Register Length?
« Reply #7 on: January 28, 2018, 06:57:23 pm »
This can be done much simpler, while keeping your 11-bit shift register.
Just send 16 bits framed as dddddddd dddxxxxx where d is data and x is don't care. The x bits will flow through your shift register and disappear, the rest will be latched correctly at the end of transmission.

 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13695
  • Country: gb
    • Mike's Electric Stuff
Re: Arbitrary SPI Register Length?
« Reply #8 on: January 28, 2018, 07:24:12 pm »
The only variable-length SPI port I've  seen is on the earlier NXP ARM MCUs - don't know if it's also on the later Cortex parts.
Definitely go 16 bit.
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3137
  • Country: ca
Re: Arbitrary SPI Register Length?
« Reply #9 on: January 28, 2018, 09:02:59 pm »
PIC32 can handle any-length transfers up to 32.

However, regardless of the hardware ability, it'll be easier to deal with your device if you use 16-bit transfers.
 

Online mikeselectricstuff

  • Super Contributor
  • ***
  • Posts: 13695
  • Country: gb
    • Mike's Electric Stuff
Re: Arbitrary SPI Register Length?
« Reply #10 on: January 28, 2018, 09:10:27 pm »
PIC32 can handle any-length transfers up to 32.
Which ones ? All the ones I've used only support 8,16 and 32
Youtube channel:Taking wierd stuff apart. Very apart.
Mike's Electric Stuff: High voltage, vintage electronics etc.
Day Job: Mostly LEDs
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1626
  • Country: nl
Re: Arbitrary SPI Register Length?
« Reply #11 on: January 28, 2018, 09:33:08 pm »
I think the widest range of data bits I've seen is on EFM32G series, which was 4-16 bits configurable.
LPC1768 is 8-16bits configurable (1-bit steps).

I think in general most microcontrollers allow control in steps of 8-bits, with some allowing up to 32-bits, but most 32-bit MCUs "only" going up to 16-bit transfers.
 

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5840
  • Country: de
Re: Arbitrary SPI Register Length?
« Reply #12 on: January 28, 2018, 11:49:38 pm »
Just to get back on track: the OP is not asking about the capabilities of <insert my absolute favorite MCU here>, but if an SPI transfer to an 11-bit slave device is feasible.
Yes, it is.
 
The following users thanked this post: Bassman59

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Arbitrary SPI Register Length?
« Reply #13 on: January 28, 2018, 11:55:43 pm »
The only variable-length SPI port I've  seen is on the earlier NXP ARM MCUs - don't know if it's also on the later Cortex parts.
Definitely go 16 bit.

STM32 from ST can do arbitrary SPI lengths too on some MCU families.
 

Offline NorthGuy

  • Super Contributor
  • ***
  • Posts: 3137
  • Country: ca
Re: Arbitrary SPI Register Length?
« Reply #14 on: January 29, 2018, 01:23:54 am »
PIC32 can handle any-length transfers up to 32.
Which ones ? All the ones I've used only support 8,16 and 32

Sorry. My mistake. Some may let you select the size to the byte  - 8,16,24,32 (such as MK), but cannot do it to the bit. That was PIC18 K42 which lets you select the number of bits.
 

Offline hans

  • Super Contributor
  • ***
  • Posts: 1626
  • Country: nl
Re: Arbitrary SPI Register Length?
« Reply #15 on: January 29, 2018, 08:48:05 am »
Just to get back on track: the OP is not asking about the capabilities of <insert my absolute favorite MCU here>, but if an SPI transfer to an 11-bit slave device is feasible.
Yes, it is.

I think you're missing the point. If the OP asked, can I do this on a <insert particular MCU part>, then the answer would be RTFM.
It is useful to have this discussion about the applicability of variable bit length SPI communication, on both master and slave, and conclude that "it depends".

E.g. extreme case: if you're setting up a communication between 2 FPGA's, you can basically do whatever you like..
 

Offline andersm

  • Super Contributor
  • ***
  • Posts: 1198
  • Country: fi
Re: Arbitrary SPI Register Length?
« Reply #16 on: January 29, 2018, 10:30:23 am »
It is useful to have this discussion about the applicability of variable bit length SPI communication, on both master and slave, and conclude that "it depends".
You can always do it, but you may have to do some extra shifting to align the data on the master side.

Offline Benta

  • Super Contributor
  • ***
  • Posts: 5840
  • Country: de
Re: Arbitrary SPI Register Length?
« Reply #17 on: January 29, 2018, 05:06:34 pm »
Just to get back on track: the OP is not asking about the capabilities of <insert my absolute favorite MCU here>, but if an SPI transfer to an 11-bit slave device is feasible.
Yes, it is.

I think you're missing the point. If the OP asked, can I do this on a <insert particular MCU part>, then the answer would be RTFM.
It is useful to have this discussion about the applicability of variable bit length SPI communication, on both master and slave, and conclude that "it depends".

E.g. extreme case: if you're setting up a communication between 2 FPGA's, you can basically do whatever you like..

I'm not missing anything. Read my reply #7. OP is asking about the slave. Now, if his design is daisy-chained it's a different story, but there's no mention of that.
« Last Edit: January 29, 2018, 05:12:24 pm by Benta »
 

Offline Sal Ammoniac

  • Super Contributor
  • ***
  • Posts: 1663
  • Country: us
Re: Arbitrary SPI Register Length?
« Reply #18 on: January 29, 2018, 06:42:51 pm »
The only variable-length SPI port I've  seen is on the earlier NXP ARM MCUs - don't know if it's also on the later Cortex parts.

The Infineon XMC-4000 series (Cortex-M4) supports SPI widths of 1-63 bits.
Complexity is the number-one enemy of high-quality code.
 

Online newbrain

  • Super Contributor
  • ***
  • Posts: 1714
  • Country: se
Re: Arbitrary SPI Register Length?
« Reply #19 on: January 30, 2018, 08:37:27 am »
Some may let you select the size to the byte  - 8,16,24,32 (such as MK), but cannot do it to the bit. That was PIC18 K42 which lets you select the number of bits.
Same thing for STM32, it depends on the family.
From a quick check of the DS I have on hand:
  • F0 and F7: from 4 to 16 bits, 1 bit granularity
  • F1 and F4: 8 or 16 bits

I don't think designing a slave with an odd bit size is good idea.
Nandemo wa shiranai wa yo, shitteru koto dake.
 

Offline jesuscf

  • Frequent Contributor
  • **
  • Posts: 499
  • Country: ca
Re: Arbitrary SPI Register Length?
« Reply #20 on: February 04, 2018, 04:46:45 pm »
I think I know the answer to this, but am looking for additional opinions. I'm designing an SPI slave device whose shift register length is 11. I'm concerned that some IO chips and their drivers won't be able to properly handle a register length that is not a multiple of 8 bits. In the spirit of engineering for the lowest-common-demoninator, am I better off making it 16 bits totals with 5 dead bits?

Thanks

What I have seen with other slave SPI devices with an arbitrary number of bits is that they use a start bit to begin loading the shift register.  Two examples that come to my mind are: the 93C66 EEPROM (1 start bit, 2 command bits, 9 address bits, and 8 data bits for a total of 20 bits) and the MCP3008 10-bit ADC (1 start bit, 4 selection bits, 1 dummy bit, 1 null bit, and 10 data bits for a total of 17 bits).
Homer: Kids, there's three ways to do things; the right way, the wrong way and the Max Power way!
Bart: Isn't that the wrong way?
Homer: Yeah, but faster!
 

Offline Bassman59

  • Super Contributor
  • ***
  • Posts: 2501
  • Country: us
  • Yes, I do this for a living
Re: Arbitrary SPI Register Length?
« Reply #21 on: February 05, 2018, 05:13:20 pm »
I think I know the answer to this, but am looking for additional opinions. I'm designing an SPI slave device whose shift register length is 11. I'm concerned that some IO chips and their drivers won't be able to properly handle a register length that is not a multiple of 8 bits. In the spirit of engineering for the lowest-common-demoninator, am I better off making it 16 bits totals with 5 dead bits?


For shits and grins, look at the Linear Tech LTC1598 octal ADC. It's advertised as "I/O Compatible with QSPI, SPI, MICROWIRE ™, etc." but it's batshit daft. The channel select is shifted in with the chip select high, and that select is the last four bits prior to the chip select going low. Sampling starts after the falling edge of chip select, then two clocks later it goes into hold mode, at which point you start clocking out the conversion result MSb first. Since it's a 12-bit converter, it takes 14 clocks to get that result, and after bit 0 shifts out, if you continue shifting (with the chip select asserted low), it shifts out the result in LSb-first order! The data sheet "helpfully" includes MC68HC05 assembly code to read the converter, which is amusing -- the result is shifted right by a bit.

I read this thing from an FPGA, so the weird shifting means I can design the "SPI" interface to do what I need. Shit like this is why I don't use an "SPI core," and instead just design the interface to meet the needs of the particular slave device. After all, SPI is just a couple of shift registers ...
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf