Coding Raspberry Pi with an ADC - SPI - raspberry-pi

I am trying to connect an analogue to digital converter to the raspberry pi. As far as I am able to understand, the RPi doesn't support Bi-directional SPI mode. The adc I am using says it is SPI compatible but only has the inputs SCLK, CNV and outputs CLKOUT+ and CLKOUT- and SD0+ and SD0-. This leads me to understand that it will only work with bi-directional SPI as there is only the serial data out. I am thinking of using a PWM for CNV (which I think CE), GPIO clock for SCLK and then an interrupt on the falling edge of the GPIO clock to just digitally read each bit from the adc. I don't understand SPI in detail but from what I've read quite often it requires sending data in order to receive it. Do you know if the setup I mentioned (without using SPI) will work? Or am I missing something about SPI and the adc will work with that while not in bi-directional mode?
We are using the Raspberry Pi 3 b
adc - http://cds.linear.com/docs/en/datasheet/232316fa.pdf
Thanks for any help you can provide.

Read the data sheet carefully, in particular pages 8 and 9. I suggest that you tie CMOS/LVDS pin to ground to enable CMOS mode. Then use only the "+"-pins. Use the SCK for SPI clock, SD01+ for SPI data input to the Rpi. Connect a GPIO pin to CNV.
Also observe that the RPi runs at 3.3V, and the ADC's max rating is also 3v3, that is running the IC right to the edge.

Related

Do I need a level converter for Raspberry Pi and STM32 to communicate via GPIO(UART) port?

I want to connect an STM32F407 Discovery board with a Raspberry Pi 4 Model B.
And I want to use UART as communication so I plan to use PD5&6 on STM32 and Pin8&10 on RPi. But after looking up online it says that the voltage of a STM32 port is 5V and RPi is 3.3V, so it seems that I need a level converter between them?
And there are also some articles says that not all the STM32 port are 5V, some are 3.3V. But I cannot find any of that information in the datasheet. Can anyone tell me where can I find these information?
Thank you very much ~ ~
The STM32 uses 3.3V as well. But it's 5V tolerant.
Just go ahead and connect them. There is no voltage difference.
You should have a look at the reference manual for that discovery board. It is here: STM32F407 Reference Manual.
There should be no issue connecting UARTs between those boards. Just remember to connect the TX from one to the RX of the other and vice versa. You can also use the CTS/RTS for flow control, but that isn't necessary as long as you are using baud rates of 115200 or slower.
Something else that I would recommended is to power the Raspberry Pi from the Discovery board. There should be pins for suitable power on the discovery. This is important because it gets both boards using the same power and ground so that the UART logic levels are consistent between the two. This may not be necessary, but I have had issues trying to connect two Nucleo boards SPI busses together if I didn't power one board from the other.

How do I setup one GPIO of raspberry to receive float numbers

So, how do I connect a wire to a gpio on my raspberry and start receiving data, like an int or a float number
Raspberry got great documentation for wiring a simple button to the Raspberry Pi GPIO on https://www.raspberrypi.org/learning/physical-computing-guide/pull_up_down/
To receive float numbers, you could use the Raspberry SPI peripheral. Mathworks got a great example for creating a digital voltmeter with Raspberry and the MPC3008 Analog to Digital converter on https://www.mathworks.com/examples/matlab/mw/raspberrypiio_product-raspi_build_a_digital_voltmeter-build-a-digital-voltmeter
Just to mention since it's not there yet (or only implicitly in the above answer): For actually reading values you need to use an AD converter, since the RPis GPIOs are digital IOs only. So, you cannot receive more then a high or low signal from them. AD conversion instead will use the I2C-Bus for reading the values comming from the converter.

implement SPI MUX driver in Linux [duplicate]

The Arm processor on one of our boards has an spi port with two chip select lines.
It is mentioned in the processor's datasheet that it can control upto two spi devices.
Is it possible to use a GPIO as a slave select for an additional spi device?
How to modify the existing libraries/device drivers to support this change?
So far i've found a file in the kernel's source which contains the addresses of SPI port pins. Can anyone plz tell in which direction should i proceed?
If you have enough pins, you can bitbang the whole SPI protocol and use as many CS as you need.
You don't mention what processor it is. You have three possibilities.
If the processor has an i/o mux capabilities, turn off the SPI chip select functionality. The SPI controller will think it has asserted the line, but it won't go external.
Don't connect one SPI chip select. Use a pull-up/down for ESD protection.
Multiplex the chip select as per Joachim Isaksson
In first two cases, connect GPIOs to the additional device's chip select. Toggle the GPIO manually before running spi_write(), etc. This will allow the SPI controller to transfer at higher rates than are possible with bit banging and is a better system design. Ie, lower power consumption, lower CPU use, faster data rates, etc. If the peripheral is just for setup/boot, then the bit banging makes sense for simplicity. However, if your main operation depends on the SPI bus, you could consider this solution.
If only one peripheral needs the SPI for setup AND you have the i/o mux, you can disable the chip select functionality during setup, using a GPIO to select the setup peripheral and then re-enable the spi chip select during standard system operation for the other peripheral.
Using a GPIO doesn't require user space intervention. Drivers can provide call backs to set the GPIO when in use, so SPI commands can be buffered/queued and these solutions still work. For instance, the IMX SPI driver supports GPIO toggle by passing a negative chip select number to denote a GPIO id.
Note: Some SPI devices may require the chip select to toggle between words; what ever a word is for the device. Some controller may leave the chip select asserted when transferring multiple words. You need to get this right if you use a GPIO to manually select devices. I am sure some standard defines this, but definitely some device don't follow the standard.
Addendum: Most drivers support a GPIO chip select; via a negative chip select value. They will call Linux GPIO functions. Write a GPIO handler that does the de-multiplexing. No need to alter the SPI drivers.

Set initial state as input on pins using FTDI device FT4232H

I am using a USB device from FTDI called FT4232H and I want to write on the EEPROM to make sure that some pins are set to inputs at start. I am using the D2XX drivers (pdf here). Here I found at page 106 that there is a struct called FT_EEPROM_4232H. Could this be something to use to make sure the pins are set to inputs at the beginning or is this totaly wrong? There are four UCHAR variables called A-, B-, C- and DDriverType. Does anyone know what these should be used for?
I realise this question is 3 months old now but I believe pins on the FTx232H series of chips only get set as GPIO once the MPSSE command SetOutput is issued.
The EEPROM configuration is used to define things like drive strength, slew rate and whether the pin is a schmitt input and what each of the 4 ports are set up to be (async FIFO akin to FT245 series, serial port (FT232), etc).
If anyone else can disprove this, I would be interested to know also!
I just plugged my FT232H board in my PC and ran FTDI FT_Prog, it does not appears you can control the GPIO mode input/output at start time. There is nothing in the FTDI FT_Prog UI that allow to set a mode for GPIO pins and set them as input.
I did set programmatically my FT232H board as an SPI device with 8 GPIOS
but this was done after the chip was started.
A video experimenting with the FT232H
I also once asked FTDI support a similar question for the FT232RL which is as default a UART and I asked if there was a way to configure the chip to start in Synchronous bit banging mode and set the GPIOs as OUTPUT. The answer was no.
The FT232RL will always start as a UART and then by software I can activate Synchronous bit banging mode, and set the mode of my GPIO.
I suppose it is the same for the FT232H, FT2232H and FT4232H.

More than two SPI devices on an Arm board that supports only two?

The Arm processor on one of our boards has an spi port with two chip select lines.
It is mentioned in the processor's datasheet that it can control upto two spi devices.
Is it possible to use a GPIO as a slave select for an additional spi device?
How to modify the existing libraries/device drivers to support this change?
So far i've found a file in the kernel's source which contains the addresses of SPI port pins. Can anyone plz tell in which direction should i proceed?
If you have enough pins, you can bitbang the whole SPI protocol and use as many CS as you need.
You don't mention what processor it is. You have three possibilities.
If the processor has an i/o mux capabilities, turn off the SPI chip select functionality. The SPI controller will think it has asserted the line, but it won't go external.
Don't connect one SPI chip select. Use a pull-up/down for ESD protection.
Multiplex the chip select as per Joachim Isaksson
In first two cases, connect GPIOs to the additional device's chip select. Toggle the GPIO manually before running spi_write(), etc. This will allow the SPI controller to transfer at higher rates than are possible with bit banging and is a better system design. Ie, lower power consumption, lower CPU use, faster data rates, etc. If the peripheral is just for setup/boot, then the bit banging makes sense for simplicity. However, if your main operation depends on the SPI bus, you could consider this solution.
If only one peripheral needs the SPI for setup AND you have the i/o mux, you can disable the chip select functionality during setup, using a GPIO to select the setup peripheral and then re-enable the spi chip select during standard system operation for the other peripheral.
Using a GPIO doesn't require user space intervention. Drivers can provide call backs to set the GPIO when in use, so SPI commands can be buffered/queued and these solutions still work. For instance, the IMX SPI driver supports GPIO toggle by passing a negative chip select number to denote a GPIO id.
Note: Some SPI devices may require the chip select to toggle between words; what ever a word is for the device. Some controller may leave the chip select asserted when transferring multiple words. You need to get this right if you use a GPIO to manually select devices. I am sure some standard defines this, but definitely some device don't follow the standard.
Addendum: Most drivers support a GPIO chip select; via a negative chip select value. They will call Linux GPIO functions. Write a GPIO handler that does the de-multiplexing. No need to alter the SPI drivers.