Last active
August 1, 2019 17:01
-
-
Save xopr/05ce68a74acc9de5deb650cd8429b0bb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// NOTE: make sure you disable the Arduino reset when using as serial terminal | |
// run: `systemctl enable [email protected]` (or the appropriate Arduino serial device | |
// edit: `/etc/systemd/system/getty.target.wants/[email protected]` | |
// and change | |
// ExecStart=...... $TERM | |
// into: | |
// ExecStart=...... vt52 | |
// then run: `systemctl daemon-reload` | |
// and: `systemctl restart [email protected]` | |
#define SERIAL_BUFFER_SIZE 1024 | |
//from https://forum.arduino.cc/index.php?topic=52111.0 | |
#include "pins_arduino.h" | |
volatile char serialByte = 0; | |
volatile char spiByte = 0; | |
void setup (void) | |
{ | |
Serial.begin( 9600 ); | |
// have to send on master in, *slave out* | |
pinMode(MISO, OUTPUT); | |
// turn on SPI in slave mode | |
SPCR |= _BV(SPE); | |
// turn on interrupts | |
SPCR |= _BV(SPIE); | |
} | |
// SPI interrupt routine | |
ISR (SPI_STC_vect) | |
{ | |
spiByte = SPDR; | |
SPDR = serialByte; | |
serialByte = 0; | |
} | |
// main loop - wait for flag set in interrupt routine | |
void loop (void) | |
{ | |
if ( spiByte && spiByte > 0 ) | |
{ | |
Serial.print( spiByte ); | |
spiByte = 0; | |
} | |
if ( !serialByte && Serial.available() ) | |
serialByte = Serial.read(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment