Hi everyone guys, i've a problem keeping MCP23S17 in SPI mode working with my bluepill. I'm using the official arduino STM core (not the roger one) and this library
https://github.com/MajenkoLibraries/MCP23S17. I've modified this library in the readPort(uint8_t port); function adding a parameter that can permit me to detect the MCP reading the IOCONA register as this
Code: Select all
uint8_t MCP23S17::readPort(uint8_t port) {
if (port == 2) {
readRegister(MCP_IOCONA);
return _reg[MCP_IOCONA];
}
if (port == 0) {
readRegister(MCP_GPIOA);
return _reg[MCP_GPIOA];
} else {
readRegister(MCP_GPIOB);
return _reg[MCP_GPIOB];
}
}
For first i've tested this code and library with the same HW (Cables, breakout board which this MCP is installed etc..) using an Arduino Mega. All worked perfectly, i've received my decimal 24 reading the IOCONA register and i tested it reading the GPIO expander. All fine. But going to the STM32 is going to made me crazy so i'm asking for help. I've tested using 3.3V and 5V source on MCP but i always read 0 in GPIO register and IOCONA register too.
I would prefer to use SPI2 interface, becouse after test a TFT ILI9486 will use the SPI1 PINS.
Thank you.
by ag123 » Mon Nov 15, 2021 3:59 am
i took a look at the specs, it says 10 Mhz max for SPI bus.
https://www.microchip.com/en-us/product/MCP23S17
use spi.BeginTransaction, pass a SPISettings with a lower speed like 10 Mhz to see if it helps.
defacto SPI speeds for stm32 is like 50 Mhz, everyone assumed u'd need it to go 'as fast as possible'
Other things include setting up SPI, initializing SPI using the correct pins.
https://github.com/stm32duino/wiki/wiki/API#spi
the default SPI normally goes to SPI 1
Go to full post