Advertisement
Guest User

Untitled

a guest
Mar 17th, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <SPI.h>
  2.  
  3. ISR (SPI_STC_vect) {
  4.     static uint16_t v = 0;
  5.  
  6.     uint8_t c = SPDR;
  7.  
  8.     // if bit 7 is set, then retrieve a value
  9.     // from the adc and send its upper bits
  10.  
  11.     if (c & 128) {
  12.         int ch = A0 + c;
  13.         v = analogRead(ch);
  14.         SPDR = v >> 8;
  15.     }
  16.     else {
  17.         SPDR = v;
  18.     }
  19. }
  20.  
  21. void setup (void) {
  22.     Serial.begin(115200);
  23.     Serial.println(F("Init " __DATE__ " " __TIME__));
  24.  
  25.     pinMode(SCK, INPUT);
  26.     pinMode(MOSI, INPUT);
  27.     pinMode(MISO, OUTPUT);
  28.     pinMode(SS, INPUT);
  29.  
  30.     // enable SPI slave mode
  31.     SPCR |= _BV(SPE);
  32.  
  33.     // switch on interrupts
  34.     SPCR |= _BV(SPIE);
  35. }
  36.  
  37. void loop (void) {
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement