Page 1 of 1

MCP23S17 ESP-IDF library

Posted: Mon Feb 18, 2019 4:24 pm
by commando_j
Hello,

I'm wondering if anyone has made any progress in a library for the MCP23S17 (SPI version) that is native to the ESP-IDF? I have seen the Arduino version, but I'm having trouble understanding how to get it to work with ESP-IDF and Eclipse. I saw a few people working on a solution, but no one posted any final resolution. I'm hoping someone completed their work and would share their solutions.

Thanks

Re: MCP23S17 ESP-IDF library

Posted: Mon Feb 18, 2019 6:31 pm
by mikemoy
Give this a shot

Re: MCP23S17 ESP-IDF library

Posted: Mon Feb 18, 2019 6:42 pm
by commando_j
Thank you! Can't wait to get home and try it.

May take a day or two. I'm about to test to make sure I can send something on the bus with simple transmit command to make sure the connections and initilization of SPI is good.

Love the forum.

Re: MCP23S17 ESP-IDF library

Posted: Mon Feb 25, 2019 2:28 am
by commando_j
It works!

After getting home the other night, I blew up my one prototype by putting 12V to the ESP32 reset line! So I just got everything hooked back up with my ESP32 dev board and just the MCP23S17 on my PCB, connected with jumper wires.

I noted that your SPI setup is only running at 10Khz, is there a reason why it's so low?
Other notes:
- You write to GPIOA only, but you write 2 bytes, so essentially you write to GPIOA and B at the same time. You do this elsewhere with other registers that are next to each other. Not an issue, just took me a bit of time to see that.
- In the GpioMode function, you set _modeCache = mode, but _modeCache is not used to write a Word to the MCP23S17. I figure for this one routine, setting _modeCache was not needed.

Thanks again.

Re: MCP23S17 ESP-IDF library

Posted: Mon Feb 25, 2019 3:37 am
by mikemoy
I noted that your SPI setup is only running at 10Khz, is there a reason why it's so low?
I dont need the speed for my application and my PCB is 12" x 13" in size. The ESP32 is on one end and the MCP23S17 is on the other end, so I did not want to run a high freq across the PCB.
You write to GPIOA only, but you write 2 bytes, so essentially you write to GPIOA and B at the same time. You do this elsewhere with other registers that are next to each other. Not an issue, just took me a bit of time to see that.
Correct, The part is set up in auto increment mode. So when you write to GPIOA, it will auto increment the register so you can then write to that register without issuing another register location and write again. Its just a way to write a word faster to it.
In the GpioMode function, you set _modeCache = mode, but _modeCache is not used to write a Word to the MCP23S17. I figure for this one routine, setting _modeCache was not needed.
It is needed because if you later use mcp23S17_GpioPinMode, because it uses _modeCache

Re: MCP23S17 ESP-IDF library

Posted: Fri Jun 14, 2019 8:13 pm
by bonmotwang
mikemoy wrote:
Mon Feb 18, 2019 6:31 pm
Give this a shot
You are the best!

Thanks

Paul