start:arduino:esp32:i2c_spi:multiple
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| start:arduino:esp32:i2c_spi:multiple [2022/11/01 06:58] – gerardadmin | start:arduino:esp32:i2c_spi:multiple [2023/01/27 16:08] (Version actuelle) – modification externe 127.0.0.1 | ||
|---|---|---|---|
| Ligne 6: | Ligne 6: | ||
| {{ : | {{ : | ||
| + | |||
| + | En bref, pour utiliser HSPI et VSPI simultanément, | ||
| + | |||
| + | 1) Tout d’abord, assurez-vous d’inclure la [[https:// | ||
| + | |||
| + | #include < | ||
| + | |||
| + | 2) Initialiser deux Classe SPI objets avec des noms différents, | ||
| + | |||
| + | vspi = new SPIClass(VSPI); | ||
| + | hspi = new SPIClass(HSPI); | ||
| + | |||
| + | 3) Appeler le beginr() méthode sur ces objets. | ||
| + | |||
| + | vspi.begin(); | ||
| + | hspi.begin(); | ||
| + | |||
| + | Vous pouvez transmettre des broches personnalisées au begin() méthode si nécessaire. | ||
| + | |||
| + | vspi.begin(VSPI_CLK, | ||
| + | hspi.begin(HSPI_CLK, | ||
| + | |||
| + | 4) Enfin, vous devez également définir les broches SS comme sorties. Par exemple: | ||
| + | |||
| + | pinMode(VSPI_SS, | ||
| + | pinMode(HSPI_SS, | ||
| + | |||
| + | Ensuite, utilisez les commandes habituelles pour interagir avec les appareils SPI, que vous utilisiez une bibliothèque de capteurs ou les méthodes de la bibliothèque SPI. | ||
| + | |||
| + | Vous pouvez trouver un exemple d’utilisation de plusieurs bus SPI sur la [[https:// | ||
| + | |||
| + | |||
| + | <code c exemple_Multiple_SPI_ESP32.ino> | ||
| + | |||
| + | |||
| + | |||
| + | /* The ESP32 has four SPi buses, however as of right now only two of | ||
| + | * them are available to use, HSPI and VSPI. Simply using the SPI API | ||
| + | * as illustrated in Arduino examples will use VSPI, leaving HSPI unused. | ||
| + | | ||
| + | * However if we simply intialise two instance of the SPI class for both | ||
| + | * of these buses both can be used. However when just using these the Arduino | ||
| + | * way only will actually be outputting at a time. | ||
| + | | ||
| + | * Logic analyser capture is in the same folder as this example as | ||
| + | * " | ||
| + | | ||
| + | * created 30/04/2018 by Alistair Symonds | ||
| + | */ | ||
| + | #include < | ||
| + | |||
| + | // Define ALTERNATE_PINS to use non-standard GPIO pins for SPI bus | ||
| + | |||
| + | #ifdef ALTERNATE_PINS | ||
| + | #define VSPI_MISO | ||
| + | #define VSPI_MOSI | ||
| + | #define VSPI_SCLK | ||
| + | #define VSPI_SS | ||
| + | |||
| + | #define HSPI_MISO | ||
| + | #define HSPI_MOSI | ||
| + | #define HSPI_SCLK | ||
| + | #define HSPI_SS | ||
| + | #else | ||
| + | #define VSPI_MISO | ||
| + | #define VSPI_MOSI | ||
| + | #define VSPI_SCLK | ||
| + | #define VSPI_SS | ||
| + | |||
| + | #define HSPI_MISO | ||
| + | #define HSPI_MOSI | ||
| + | #define HSPI_SCLK | ||
| + | #define HSPI_SS | ||
| + | #endif | ||
| + | |||
| + | #if CONFIG_IDF_TARGET_ESP32S2 || CONFIG_IDF_TARGET_ESP32S3 | ||
| + | #define VSPI FSPI | ||
| + | #endif | ||
| + | |||
| + | static const int spiClk = 1000000; // 1 MHz | ||
| + | |||
| + | // | ||
| + | SPIClass * vspi = NULL; | ||
| + | SPIClass * hspi = NULL; | ||
| + | |||
| + | void setup() { | ||
| + | // | ||
| + | vspi = new SPIClass(VSPI); | ||
| + | hspi = new SPIClass(HSPI); | ||
| + | | ||
| + | //clock miso mosi ss | ||
| + | |||
| + | #ifndef ALTERNATE_PINS | ||
| + | // | ||
| + | //SCLK = 18, MISO = 19, MOSI = 23, SS = 5 | ||
| + | vspi-> | ||
| + | #else | ||
| + | // | ||
| + | vspi-> | ||
| + | #endif | ||
| + | |||
| + | #ifndef ALTERNATE_PINS | ||
| + | // | ||
| + | //SCLK = 14, MISO = 12, MOSI = 13, SS = 15 | ||
| + | hspi-> | ||
| + | #else | ||
| + | // | ||
| + | hspi-> | ||
| + | #endif | ||
| + | |||
| + | //set up slave select pins as outputs as the Arduino API | ||
| + | // | ||
| + | pinMode(vspi-> | ||
| + | pinMode(hspi-> | ||
| + | |||
| + | } | ||
| + | |||
| + | // the loop function runs over and over again until power down or reset | ||
| + | void loop() { | ||
| + | //use the SPI buses | ||
| + | spiCommand(vspi, | ||
| + | spiCommand(hspi, | ||
| + | delay(100); | ||
| + | } | ||
| + | |||
| + | void spiCommand(SPIClass *spi, byte data) { | ||
| + | //use it as you would the regular arduino SPI API | ||
| + | spi-> | ||
| + | digitalWrite(spi-> | ||
| + | spi-> | ||
| + | digitalWrite(spi-> | ||
| + | spi-> | ||
| + | } | ||
| + | |||
| + | </ | ||
| + | |||
| + | |||
| + | |||
/home/chanteri/www/fablab37110/data/attic/start/arduino/esp32/i2c_spi/multiple.1667282315.txt.gz · Dernière modification : (modification externe)
