Driver Boards

Arduino Driver Board sketch

This sketch sends PDB protocol commands over the SPI data pin. The functionality was verified on a 16 MHz Arduino Uno.

#include <SPI.h>
#define pinMOSI 11
#define PDB_COMMAND_WRITE 1

 

void setup() {
SPI.begin();
SPI.setBitOrder(MSBFIRST);
SPI.setClockDivider(SPI_CLOCK_DIV2); // Need 8 MHz. So use DIV2 on a 16 MHz board.
}

 

void sendPDBCommand(byte addr, byte command, byte bankAddr, byte data)
{
byte cmdWord[5];
cmdWord[0] = addr;
cmdWord[1] = command;
cmdWord[2] = bankAddr;
cmdWord[3] = (data >> 4) & 0xF;
cmdWord[4] = data & 0xF;
// Turn off interrupts so the transfer doesn't get interrupted.
noInterrupts();
// Hardcode transfers to minimize IDLEs between transfers.
// Using a for-loop adds 5 extra IDLEs between transfers.
SPI.transfer(cmdWord[0]);
SPI.transfer(cmdWord[1]);
SPI.transfer(cmdWord[2]);
SPI.transfer(cmdWord[3]);
SPI.transfer(cmdWord[4]);
// Re-enable interrupts
interrupts();
}

 

byte lastData = 0;
void loop() {
byte data = ~lastData;
byte board = 0;
sendPDBCommand(board, PDB_COMMAND_WRITE, 0, data); // Write data to bank 0
sendPDBCommand(board, PDB_COMMAND_WRITE, 1, ~data); // Write inverted data to bank 1
lastData = data;
delay(500);
}