Zuweisung verketten

09 Mar 2019

Hallo Zusammen, Hello everybody,

ich möchte in einer Schleife mehrere IO-Expander de­kla­rie­ren: I want to declare several IO expander in a loop:

int i;

for(i=0; i<5; i++) {

char* Ex = "Expander"; strcat(Ex,i); char* Ad = "Adresse"; strcat(Ad,i);

MCP23S17 Ex = MCP23S17(spi, p20 , Ad );

}

So sollte es Aussehen. It should look like this.

Funktionieren wird es natürlich nicht, jetzt kommt Ihr ins spiel ich benötige einen Schupser zur Lösung. Of course, it will not work, now you come into play, I need a shove to solve it.

besten dank im voraus Thank you in advance Dirk

27 Sep 2019

Hello,

If you want to use SPI between mbedOS mcu and MCP23S17 and you want to have several MCP23S17 chips you can have only one SPI Master in your mbedOS device: SPI spi(D11, D12, D13); mosi, miso, sclk look pin names from the board you are using DigitalOut cs_MCP1(D0); look the DO pin name from the board you are using DigitalOut cs_MCP2(D1); DigitalOut cs_MCP3(D2);

Use the correct chip select when you want to communicate selected MCP chip. Here you find example about how to use SPI in mbedOS: https://os.mbed.com/docs/mbed-os/v5.14/apis/spi.html

Regards, Pekka