-
Notifications
You must be signed in to change notification settings - Fork 7.6k
How to work/interfacing with more than 8 SPI devices on ESP32 #1904
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
@kennythum I would add more hardware. I would connect a MCP23S08(8bit SPI I/O expander) to the SPI use its eight output bits as inputs to an octal bus driver, connect the Output_Enable pin of the bus driver to the ESP32 as the thermocouple's CS pin. Place 3.3k pullups on each of the Octal drivers outputs. These pullups keep the CS pins high when the bus drivers output is disabled. Using it would be a two step process:
This design uses the SPI bus and 2 CS pins to control eight thermocouples. Up to eight MCP23S08 can share the same CS pin, so you could add seven more MCP23S08, that would allow you 64 Thermocouples. Or, use the MCPS17(16bit SPI I/O expander) and go way overboard! Chuck. |
Wow, thanks for the suggestion. But must it be SPI to IO expander? I have some I2C to 8-bit IO IC laying around, not sure is it working. Another question, why can't we use the GPIO of ESP32 to use as CS? I think the ESP32 has some quite amount of GPIO right? |
@kennythum I just recommended an SPI I/O expander because you were already using the SPI bus. I don't know of your 3 pin CS restriction, But, if that is the case then an I/O expander is necessary. Chuck. |
@kennythum I'm also trying the same project as taking values from thermocouples using SPI bus, but the not able to get the correct readings. Following is the code with which I'm trying to interface `#include "max6675.h" void setup() void loop() |
I think you messed up with the CS...you read the device by trigger LOW on the CS pin, not HIGH. When a device's Slave Select pin is low, it communicates with the master. When it's high, it ignores the master. This allows you to have multiple SPI devices sharing the same MISO, MOSI, and CLK lines. Adapted from arduino SPI. |
Thank you...!!! @kennythum |
Helo @stickbreaker . I have tried as per your suggestion. Meanwhile, I can't get the reading properly from the MCP23S17 which connected with arrays of MAX6675 modules. Weird thing was, when i remove everything, and just left out one MAX6675 module on the SPI bus, it can read well, with the normal value (temperature). I do as you suggested, pullup resistor on each CS pin for each MAX6675, and all MAX6675 MISO/SCLK share the pin/bus on the SPI with the MCP23S17. Question, when i read 1 of the MAX6675 which over the MCP23S17, the value i obtain is the value from MCP23S17? or the selected MAX6675?? since they both sharing the same SPI bus, and both, well, consider as CS PIN enabled. God, please help me out... |
@kennythum here is my expander circuit for a MEGA2560 and ESP12 SPI sharing circuit: SPIExpander circuitThis is the Arbitration circuit: between ESP12 and MEGA2560Explanation:The arbitration circuit uses The ESP12 SPI (ESP_SCK,ESP_MOSI, ESP_MISO, ESP_CS1, ESP_CS2) use the lower four bits of the MCP23S08 as four !CS pins. GP4 is an output bit, GP5 is readback of SPI bus ownership(arbitration win). my ESP12 SPI code has two phases:
@kennythum You probably don't need the arbitration circuit, just remove IC11A and control the 'G' pin of the bus driver(74LVC244) directly from your ESP12 with your Second CS pin.
Chuck. |
Thank thank you so much for replying me. At least giving me some little hope, else im clueless! Question 1: why can't we connect all the SPI devices CS to GPn of the MCP23S08? And LOW the GPn and set all the other bit to high, as chip select to the target SPI device, while sharing the same MISO/MOSI/SCLK with the MCP23S08?? what is the main reason of crossing over a 74LVC244DW?? Question 2: Do all the SPI devices share the same MISO/MOSI/SCLK with the MCP23S08?? and from your circuit, I should read my value of the selected device from CS2? Question 3: Is MCP23S08/MCP23S17 of these chip work as merely IO extender? Like really only work as HIGH/LOW function of its pins?? yet we cant interfacing any other function from it's GPIOs?? Thank you a billions for giving me hope! Srsly...appreciate your kindness. |
@kennythum #1 timing. When CS goes low is the start of an SPI transaction. When CS goes high the slave stops monitoring the SPI bus. This means ONLY ONE CS pin CAN be low at a time. A normal transaction consists of:
If you directly connect GPn to the CS input of one of the thermocouples, both the MCP23Sxx and MAX will be driving MISO. #2 YES #3 Input, output, weak pullup, weak pulldown, interrupt on level, change Chuck |
I believe that SPI bus is not the best option for comunicating with other devices. I think it is best to try and establish the communication via the I2C bus. |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions. |
This stale issue has been automatically closed. Thank you for your contributions. |
Dear gurus, Im currently having a project to work with 8 K-type thermocouples, all using MAX6675 individually to read the value and communicate with ESP32 via SPI. Meanwhile, it requires to log the data into a SD card, so there goes another SPI device. My question is, how could all these devices interface with the ESP32?? I'd done some research and all i could found was HSPI or VSPI could only support up to 3 devices. Anyone could shared some light? :roll:
The text was updated successfully, but these errors were encountered: