MCP23S17 and BluePill Problem

Post here first, or if you can't find a relevant section!
Post Reply
SG_47
Posts: 2
Joined: Sun Nov 14, 2021 9:56 pm

MCP23S17 and BluePill Problem

Post by SG_47 »

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
mrburnette
Posts: 633
Joined: Thu Dec 19, 2019 1:23 am
Answers: 7

Re: MCP23S17 and BluePill Problem

Post by mrburnette »

Suggestion: Either fully nest the "if"s with "else" or better, use a switch-case structure.

Also, the Mega's int is int16_t and the STM32 int is int32_t, so adjust your parameter accordingly.
ag123
Posts: 1655
Joined: Thu Dec 19, 2019 5:30 am
Answers: 24

Re: MCP23S17 and BluePill Problem

Post by ag123 »

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
SG_47
Posts: 2
Joined: Sun Nov 14, 2021 9:56 pm

Re: MCP23S17 and BluePill Problem

Post by SG_47 »

ag123 wrote: 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
Man i Love You! You resolved my problem! I have to set this to 10Mhz with begin transaction!
Post Reply

Return to “General discussion”