Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
#include <SoftwareSerial.h>
// Pin definitions
const int rfid_irq = 0;
const int rfid_tx_pin = 6;
const int rfid_rx_pin = 7;
// For communication with RFID module
SoftwareSerial rfid(rfid_tx_pin, rfid_rx_pin);
// Indicates that a reading is now ready for processing
volatile bool ready = false;
// Buffer to contain the reading from the module
uint8_t buffer[14];
uint8_t* buffer_at;
uint8_t* buffer_end = buffer + sizeof(buffer);
void rfid_read(void);
void setup(void)
{
// Open serial connection to host PC to view output
Serial.begin(57600);
Serial.println("rfid_simple");
// Open software serial connection to RFID module
pinMode(rfid_tx_pin,INPUT);
rfid.begin(9600);
// Listen for interrupt from RFID module
attachInterrupt(rfid_irq,rfid_read,FALLING);
}
void loop(void)
{
if ( ready )
{
ready = false;
// Print the buffer
Serial.print("Reading: ");
const uint8_t* bp = buffer;
while ( bp < buffer_end )
Serial.print(*bp++);
Serial.println();
}
}
void rfid_read(void)
{
// Read characters into the buffer until it is full
buffer_at = buffer;
while ( buffer_at < buffer_end )
*buffer_at++ = rfid.read();
// Signal that the buffer has data ready
ready = true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment