simple spi with multiple devices
simple spi with multiple devices
Hello,
I'm working with the esp idf 4.3 example hd_eeprom. I've got 3 different devices connected to the spi bus with separate chip selects. Is there a simpler example that shows how to init the bus, read and write bytes or sequences of bytes to a particular device, one at a time by only changing the respective chip select for the device being talked to? The hd_eeprom example seems taylored to one device only and is a bit difficult to follow. Any simpler code examples would be appreciated.
Thanks
I'm working with the esp idf 4.3 example hd_eeprom. I've got 3 different devices connected to the spi bus with separate chip selects. Is there a simpler example that shows how to init the bus, read and write bytes or sequences of bytes to a particular device, one at a time by only changing the respective chip select for the device being talked to? The hd_eeprom example seems taylored to one device only and is a bit difficult to follow. Any simpler code examples would be appreciated.
Thanks
-
- Posts: 112
- Joined: Thu Oct 03, 2019 10:52 pm
- Contact:
Re: simple spi with multiple devices
What kind of SPI device do you want to run?
Re: simple spi with multiple devices
Im curious about this too. Id like to use an SD card and an MCP2515 CAN controller on the same SPI bus...hopefully its possible...?
-
- Posts: 7
- Joined: Mon Oct 11, 2021 12:21 pm
Re: simple spi with multiple devices
why are you using an SPI can interface when there is a can interface built into the ESP32?? Look up TWAI in the esp-idf documentation.
You need a transceiver like the MCP2562. This gives you all of the same features as the MCP2515 but without having to muck about with the registers to get and set he data. It can also be set up so when there is no CAN traffic you can put the ESP32 into a deep sleep and also put the transceiver into a standby state. When the transceiver sees any activity on the bus it will wake the ESP32. The transceiver accepts 3.3v and 5.0v and if you are using a 5.0v supply there is a ref pin you can attach 3.3v to so you won't need a logic level shifter. The cost is something like 1.00USD and it comes in a through hole variant so testing can be done using a bread board.
Re: simple spi with multiple devices
Im well aware of how the ESP32's internal CAN controller works. Ive been using it for years........kgschlosser wrote: ↑Sun Oct 17, 2021 4:25 amwhy are you using an SPI can interface when there is a can interface built into the ESP32?? Look up TWAI in the esp-idf documentation.
You need a transceiver like the MCP2562. This gives you all of the same features as the MCP2515 but without having to muck about with the registers to get and set he data. It can also be set up so when there is no CAN traffic you can put the ESP32 into a deep sleep and also put the transceiver into a standby state. When the transceiver sees any activity on the bus it will wake the ESP32. The transceiver accepts 3.3v and 5.0v and if you are using a 5.0v supply there is a ref pin you can attach 3.3v to so you won't need a logic level shifter. The cost is something like 1.00USD and it comes in a through hole variant so testing can be done using a bread board.
My application requires two separate CAN busses. The ESP32 only has one CAN controller built in, thats why my design also has an MCP2515.
-
- Posts: 7
- Joined: Mon Oct 11, 2021 12:21 pm
-
- Posts: 7
- Joined: Mon Oct 11, 2021 12:21 pm
Re: simple spi with multiple devices
and yes you can use an SD card reader and also the CAN interface on the same bus. You are going to have to have a cable select pin set up for each device and when you want that device to listen you turn off the select pin for that device. When finished turn it back on.
errr I think it's off is selected for use and on is idle.You would have to double check that, been a while since I have used SPI.
errr I think it's off is selected for use and on is idle.You would have to double check that, been a while since I have used SPI.
-
- Posts: 75
- Joined: Fri Dec 04, 2020 9:56 pm
Re: simple spi with multiple devices
Generally speaking (have not checked IDF implementation), there can be issues with card initialization (at its insertion, before the card enters SPI communication mode).
Last edited by Victoria Nope on Thu Oct 21, 2021 8:44 am, edited 1 time in total.
Re: simple spi with multiple devices
yes...we all know how SPI works. Obviously you need chip-select lines for each slave................kgschlosser wrote: ↑Wed Oct 20, 2021 2:07 amand yes you can use an SD card reader and also the CAN interface on the same bus. You are going to have to have a cable select pin set up for each device and when you want that device to listen you turn off the select pin for that device. When finished turn it back on.
errr I think it's off is selected for use and on is idle.You would have to double check that, been a while since I have used SPI.
Im guessing you havent actually tried using an SD card in 1-bit SPI mode and an MCP2515 together on the same bus in real life since you're just giving elementary level answers that are better suited for an Arduino website.
Sometimes real life applications dont work they way they're supposed to, sometimes certain SPI slaves dont exactly follow protocol. Sometimes slaves dont tri-state their MISO outputs, sometimes they output garbage on power up, etc.
Im saying this because prototyping on the bench, im having some issues getting them to both work together. The SD card seems to initialize correctly, but when working side-by-side with the MCP2515, I have to read the SD card twice after suspending MCP2515 communications. The first read returns a 0x107 or 0x108 error.
So obviously theres something in software or hardware that is preventing them from coexisting seamlessly.
-
- Posts: 7
- Joined: Mon Oct 11, 2021 12:21 pm
Re: simple spi with multiple devices
As the thread title states... "simple spi with multiple devices." The key words in that being SIMPLE So perhaps you need to go back to school and learn how to read instead of incorrectly criticizing my answer
and as far as your bench test is concerned. maybe using different hardware instead of something that is flawed will give you a correct outcome. maybe that is too much of an entry level solution for ya.
and as far as your bench test is concerned. maybe using different hardware instead of something that is flawed will give you a correct outcome. maybe that is too much of an entry level solution for ya.
Who is online
Users browsing this forum: No registered users and 86 guests