stronk_8s

SPI Arduino

Nov 24th, 2025
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 0.64 KB | Source Code | 0 0
  1. #include<SPI.h>
  2. char buf[100];
  3. byte c=0,b=0;
  4. volatile byte pos;
  5. volatile boolean processing;
  6. byte i;
  7. void setup(void) {
  8. // put your setup code here, to run once:
  9. Serial.begin(9600);
  10. pinMode(MISO,OUTPUT);
  11. pinMode(MOSI,INPUT);
  12. SPCR |= _BV(SPE);
  13. pos = 0;
  14. processing = false;
  15. SPI.attachInterrupt();
  16. }
  17. ISR(SPI_STC_vect){
  18. c = SPDR;
  19. // SPDR = 0x55;
  20. // if(pos<20){
  21. // buf[pos++] = c;
  22. // if(c == '\n')
  23. // processing=true;
  24. // }
  25. processing = true;
  26. }
  27. void loop(void) {
  28. // put your main code here, to run repeatedly:
  29. if(processing){
  30. // Serial.println("Inside Processing");
  31. Serial.println(c);
  32. processing = false;
  33. SPDR = i;
  34. i = i+1;
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment