Poll the value of MISO Pin from SPI without starting SPI transfer

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
rkompass
Posts: 66
Joined: Fri Sep 17, 2021 8:25 pm

Poll the value of MISO Pin from SPI without starting SPI transfer

Post by rkompass » Sun Nov 21, 2021 8:02 pm

Hello,

I wrote a driver for the TI ADS1220 24-bit analog to digital converter. This chip has a separate DRDY_ (data ready) output to indicate that a conversion is finished and ready for readout via spi. But there also is the option to read drdy_ via the MISO pin, given the chip is active via CS_ (chip select). I prefer this because it saves a pin on the controller.

First question:
Can I extract the miso pin from just the spi structure?
In:

Code: Select all

class Ads1220:
def __init__(self, spi, cs, drdy=None, ain_pos=0, ain_neg=4, sps=20, ..
this would make the argument drdy obsolete.
Currently I have

Code: Select all

miso = Pin('B14', Pin.IN)   # do this before setting up spi, because the pin is redefined,
spi = SPI(2, baudrate=1000000, phase=1)
cs = Pin('B12', Pin.OUT_PP, value=1)
ads = Ads1220(spi, cs, miso)
in the user program and it would be more elegant (and simpler for newcomers) to just make

Code: Select all

ads = Ads1220(spi, cs)
sufficient.

Ideally there would be a function spi.miso_value() in micropython which I could use in the driver. Did anyone program such a thing or did consider to do so?
I would try to program it but I would need some help.

Second question: I use miso.value() in the driver and it works. The value of drdy is read out this way as long as there is no spi clock starting an spi transfer. Is this a reliable option given that the pin is redefined to alternating function SPI (af=Pin.AF5_SPI2)?

Post Reply