spi_documentation_2
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 | ||
| spi_documentation_2 [2022/05/30 15:33] – serge | spi_documentation_2 [2022/05/31 07:45] (Version actuelle) – serge | ||
|---|---|---|---|
| Ligne 4: | Ligne 4: | ||
| </ | </ | ||
| - | =====Qui ne marche | + | =====Une ESP32 n'est pas une carte Arduino===== |
| + | **Les sketchs ci-dessous | ||
| + | |||
| + | =====Exemple 1===== | ||
| + | https:// | ||
| + | |||
| + | Raspberry Pi (master) Arduino Uno (slave) SPI communication with WiringPi | ||
| + | |||
| + | <code csharp> | ||
| + | #include < | ||
| + | void setup() { | ||
| + | // have to send on master in, *slave out* | ||
| + | pinMode(MISO, | ||
| + | // turn on SPI in slave mode | ||
| + | SPCR |= _BV(SPE); | ||
| + | // turn on interrupts | ||
| + | SPI.attachInterrupt(); | ||
| + | } | ||
| + | // SPI interrupt routine | ||
| + | ISR (SPI_STC_vect) | ||
| + | { | ||
| + | byte c = SPDR; | ||
| + | SPDR = c+10; | ||
| + | } // end of interrupt service routine (ISR) for SPI | ||
| + | |||
| + | void loop () { } | ||
| + | </ | ||
| + | |||
| + | **Raspberry Pi avec wiringPi** | ||
| + | < | ||
| + | #include < | ||
| + | #include < | ||
| + | #define SPI_CHANNEL 0 | ||
| + | #define SPI_CLOCK_SPEED 1000000 | ||
| + | int main(int argc, char **argv) | ||
| + | { | ||
| + | int fd = wiringPiSPISetupMode(SPI_CHANNEL, | ||
| + | if (fd == -1) { | ||
| + | std::cout << " | ||
| + | return -1; | ||
| + | } | ||
| + | std::cout << "SPI communication successfully setup.\n"; | ||
| + | |||
| + | unsigned char buf[2] = { 23, 0 }; | ||
| + | wiringPiSPIDataRW(SPI_CHANNEL, | ||
| + | std::cout << "Data returned: " << +buf[1] << " | ||
| + | return 0; | ||
| + | } | ||
| + | </ | ||
| + | Voir le lien pour la compilation de wiringPi et de ce script | ||
| + | |||
| + | =====Exemple 2===== | ||
| Tiré de [[http:// | Tiré de [[http:// | ||
| - | SPCR et SPDR pas défini ! | + | Arduino: |
| ====Raspberry==== | ====Raspberry==== | ||
| - | <code python | + | <code python> |
| import spidev | import spidev | ||
| import time | import time | ||
| Ligne 82: | Ligne 133: | ||
| ====Arduino==== | ====Arduino==== | ||
| - | <code csharp | + | <code csharp> |
| #include < | #include < | ||
| // track if digital pins are set as input or output (saves reading registers) | // track if digital pins are set as input or output (saves reading registers) | ||
spi_documentation_2.1653924795.txt.gz · Dernière modification : de serge
