Guest User

Untitled

a guest
May 24th, 2018
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. #include <SPI.h>
  2. char buff [50];
  3. volatile byte indx;
  4. volatile boolean process;
  5.  
  6. void setup() {
  7. Serial.begin (115200);
  8. pinMode(MISO, OUTPUT); // have to send on master in so it set as output
  9. SPCR |= _BV(SPE); // turn on SPI in slave mode
  10. indx = 0; // buffer empty
  11. process = false;
  12. SPI.attachInterrupt(); // turn on interrupt
  13. }
  14.  
  15. ISR (SPI_STC_vect) {// SPI interrupt routine
  16. byte c = SPDR; // read byte from SPI Data Register
  17. if (indx < sizeof buff) {
  18. buff [indx++] = c; // save data in the next index in the array buff
  19. if (c == '\r') //check for the end of the word
  20. process = true;
  21. }
  22. }
  23.  
  24. void loop(){
  25. if (process) {
  26. process = false; //reset the process
  27. Serial.println (buff); //print the array on serial monitor
  28. indx= 0; //reset button to zero
  29. }
  30. }
Add Comment
Please, Sign In to add comment