Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Microwire sketch for Digispark
#include <DigiCDC.h>
#include <MicrowireEEPROM.h>
/*
* +-----+---------+
* | Pin | Func |
* +-----+---------+
* | P0 | DO/DI |
* +-----+---------+
* | P1 | CLK/LED |
* +-----+---------+
* | P2 | CS |
* +-----+---------+
* | P3 | USB |
* +-----+---------+
* | P4 | USB |
* +-----+---------+
* | P5 | NRST |
* +-----+---------+
*/
int CS=2; int CLK=1; int DI=0; int DO=0;
/*
* 2 bytes at a time, 8-bit address (93C56!) and 5 kHz
*/
int PGS=16; int ADW=8; int SPD=200;
MicrowireEEPROM *ME;
void setup() {
pinMode(1, OUTPUT);
pinMode(5, OUTPUT);
digitalWrite(1, HIGH);
digitalWrite(5, HIGH);
delay(1000);
digitalWrite(1, LOW);
digitalWrite(5, LOW);
ME = new MicrowireEEPROM(CS, CLK, DI, DO, PGS, ADW, SPD);
/* init virtual serial console on USB */
SerialUSB.begin();
SerialUSB.delay(500);
SerialUSB.print(F("Hello, World!\r\n"));
}
void loop() {
static int once = false;
/* send any key to continue */
if (!once && SerialUSB.available() > 0) {
once = true;
int addr=0x31;
char hexword[5];
// 2048b = 256B = 128 words
for (addr = 0; addr < 128; addr++) {
#if 0
ME->writeEnable();
ME->write(addr, 0x1337);
SerialUSB.delay(10);
#endif // 0
unsigned int r = ME->read(addr);
r &= 0xffff;
SerialUSB.print(r, HEX);
if (addr % 8 == 7) {
SerialUSB.println();
}
}
} else {
SerialUSB.delay(10);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment