1

I am using Raspberry pi 4 and I want to connect three MCP3008 ic. I am a little bit confused about how to SPI MISO and SPI MOSI and chip select of Raspberry pi to Dout Din and CS of each of the three MCP3008 ic's

Note: I need to read from the ics at the same time and DO NOT switch with them

Thanks in advance

MCP3008 schemetic diagram

Omar Alaa
  • 21
  • 3
  • Which part is confusing. Plenty of examples. – joan Dec 27 '22 at 08:12
  • The connection itself. there is no problem regarding connecting clck because clck synchronizes all ic clocks to that of Raspberry Pi , but how to assure Raspberry pi will differentiate from the output of every ic? – Omar Alaa Dec 27 '22 at 08:26
  • MCP3008 connects through serial communication with Raspberry pi through the three pins I mentioned in my question – Omar Alaa Dec 27 '22 at 08:28
  • NOTE whatever you do DO NOT connect to 5V – Milliways Dec 27 '22 at 09:49
  • It is possible to connect 3 SPI devices using dtoverlay spi1-3cs. What have you tried? – Milliways Dec 27 '22 at 10:55
  • After I read about dtoverlay, I found that it configures more Raspberry pi GPIO pins. so I will try it and inform you – Omar Alaa Dec 27 '22 at 11:47
  • The problem is that dtoverlay switches between thhe ics. I need to read from the ics at the same time – Omar Alaa Dec 27 '22 at 13:51
  • 1
    You seem to have arrived at a non-workable solution for whatever underlying problem you are trying to solve. You should have asked about the underlying problem in the first place. – joan Dec 27 '22 at 18:22
  • 1
    @OmarAlaa the only way to read all three MCP3008 at the same time is to use a separate microcontroller for each one and synchronize the reading with one trigger signal ... that would allow you to read 3 of 24 inputs at the same time – jsotola Dec 27 '22 at 19:08
  • what is connected to the MCP3008 inputs? – jsotola Dec 27 '22 at 19:09
  • @jsotola You can actually bit bang. Common CLK, MOSI, CS with separate GPIO for each MISO. I've done it myself to read multiple SPI ADC at the same time (up to 20 ksps using the MCP3008 and pigpio). See https://forums.raspberrypi.com/viewtopic.php?t=71089 – joan Dec 27 '22 at 21:00

3 Answers3

2

If you just need all 3 ADCs to sample at the same time, you can do this by connecting all the clock signals together on one Pi O/P pin, all the MOSI signals together to another O/P pin, and all the CS signals together onto a third Pi O/P pin. Connect the 3 MISO signals to individual Pi I/P pins.

Now write some 'bit-banging' code to set the CS line low, then toggle the clock while outputting the command to the ADCs on the MOSI line, then keep toggling the clock and read the result on all 3 MISO lines simultaneously. This will give you 3 values that are very accurately aligned together, as requested.

What this won't give you is an accurate time-spacing between each measurement cycle; you can try triggering the code from an periodic interrupt, but it will be subject to pauses and delays due to higher-priority processes interrupting the transfer; maybe around 100 microseconds of jitter in the time-interval, but this very much depends on what else the CPU is doing.

If you also want accurate time-intervals between measurements, the code gets much more complex; I suspect it may be possible using SMI (Secondary Memory Interface) but it won't be easy.

jayben
  • 585
  • 2
  • 3
0

You connect all of the MISO (Master In Slave Out), MOSI (Master Out Slave In), SCLK (SPI Clock) together and to the appropriate pins on the pi. The CS\ (Chip Select) is an active low pin that enables the A/D converter so it will communicate with the pi. Each CS\ will need to be assigned to a different GPIO pin on the Pi. Only one of the pins is allowed to be asserted low at any given time. This is done to select that individual chip so you can communicate with it. If two or more are selected you will get garbage.

Your question was not clear, the parts you chose to my knowledge are not designed to be sinked.It sounds like you need a simultaneous converting A/D. Do a google search for "simultaneous converting A/D" there are many good ones available. This will allow you to convert all channels at one time then read the values sequentially. This is a SWAG as you have not given more details of your project such as data rates etc.

Gil
  • 1,228
  • 4
  • 5
  • Thanks, but it is not suitable to me. My application receives stream of bits on the three ic's and prints its analog value. i need the three to work at the same time – Omar Alaa Dec 27 '22 at 13:31
0

Your question keeps changing.

If you WANT independent, simultaneous conversion (depends on your definition of "simultaneous") you NEED to use different SPI devices. Although it is not clear WHY the small conversion time of MCP3008 would be a problem with sequential reading.

The BCM2711 has 6 (although not all are accessible on Pi4). I have only used SPI0, SPI1 but there is Device Tree support for all (in various combinations).

Milliways
  • 59,840
  • 31
  • 101
  • 209