Hello,
i saw this post regarding the above mentioned topic and was wondering if anyone found the solution to this
I was using MCP23S17 and needed to use GPIO pins to be programmed as CS for SPI devices.
Currently for testing i have 2 MAX 31865 modules and i do not have any more gpios left on the microcontroller. the ones i had are being used as MOSI, MISO, CLK , CS for MCP23S17 for using multiple devices.
No practical experience with it but this is how I think it can work.
You need two CS pins, one for the MCP23S17 and one for the all other devices. The latter will be a dummy (nothing connected to it) and is there to keep libraries happy; you can use e.g. the SS pin of the Arduino (on AVR based boards, no experience with other
boards). The actual CS pin for the other device will be connected to the outputs of the MCP23S17.
When communicating with one of the other devices, you first set (low?) the output of one of the pins of the MCP23S17 to select one of the other devices and next communicate with the other device in the usual way. After that you unset (high?) the output pin of the MCP23S17 that provides the CS for the other device.
umm forgive me if i didnt understand it correctly but
what you suggest is programming a pin for the SPI & microcontroller and toggle it as from my code and use the pin from GPIO expander connected to MAX31865 device's CS and toggle it at the same time as the dummy pin.
the second part is a bit difficult to understand for me. how should the flow be ?
I'm not sure using an MCP23S17 to provide multiple CS would work as intended.
I think that the setting of the required CS pin low would work as intended.
However, the process of setting the CS pin high might not work as expected. With the MCP23S17 GPIO output pin set low - i.e. the other SPI device is selected - you would then need to set the MCP23S17 CS pin low in order to write a new GPIO setting - i.e set the other devices CS pin high.
At that point, you will have the CS pin of the MCP23S17 and the CS pin of the other device low at the same time. Data transmitted over SPI would then be received by both devices.
However, if you were to use an MCP23017 - an I2C variant - the process may work as intended.
aaaah how painful is this approach!!
thing is i can use either i2c or spi not both since i am having just 4 empty ports
the other possible (rather impossible) solution would be to find a i2c based rtd to digital convetor which i cannot seem to find
is there any other approach with spi that i can try before labelling this as "i2c is easier" ?
thanks a lot for your help
You could fix the problem described by @markd833 using a discrete logic chip. Various chips could be made to work, for example 74hc32 (quad 2-input OR gates).
This way, your second CS pin would not simply be a "dummy" as described by @sterretje. It would be an input to the logic gates, the other inputs coming from the 23s17.
But you would still need to free-up an Arduino pin to use as that second CS pin.
You would have many free pins on the 23s17. Could that take over from an Arduino pin to free it up?
thank you for your quick reply,
i am using a M5dial , this product from m5stack only gives me 4 configurable pins that I can use externally. Other case would be removing the chip from the casing and using it seperatly but that breaks the whole purpose of that product.
But i do like your soution and it probably works but my limitations cannot allow that. sorry
Is that all you are planning to connect? If so, you could use a logic gate to invert the CS pin for one of the sensors. HIGH selects one sensor, LOW selects the other. If the library you plan to use controls the CS pin, this could require changes to the library in order to work.
No, sorry i should have mentioned this earlier , i have more devices in scope but for testing i wanted to run these two as they were in my hand
but i saw some solutions that were using multiplexers which would give a similar output as this
Your current choice, MAX31865, is often used for PT100 temperature sensors, which are generally used where very high temperatures >500C need to measured. TMP-102 would be destroyed by such high temps!
I often use SHT31 sensors. These are i2c and also measure humidity. They are available in several packages:
Thank you, that is a good alternative.
ill need a bit of research if this can be fit mechanically as a probe wire with ring would have been ideal. but yes, definitely a good option
Thanks .
Don't forget that i2c wires won't go too far. I have successfully used them around 1m long. Others say even longer, but there are no guarantees. There are ways to extend the length, such as i2c extender chips/modules.