Reorganizing library structure, prep for 2.0.0
This commit is contained in:
@@ -0,0 +1,12 @@
|
||||
#include <DigitalIO.h>
|
||||
// Create object for pin 13 in output mode and demo toggle().
|
||||
DigitalPin<13> pin13(OUTPUT);
|
||||
|
||||
void setup() {}
|
||||
|
||||
void loop() {
|
||||
// toggle is a two byte instruction that executes
|
||||
// in two cycles or 125 ns on a 16 MHz CPU
|
||||
pin13.toggle();
|
||||
delay(250);
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
// Demo of config() and fast toggle() function.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
// Class with compile time pin number.
|
||||
DigitalPin<13> pin13;
|
||||
|
||||
void setup() {
|
||||
// Set mode to OUTPUT and level LOW.
|
||||
pin13.config(OUTPUT, LOW);
|
||||
}
|
||||
void loop() {
|
||||
// toggle is a two byte instruction that executes
|
||||
// in two cycles or 125 ns on a 16 MHz CPU
|
||||
pin13.toggle();
|
||||
delay(100);
|
||||
pin13.toggle();
|
||||
delay(400);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
// Read pin 12 and write value to pin 13.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
DigitalPin<12> pin12(INPUT);
|
||||
DigitalPin<13> pin13(OUTPUT);
|
||||
|
||||
void setup() {}
|
||||
|
||||
void loop() {
|
||||
pin13 = pin12;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
// Scope test for fast shiftOut function.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
// Create clockPin in output mode with inital level LOW.
|
||||
DigitalPin<12> clockPin(OUTPUT, LOW);
|
||||
|
||||
// Create dataPin in output mode with inital level HIGH.
|
||||
DigitalPin<13> dataPin(OUTPUT, HIGH);
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
// Time to send one bit is ten cycles or 625 ns for 16 MHz CPU.
|
||||
inline __attribute__((always_inline))
|
||||
void sendBit(uint8_t bit, uint8_t data) {
|
||||
dataPin = data & (1 << bit);
|
||||
clockPin = 1;
|
||||
// may want a nop here - clock pulse is 125 ns wide
|
||||
clockPin = 0;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// Time to send one byte is 5 usec.
|
||||
void shiftOut(uint8_t bits) {
|
||||
sendBit(7, bits);
|
||||
sendBit(6, bits);
|
||||
sendBit(5, bits);
|
||||
sendBit(4, bits);
|
||||
sendBit(3, bits);
|
||||
sendBit(2, bits);
|
||||
sendBit(1, bits);
|
||||
sendBit(0, bits);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
// Not used.
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {
|
||||
shiftOut(0X55);
|
||||
delay(2);
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
// Use begin to assign pin numbers.
|
||||
// Read pin 12 and write the value to pin 13.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
// Declare the PinIO instances.
|
||||
PinIO readPin;
|
||||
PinIO writePin;
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
// Assign pin 12 to readPin.
|
||||
readPin.begin(12);
|
||||
|
||||
// input mode with pull-ups disabled
|
||||
readPin.config(INPUT, LOW);
|
||||
|
||||
// Assign pin 13 to writePin and set mode to output.
|
||||
writePin.begin(13);
|
||||
writePin.mode(OUTPUT);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {
|
||||
// Copy the value read from readPin to writePin.
|
||||
writePin.write(readPin.read());
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Test the config() and toggle() functions.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
// Set runtime pin number.
|
||||
PinIO pin13(13);
|
||||
|
||||
void setup() {
|
||||
// set mode to OUTPUT and level LOW
|
||||
pin13.config(OUTPUT, LOW);
|
||||
}
|
||||
void loop() {
|
||||
pin13.toggle();
|
||||
delay(100);
|
||||
pin13.toggle();
|
||||
delay(400);
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
// Read pin 12 and write the value to pin 13.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
PinIO readPin(12);
|
||||
PinIO writePin(13);
|
||||
|
||||
void setup() {
|
||||
// Set input mode and disable pull-up.
|
||||
readPin.config(INPUT, LOW);
|
||||
|
||||
// set output mode
|
||||
writePin.mode(OUTPUT);
|
||||
}
|
||||
void loop() {
|
||||
writePin.write(readPin.read());
|
||||
}
|
||||
@@ -0,0 +1,78 @@
|
||||
/* Scan I2C bus for devices.
|
||||
*
|
||||
* For I2C write addresses: the scanner sends a start,
|
||||
* the write address, looks for an ACK, then sends a stop.
|
||||
*
|
||||
* For I2C read addresses: the scanner sends a start, the
|
||||
* read address, looks for an ACK. If there is an ACK, it
|
||||
* reads a byte and NACKs it. Finally it sends a stop.
|
||||
*
|
||||
* When the I2C chip responds to the read address, it
|
||||
* outputs data and will miss a stop condition sent
|
||||
* immediately after the read address (bus contention).
|
||||
*
|
||||
* If the I2C chip misses the stop condition, the
|
||||
* address scanner will see ghost addresses until the
|
||||
* read ends randomly. By reading a byte after any read
|
||||
* address that ACKs, there is a chance to NACK the read
|
||||
* and properly end the I2C transaction.
|
||||
*/
|
||||
#include <DigitalIO.h>
|
||||
|
||||
// Set pin numbers for your configuration.
|
||||
const uint8_t SDA_PIN = A4;
|
||||
const uint8_t SCL_PIN = A5;
|
||||
|
||||
SoftI2cMaster i2c(SCL_PIN, SDA_PIN);
|
||||
//FastI2cMaster<SCL_PIN, SDA_PIN> i2c;
|
||||
//------------------------------------------------------------------------------
|
||||
void setup() {
|
||||
|
||||
Serial.begin(9600);
|
||||
while (!Serial);
|
||||
|
||||
if (!digitalRead(SDA_PIN) && !digitalRead(SCL_PIN)) {
|
||||
Serial.println("External pull-up resistors appear to be missing.");
|
||||
Serial.println("Many false responses may be detected.");
|
||||
Serial.println("Type any character to continue.");
|
||||
|
||||
while (!Serial.available());
|
||||
Serial.println();
|
||||
|
||||
}
|
||||
uint8_t add = 0;
|
||||
bool found = false;
|
||||
do {
|
||||
bool wr = i2c.transfer(add | I2C_WRITE, 0, 0);
|
||||
bool rd = i2c.transfer(add | I2C_READ, 0, 0, I2C_CONTINUE);
|
||||
if (rd) {
|
||||
uint8_t dummy;
|
||||
// Must read byte, send NACK, and issue STOP.
|
||||
i2c.transferContinue(&dummy, 1);
|
||||
}
|
||||
if (rd || wr) {
|
||||
found = true;
|
||||
Serial.print("Device at address: 0X");
|
||||
Serial.print(add, HEX);
|
||||
Serial.print(" responds to ");
|
||||
if (rd) Serial.print("Read");
|
||||
if (rd && wr) Serial.print(" and ");
|
||||
if (wr) Serial.print("Write");
|
||||
Serial.println('.');
|
||||
}
|
||||
add += 2;
|
||||
}
|
||||
while (add);
|
||||
|
||||
if (!found) {
|
||||
Serial.println("No devices found.");
|
||||
}
|
||||
Serial.println("Done");
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop() {
|
||||
// Not used.
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,324 @@
|
||||
// Utility sketch to explore DS1307 and demonstrate software I2C Master.
|
||||
//
|
||||
|
||||
#include <DigitalIO.h>
|
||||
|
||||
// Set pin numbers for your configuration.
|
||||
const uint8_t SDA_PIN = A4;
|
||||
const uint8_t SCL_PIN = A5;
|
||||
|
||||
//SoftI2cMaster rtc(SCL_PIN, SDA_PIN);
|
||||
FastI2cMaster<SCL_PIN, SDA_PIN> rtc;
|
||||
|
||||
// i2c 8-bit address for DS1307. low bit is read/write
|
||||
#define DS1307ADDR 0XD0
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
* Read 'count' bytes from the DS1307 starting at 'address'.
|
||||
*/
|
||||
uint8_t readDS1307(uint8_t address, uint8_t *buf, uint8_t count) {
|
||||
|
||||
// Send address of data.
|
||||
if (!rtc.transfer(DS1307ADDR | I2C_WRITE, &address, 1)) return false;
|
||||
|
||||
// Read data.
|
||||
return rtc.transfer(DS1307ADDR | I2C_READ, buf, count);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/*
|
||||
* write 'count' bytes to DS1307 starting at 'address'.
|
||||
*/
|
||||
uint8_t writeDS1307(uint8_t address, uint8_t *buf, uint8_t count) {
|
||||
|
||||
// Write address and continue transfer for write of data.
|
||||
if (!rtc.transfer(DS1307ADDR | I2C_WRITE, &address, 1, I2C_CONTINUE)) {
|
||||
return false;
|
||||
}
|
||||
// Write data.
|
||||
return rtc.transferContinue(buf, count);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setup(void) {
|
||||
Serial.begin(9600);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
/** Store and print a string in flash memory.*/
|
||||
#define PgmPrint(x) Serial.print(F(x))
|
||||
/** Store and print a string in flash memory followed by a CR/LF.*/
|
||||
#define PgmPrintln(x) Serial.println(F(x))
|
||||
//-------------------------------------------------------------------------------
|
||||
// Day of week U.S. convention.
|
||||
char *Ddd[] = {"Bad", "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
|
||||
//------------------------------------------------------------------------------
|
||||
void hexPrint(uint8_t v) {
|
||||
Serial.print(v >> 4, HEX);
|
||||
Serial.print(v & 0XF, HEX);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void hexPrintln(uint8_t v) {
|
||||
hexPrint(v);
|
||||
Serial.println();
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// read hex input
|
||||
uint8_t hexRead(uint16_t* v) {
|
||||
bool valid = false;
|
||||
uint16_t n = 0;
|
||||
while (!Serial.available());
|
||||
while (Serial.available()) {
|
||||
uint8_t c = Serial.read();
|
||||
// Exit if end-of-line.
|
||||
if (c == '\n' || c == '\r') {
|
||||
delay(10);
|
||||
// If CR/LF.
|
||||
Serial.read();
|
||||
break;
|
||||
}
|
||||
n <<= 4;
|
||||
if ('a' <= c && c <= 'f') {
|
||||
n += c - ('a' - 10);
|
||||
}
|
||||
else if ('A' <= c && c <= 'F') {
|
||||
n += c - ('A' - 10);
|
||||
}
|
||||
else if ('0' <= c && c <= '9') {
|
||||
n += c - '0';
|
||||
}
|
||||
else {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
delay(10);
|
||||
valid = true;
|
||||
}
|
||||
if (!valid) {
|
||||
PgmPrintln("Invalid entry");
|
||||
return false;
|
||||
}
|
||||
*v = n;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
uint8_t bcdRead(uint8_t min, uint8_t max, uint8_t* n) {
|
||||
uint16_t v;
|
||||
if (!hexRead(&v)) return false;
|
||||
uint8_t d = 10 * (v >> 4) + (v & 0XF);
|
||||
if ((v >> 4) > 9 || (v & 0XF) > 9 || d < min || d > max) {
|
||||
PgmPrintln("Invalid");
|
||||
return false;
|
||||
}
|
||||
*n = v;
|
||||
return true;
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void displayTime(void) {
|
||||
uint8_t r[8];
|
||||
if (!readDS1307(0, r, 8)) {
|
||||
PgmPrintln("Read Failed for display time");
|
||||
return;
|
||||
}
|
||||
PgmPrint("The current time is 20");
|
||||
// year
|
||||
hexPrint(r[6]);
|
||||
Serial.write('-');
|
||||
|
||||
// month
|
||||
hexPrint(r[5]);
|
||||
Serial.write('-');
|
||||
|
||||
// day
|
||||
hexPrint(r[4]);
|
||||
Serial.write(' ');
|
||||
|
||||
Serial.print(Ddd[r[3] < 8 ? r[3] : 0]);
|
||||
Serial.write(' ');
|
||||
|
||||
// hour
|
||||
hexPrint(r[2]);
|
||||
Serial.write(':');
|
||||
|
||||
// minute
|
||||
hexPrint(r[1]);
|
||||
Serial.write(':');
|
||||
|
||||
// second
|
||||
hexPrintln(r[0]);
|
||||
|
||||
// Control register.
|
||||
PgmPrint("Control Register: ");
|
||||
hexPrintln(r[7]);
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// dump registers and 56 bytes of RAM
|
||||
void dumpAll(void) {
|
||||
uint8_t buf[8];
|
||||
for (uint8_t a = 0; a < 64; a += 8) {
|
||||
hexPrint(a);
|
||||
Serial.write(' ');
|
||||
if (!readDS1307(a, buf, 8)) {
|
||||
PgmPrint("read failed for dumpAll");
|
||||
return;
|
||||
}
|
||||
for (uint8_t i = 0; i < 8; i++) {
|
||||
Serial.write(' ');
|
||||
hexPrint(buf[i]);
|
||||
}
|
||||
Serial.println();
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void fillNvRam(void) {
|
||||
uint8_t buf[8];
|
||||
PgmPrint("Enter HEX value for all NV RAM locations (00-FF): ");
|
||||
uint16_t v;
|
||||
if (!hexRead(&v)) return;
|
||||
hexPrint(v);
|
||||
for (uint8_t a = 8; a < 64; a ++) {
|
||||
if (!writeDS1307(a, (uint8_t *)&v, 1)) {
|
||||
PgmPrintln("write failed for fillNvRam");
|
||||
}
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
// set control register
|
||||
/*
|
||||
The DS1307 control register is used to control the operation of the SQW/OUT pin.
|
||||
+-----------------------------------------------+
|
||||
|BIT 7|BIT 6|BIT 5|BIT 4|BIT 3|BIT 2|BIT 1|BIT 0|
|
||||
+-----------------------------------------------+
|
||||
|OUT | 0 | 0 |SQWE | 0 | 0 | RS1 | RS0 |
|
||||
+-----------------------------------------------+
|
||||
|
||||
OUT (Output control): This bit controls the output level of the SQW/OUT pin
|
||||
when the square wave output is disabled. If SQWE = 0, the logic level on the
|
||||
SQW/OUT pin is 1 if OUT = 1 and is 0 if OUT = 0.
|
||||
|
||||
SQWE (Square Wave Enable): This bit, when set to a logic 1, will enable the
|
||||
oscillator output. The frequency of the square wave output depends upon the
|
||||
value of the RS0 and RS1 bits. With the square wave output set to 1Hz, the
|
||||
clock registers update on the falling edge of the square wave.
|
||||
|
||||
Square wave Output Frequency for SQWE = 1.
|
||||
RS1 RS0 FREQUENCY
|
||||
0 0 1Hz
|
||||
0 1 4.096kHz
|
||||
1 0 8.192kHz
|
||||
1 1 32.768kHz
|
||||
*/
|
||||
void setControl(void) {
|
||||
PgmPrintln("SQW/OUT pin: ");
|
||||
PgmPrintln("(00) Low");
|
||||
PgmPrintln("(10) 1Hz");
|
||||
PgmPrintln("(11) 4.096kHz");
|
||||
PgmPrintln("(12) 8.192kHz");
|
||||
PgmPrintln("(13) 32.768kHz");
|
||||
PgmPrintln("(80) High");
|
||||
PgmPrint("Enter control: ");
|
||||
uint16_t r;
|
||||
if (!hexRead(&r)) return;
|
||||
hexPrintln(r);
|
||||
if (!writeDS1307(7, (uint8_t *)&r, 1)) {
|
||||
PgmPrint("Write Failed for setControl");
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setDate(void) {
|
||||
uint8_t r[4];
|
||||
PgmPrint("Enter year (00-99): ");
|
||||
if (!bcdRead(0, 99, &r[3])) return;
|
||||
hexPrintln(r[3]);
|
||||
PgmPrint("Enter month (01-12): ");
|
||||
if (!bcdRead(1, 12, &r[2])) return;
|
||||
hexPrintln(r[2]);
|
||||
PgmPrint("Enter day (01-31): ");
|
||||
if (!bcdRead(1, 31, &r[1])) return;
|
||||
hexPrintln(r[1]);
|
||||
PgmPrint("Enter day of week (01-07, Sun-Sat): ");
|
||||
if (!bcdRead(1, 7, &r[0])) return;
|
||||
hexPrintln(r[0]);
|
||||
|
||||
if (!writeDS1307(3, r, 4)) {
|
||||
PgmPrintln("Write failed for setDate");
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setNvRam() {
|
||||
uint8_t u;
|
||||
uint16_t a, v;
|
||||
while (true) {
|
||||
PgmPrint("Enter zero to quit or Hex address (8-3F):");
|
||||
if (!hexRead(&a) || a == 0) return;
|
||||
if (a < 8 || a > 0X3F) {
|
||||
PgmPrintln("Invalid address");
|
||||
return;
|
||||
}
|
||||
hexPrintln(a);
|
||||
if (!readDS1307(a, &u, 1)) {
|
||||
PgmPrintln("Read failed");
|
||||
return;
|
||||
}
|
||||
PgmPrint("Current value: ");
|
||||
hexPrintln(u);
|
||||
PgmPrint("Enter new HEX value (00-FF): ");
|
||||
if (!hexRead(&v)) return;
|
||||
hexPrintln(v);
|
||||
if (!writeDS1307(a, (uint8_t *)&v, 1)) {
|
||||
PgmPrint("Write Failed");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void setTime(void) {
|
||||
uint8_t r[3];
|
||||
PgmPrint("Enter hours (00-23): ");
|
||||
if (!bcdRead(0, 23, &r[2])) return;
|
||||
hexPrintln(r[2]);
|
||||
PgmPrint("Enter minutes (00-59): ");
|
||||
if (!bcdRead(0, 59, &r[1])) return;
|
||||
hexPrintln(r[1]);
|
||||
PgmPrint("Enter seconds (00-59): ");
|
||||
if (!bcdRead(0, 59, &r[0])) return;
|
||||
hexPrintln(r[0]);
|
||||
|
||||
if (!writeDS1307(0, r, 3)) {
|
||||
PgmPrintln("write failed in setTime");
|
||||
return;
|
||||
}
|
||||
}
|
||||
//------------------------------------------------------------------------------
|
||||
void loop(void) {
|
||||
Serial.println();
|
||||
displayTime();
|
||||
while (Serial.read() >= 0) {}
|
||||
PgmPrintln("\nOptions are:");
|
||||
PgmPrintln("(0) Display date and time");
|
||||
PgmPrintln("(1) Set time");
|
||||
PgmPrintln("(2) Set date");
|
||||
PgmPrintln("(3) Set Control");
|
||||
PgmPrintln("(4) Dump all");
|
||||
PgmPrintln("(5) Fill NV RAM");
|
||||
PgmPrintln("(6) Set NV RAM value");
|
||||
PgmPrint("Enter option: ");
|
||||
|
||||
uint16_t n;
|
||||
if (!hexRead(&n)) return;
|
||||
Serial.println(n, DEC);
|
||||
if (n == 0) return;
|
||||
Serial.println();
|
||||
if (n == 1) {
|
||||
setTime();
|
||||
} else if (n == 2) {
|
||||
setDate();
|
||||
} else if (n == 3) {
|
||||
setControl();
|
||||
} else if (n == 4) {
|
||||
dumpAll();
|
||||
} else if (n == 5) {
|
||||
fillNvRam();
|
||||
} else if (n == 6) {
|
||||
setNvRam();
|
||||
} else {
|
||||
PgmPrintln("Invalid option");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
// Scope test for write timing with Arduino digitaWrite().
|
||||
const uint8_t PIN13 = 13;
|
||||
|
||||
void setup() {
|
||||
// Set mode to OUTPUT.
|
||||
pinMode(PIN13, OUTPUT);
|
||||
}
|
||||
void loop() {
|
||||
digitalWrite(PIN13, HIGH);
|
||||
digitalWrite(PIN13, LOW);
|
||||
digitalWrite(PIN13, HIGH);
|
||||
digitalWrite(PIN13, LOW);
|
||||
delay(1);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Scope test for write timing of DigitalPin functions.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
// Class with compile time pin number.
|
||||
DigitalPin<13> pin13;
|
||||
|
||||
void setup() {
|
||||
// set mode to OUTPUT
|
||||
pin13.mode(OUTPUT);
|
||||
}
|
||||
void loop() {
|
||||
pin13.high();
|
||||
pin13.low();
|
||||
pin13.write(1);
|
||||
pin13.write(0);
|
||||
pin13.toggle();
|
||||
pin13.toggle();
|
||||
delay(1);
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
// Test fastDigital function timing with a scope.
|
||||
#include <DigitalIO.h>
|
||||
const uint8_t PIN = 13;
|
||||
void setup() {
|
||||
fastPinMode(PIN, OUTPUT);
|
||||
}
|
||||
void loop() {
|
||||
fastDigitalWrite(PIN, HIGH);
|
||||
fastDigitalWrite(PIN, LOW);
|
||||
fastDigitalToggle(PIN);
|
||||
fastDigitalToggle(PIN);
|
||||
delay(1);
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
// Scope test for PinIO class write timing.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
// Class with runtime pin numbers.
|
||||
PinIO pin(13);
|
||||
|
||||
void setup() {
|
||||
// Set mode to OUTPUT.
|
||||
pin.mode(OUTPUT);
|
||||
}
|
||||
void loop() {
|
||||
pin.high();
|
||||
pin.low();
|
||||
pin.write(1);
|
||||
pin.write(0);
|
||||
pin.toggle();
|
||||
pin.toggle();
|
||||
delay(1);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
// Scope test for development - assumes 328 processor.
|
||||
#include <DigitalIO.h>
|
||||
|
||||
const uint8_t SOFT_SPI_MISO_PIN = 7;
|
||||
const uint8_t SOFT_SPI_MOSI_PIN = 8;
|
||||
const uint8_t SOFT_SPI_SCK_PIN = 9;
|
||||
const uint8_t SPI_MODE = 0;
|
||||
|
||||
SoftSPI<SOFT_SPI_MISO_PIN, SOFT_SPI_MOSI_PIN, SOFT_SPI_SCK_PIN, SPI_MODE> spi;
|
||||
|
||||
int test;
|
||||
void setup() {
|
||||
Serial.begin(9600);
|
||||
spi.begin();
|
||||
while(1) {
|
||||
Serial.println("Enter:");
|
||||
Serial.println("R - Receive");
|
||||
Serial.println("S - Send");
|
||||
Serial.println("T - Transfer");
|
||||
while ((test = Serial.read()) <= 0) {}
|
||||
test = toupper(test);
|
||||
if (strchr("RST", test)) break;
|
||||
Serial.println("Invalid entry");
|
||||
};
|
||||
Serial.print("Starting test ");
|
||||
Serial.println((char)test);
|
||||
}
|
||||
void loop() {
|
||||
if (test == 'S') spi.send(0X55);
|
||||
if (test == 'R') {
|
||||
Serial.println(spi.receive(), HEX);
|
||||
}
|
||||
if (test == 'T') {
|
||||
Serial.println(spi.transfer(0XAA), HEX);
|
||||
}
|
||||
delay(10);
|
||||
}
|
||||
Reference in New Issue
Block a user