This sample demonstrates how to control the SPI Octal Relay Output Board.
#include <sys/thread.h> #include <sys/timer.h> #include <sys/print.h> #include <dev/spidigio.h> THREAD(NutMain, arg) { u_long oval = 1; u_long ival; u_char ni; u_char no; u_long baud = 115200; /* * Initialize debug UART device and * print banner. */ outp(BV(RXEN) | BV(TXEN), UCR); NutDeviceIOCtl(0, UART_SETSPEED, &baud); NutPrintString_P(0, PSTR("\r\nDigital Relay Output Demo\r\n")); /* * The outer endless loop is used to keep looking * for outputs. */ for(;;) { /* * Initialize the SPI to the digital I/O boards. * The call returns the number of inputs and * outputs detected. */ SpiDigitalInit(&ni, &no); NutPrintFormat(0, "Found %u digital inputs and %u digital outputs\r\n", ni, no); NutSleep(500); if(no) { /* * The inner endless loop switches * a single relays. */ for(;;) { /* * Set outputs. */ SpiDigitalSet(no, oval); /* * Get inputs and print the result. */ ival = SpiDigitalGet(ni + no); NutPrintFormat(0, "Out: %08lX - In: %08lX\r\n", oval, ival); /* * Shift around the walking bit value. */ if((oval <<= 1) == BV(no)) oval = 1; NutSleep(500); } } } }