Place to put your Basic demos and examples

Moderator: Mmiscool

User avatar
By Ecoli-557
#54551 Electroguard-
I have NOT been successful in getting the interrupt pin on the port expander to work. Now settling for a polling routine which should be OK as well - once I get more experience with the commands.

The nice thing is you can use multiple MCP23S17s all using the same 4 SPI lines - as well as the same chip select - if you turn on HAEN (hardware addressing enable). Once I get my project further down the road - I will attempt to use the same chip select as the TFT.

By the way, there is a new SPI command available; it is called spi.setfrequency and seems to work nicely! According to my logic analyzer, the ESP shifts the SPI clock back and forth from 20MHz for the TFT display to 10MHz which is what I have set the spi.setfrequency to.

I noticed Mike hasen't quite gotten it into the documentation but I have worked with mike over the weekend to test it for him and it worked for me - others need to test and confirm as well.
Usage: spi.setfrequency = 10000000 - for 10MHz as an example.
Caveat is that you MUST use this if the ESP has written or read anything to/from the TFT, once that is understood, you simply place the statement right before you access your slower devices. It seems anytime the ESP accesses the TFT, it uses its native clock speed of 20MHz and does not reduce speed when through accessing as other libraries do. Many devices can and do run at that clock speed but I didn't want to push the MCP datasheet too much although there are many posts on other forums which state that the 10MHz speed is quite conservative. I will try it at 20MHz later today which, in theory, will not make me 'sprinkle' the spi.setfrequency commands throughout the code.
I am certain Mike will enhance this even further once he puts more SPI features in so we can use more peripherals - he just needs more space with the builds.

Thanks again Mike!
User avatar
By renda
#57926 I also test the MCP23017, but it does not work. The address is visible via I2C scanner 0x20
A0, A1, A2 = 0 at output 0V instead of 5V. I2C pin is default wire 0.2

code:

address = 32
i2c.begin (address)
i2c.write (0) 'IODIRA register
i2c.write (0) "set all of the port and it outputs
i2c.end ()

i2c.begin (address)
i2c.write (18) 'GPIO register
i2c.write (255) 'port and All High
i2c.end ()

Do not know what. Can you help me.
User avatar
By Ecoli-557
#57948 You may have the I2C version. I used the SPI version as I also wanted to use the TFT screen which is also SPI.
Check the actual IC part number and confirm it is MCP23S17. The 'S' mean SPI.
Regards.