Hi, i wrote a driver for an ADS1118 (16bit ADC for thermocouples measurment)
The ADS1118 as a sdo/drdy pin who share MISO from SPI and a data ready pin
When The SPI transmission was finished and cs pin remain low i need to read the state of MISO pin (maybe interrupt on it)
Is it possible to
- get the pyboard name af the spi miso pin with pyb.SPI module?
-i trie to deinit spi & inti pin for read it but it dosent work in stress test
- read the state of miso pin wiout the need of pyb.pin module
Tanks Médéric
Use pyb.SPI & pyb.Pin together
Re: Use pyb.SPI & pyb.Pin together
I'm not aware of any "builtin" way to determine which pin SPI1 MISO is using.
There is a pins_af.py file created which includes all of the pins defined for a board and the alternate functions.
So you could walk through that looking for SPI1_MISO and check to see if that pin was configured in the appropriate alternate function.
Once you've got a pin ('X7' for example which corresponds to SPI1_MISO) you can change the alternate function of the pin between say a GPIO and SPI functionality.
Something like:
It turns out you can read the value of a pin even when its configured for some other purpose. So you can use miso.value() to read the pin. This behaviour may be chip specific (i.e. some chips do things a bit differently), but the STM series all behave this way.
There is a pins_af.py file created which includes all of the pins defined for a board and the alternate functions.
So you could walk through that looking for SPI1_MISO and check to see if that pin was configured in the appropriate alternate function.
Once you've got a pin ('X7' for example which corresponds to SPI1_MISO) you can change the alternate function of the pin between say a GPIO and SPI functionality.
Something like:
Code: Select all
>>> spi = pyb.SPI(1, pyb.SPI.MASTER)
>>> miso = pyb.Pin('X7')
>>> miso
Pin(Pin.cpu.A6, mode=Pin.AF_PP, pull=Pin.PULL_UP, af=Pin.AF5_SPI1)
>>> miso.value()
1
Re: Use pyb.SPI & pyb.Pin together
Tks for the reply
It work great to read a Pin.value() without initiate it before
Sadly there is now easy way to know witch pin SPI or I2C bus use
I hope this functionnality was added in a future update of µpython
It work great to read a Pin.value() without initiate it before
Sadly there is now easy way to know witch pin SPI or I2C bus use
I hope this functionnality was added in a future update of µpython