Outils pour utilisateurs

Outils du site


spi_documentation_2

Ceci est une ancienne révision du document !


Communication entre Raspberry Pi et Arduino en SPI

Cette page est inspirée de penguintutor.com Using Raspberry Pi and Arduino together through SPI serial communications

  1. # include SPI.h
  2.  
  3. void setup()
  4. {
  5. // Set the Main in Secondary Out as an output
  6. pinMode(MISO, OUTPUT);
  7. // turn on SPI as a secondary
  8. // Set appropriate bit in SPI Control Register
  9. SPCR |= _BV(SPE);
  10. }
  11.  
  12. // The following code is then used to receive a byte and then set the data register to return a byte to the master controller device.
  13. void loop ()
  14. {
  15. byte in_byte;
  16. // SPIF indicates transmission complete (byte received)
  17. if ((SPSR & (1 << SPIF)) != 0)
  18. {
  19. in_byte = SPDR;
  20. // Handle the input code here
  21. // Set return_val to the value you want to return
  22. SPDR = return_val;
  23. }
spi_documentation_2.1653916785.txt.gz · Dernière modification : de serge