This is a very crude logic analyzer. You need to be able to compile from the command line to get this to run. Output will be to the serial port. You will need to add 2040 missing lines as indicated below.
The idea is to capture everything into a .csv file and then display it using some spreadsheet --> no need for any specialized display software.
The output is formatted to allow quick analysis even in the terminal.
It will always stop in an endless loop --> push reset to restart.
//
// no rights, no warranty, no claims, just a quick hack
// Udo Klein August 2009
//
#include <WProgram.h>
int main() {
const uint8_t mask = 0xff;
const int max = 1024;
const int show = 1024;
uint8_t log[max];
// configure all port D pins for input
for (int pin = 0; pin < 8; ++pin) {
pinMode(pin,INPUT);
digitalWrite(pin, HIGH);
}
// capture 1024 at 1 byte each 3 seconds
// trigger if any of the bits in mask changes
uint8_t tmp; // dummy for temporary register
__asm__ __volatile__ (
" cli" "\n\t"
// wait for trigger condition
" in __tmp_reg__, %[port_d]" "\n\t"
" and __tmp_reg__, %[mask]" "\n\t"
"1: in %[tmp], %[port_d]" "\n\t"
" and %[tmp], %[mask]" "\n\t"
" cp %[tmp], __tmp_reg__" "\n\t"
" breq 1b" "\n\t"
// log 1024 bytes
" in %[tmp], %[port_d]" "\n\t"
" st %a[log]+, %[tmp]" "\n\t"
" in %[tmp], %[port_d]" "\n\t"
" st %a[log]+, %[tmp]" "\n\t"
--- snip --- 2040 similar lines deleted --- snip ---
" in %[tmp], %[port_d]" "\n\t"
" st %a[log]+, %[tmp]" "\n\t"
" in %[tmp], %[port_d]" "\n\t"
" st %a[log]+, %[tmp]" "\n\t"
" sei" "\n\t"
: // no output
: [log] "e" (log), // constraint: pointer register
[port_d] "M" (0x09), // constraint: constant
[mask] "e" (mask), // constraint: simple upper register
[tmp] "a" (tmp) // constraint: simple upper register
: "memory"
);
Serial.begin(115200);
for (int line = 0; line < show; ++line) {
Serial.print(line);
for (int i = 7; i >= 0; --i) {
Serial.print(',');
Serial.print((log[line] >> i) & 1);
}
Serial.println("");
}
for (;;) {}
}