Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: Need SPI ADC part advice, and 4xSPI questions

  1. #1
    Senior Member
    Join Date
    Oct 2019
    Posts
    144

    Need SPI ADC part advice, and 4xSPI questions

    I'm working on a design that requires each communication pin to be either input or output. This means I2C is not an option since SDA is bidirectional. All the accelerometers I've been working with have required I2C, so I need to search for new units with good library support that utilize hardware SPI channels. Any good recommendations?

    [Bonus] I need to make readings from several ADCs simultaneously. I've heard of people implementing 4x SPI with their Teensys. If this is doable, I'd like to be able to take 4 ADCs with duplicate input pins from the Teensy and then clock out four channels of data in parallel. Does this sound possible?

  2. #2
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,117
    Warning I have not used many of the accelerometers, although I do have a few of them sitting around here somewhere... My desk and office areas organization is not as it should be.

    But for example Adafruit and Sparkfun sell different units that can run using SPI like:
    https://www.adafruit.com/product/4097 (ADXL343
    https://www.sparkfun.com/products/14686 (BNO080) - I have few around and these also support output to a UART... Is that an option?
    ...

    Now running multiples of these?

    Now running 4 SPI? We only have 3 SPI ports and on T4.1, SPI2 is either using SD card pins which are harder to get to. Or using the same pins that are setup to have Memory chips installed... So you can do one or the other...

    You can setup code to read from all three SPI ports at the same time, so you could setup to do three that way...

    I was also playing around with FlexIO at one point and working on an SPI port, I think it may have DMA support, but has been awhile since I looked at it and don't remember how well it worked.
    Again no promises. but it is up at: https://github.com/KurtE/FlexIO_t4

  3. #3
    Senior Member
    Join Date
    Oct 2019
    Posts
    144
    UART I\O IS an option. What's available?
    Both the units you listed require I2C. The ADCL343 clearly shows I2C. The BNO080 requires it to setup the SPI

    I had the idea of setting up an interrupt on the SPI clock so that I can read three extra MISO pins when the hardware SPI reads only one.
    I think I've tried to do that, but hardware SPI hijacks the CLK pin interrupt. I'm not sure I can do the interrupt any other way except for wiring the clock pin to another pin to use as the interrupt and then reading the three extra pins. Not too much harder, but does cost an extra pin.

  4. #4
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    193
    Could you clarify the 4x SPI bit? are you talking 4 seperate SPI ports -OR- were you thinking about an SPI port with 4 data lanes?

  5. #5
    Senior Member
    Join Date
    Oct 2019
    Posts
    144
    Four data lines, one SPI port. 1xSKC, 1xMOSI, 1xCS, 4xMISO and 4x slave devices.

  6. #6
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    193
    Perhaps looking at how the on board SD Card operates on T3.5 & T3.6 could shed some light on what is required to implement that.

  7. #7
    Member
    Join Date
    Apr 2021
    Location
    Finland
    Posts
    30
    I think that, in theory, on teensy 4.1 both the QSPI port (used for the extra PSRAM normally) and FlexIO port(s) could be set up for generic 4-lane SPI ("quad-SPI" or something). Considering that I read somewhere about a project that somehow managed to arrange non-continuous FlexIO pins to handle 12 (or was it 13) lanes (correcting the bits to correct places in software) :P

    I also took a quick look at the SDCard port, but its controller seemed to be too specialized, expecting all kinds of standard specific responses etc. (At least on Teensy 4.1).

    The QSPI-idea is just something I have been reading on the datasheet, not seeing yet anything that would outright prevent its "generic" use, though it would need somewhat non-standard configuration; e.g. no address commands/instructions, just directly with read data commands, and immediate "stop" command after that. Definitely would need some deep dive in the manual. Though I've been hit with tiny sub-notes too many times before on various serial protocol implementations and I'm thus about 99% that such a specific port (meant mostly for memories) must have some kind of gotcha still waiting to surprise...

  8. #8
    Senior Member+ KurtE's Avatar
    Join Date
    Jan 2014
    Posts
    9,117
    Quote Originally Posted by kdharbert View Post
    UART I\O IS an option. What's available?
    Both the units you listed require I2C. The ADCL343 clearly shows I2C.
    The documents and libraries show the ability to hook up to SPI.
    Example: https://forum.arduino.cc/t/adxl345-w...-on-spi/257756
    Or page 15 of their PDF: https://www.analog.com/media/en/tech...ts/ADXL345.pdf

    Quote Originally Posted by kdharbert View Post
    The BNO080 requires it to setup the SPI
    Another version of the BNO is the BNO085: https://www.adafruit.com/product/4754
    Again it can be I2C, Uart, or SPI. This is chosen by solder jumpers on the back of the unit.

    Quote Originally Posted by kdharbert View Post
    I had the idea of setting up an interrupt on the SPI clock so that I can read three extra MISO pins when the hardware SPI reads only one.
    I think I've tried to do that, but hardware SPI hijacks the CLK pin interrupt. I'm not sure I can do the interrupt any other way except for wiring the clock pin to another pin to use as the interrupt and then reading the three extra pins. Not too much harder, but does cost an extra pin.
    Some reason I have doubts about this working... But can always be proved wrong.

    But before I went down that rabbit hole, (and I have gone down many), I might start asking myself some simple questions.

    Things like:

    A list of sensors that you are trying to decide between?
    What sample rate are you needing/expecting?
    Does going to higher sample rate, actually give me any more real data? For example with ADXL345 (since I still have PDF open),
    I see you can configure it for example from that PDF:
    Use of the 3200 Hz and 1600 Hz output data rates is only recommended with SPI communication rates greater than or equal to 2 MHz. The 800 Hz output data rate is recommended only for communication speeds greater than or equal to 400 kHz, and the remaining data rates scale proportionally. For example, the minimum recommended communication speed for a 200 Hz output data rate is 100 kHz.
    So for example if 800hz is sufficient and you can configure the SPI transfer speed to 5mhz (I think max) how much time does this take up on the SPI buss?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •