CatBusTest4

From ArduinoInfo
Jump to navigation Jump to search
CatBus Test 4:

Breadboarded circuit and wrote Test Sketch (below)..

CatBusTest4-1000.jpg


Test Sketch below (Cut&Paste):
/* CatBus Test 4
   Sends alternatine data, receives both data bytes
   Send 0x55, 0xAA which is displayed on 595 inverted
   Receive bits tied high or low on 165, seen inverted
   Init: SPI_CLOCK_DIV128  (125 Khz, 2uS data setup time
   Init: SPI_MODE2  See:
   http://en.wikipedia.org/wiki/Serial_Peripheral_Interface_Bus
   terry@yourduino.com */

/*-----( Import needed libraries )-----*/
#include <SPI.h>
/*-----( Declare Constants and Pin Numbers )-----*/
#define  STROBE 9  // NOT controlled by SPI Library
/*-----( Declare objects )-----*/
//None
/*-----( Declare Variables )-----*/
byte dataByte1 = 0x55;
byte dataByte2 = 0xAA;
byte dataIn1 ;
byte dataIn2 ;


void setup()   /****** SETUP: RUNS ONCE ******/
{
  Serial.begin(9600);
  SPI.setClockDivider(SPI_CLOCK_DIV128);
  SPI.setDataMode(SPI_MODE2);
  SPI.begin ();
  Serial.println("SPI CatBus Test");
  pinMode(STROBE, OUTPUT);
  digitalWrite (STROBE, LOW);
}//--(end setup )---


void loop()   /****** LOOP: RUNS CONSTANTLY ******/
{
  Serial.println("S_T_A_R_T");
  dataIn1 = SPI.transfer (0xff); //Read previous transfer Digital Input
  dataIn2 = SPI.transfer (dataByte1); //From last data to 595-Trash 
  digitalWrite (STROBE, HIGH);
  digitalWrite (STROBE, LOW);  // About 3 uS wide this way

  Serial.print("DataIn1 = ");
  Serial.println(dataIn1,BIN);
  Serial.print("DataIn2 = ");
  Serial.println(dataIn2,HEX);
  delay(4000);

  Serial.println("S_E_C_O_N_D");
  dataIn1 = SPI.transfer (0xff);//Read previous transfer Digital Input
  dataIn2 = SPI.transfer (dataByte2); //From last data to 595-Trash 
  digitalWrite (STROBE, HIGH);  //Strobe 595 Outputs, Sample 165 Inputs 
  digitalWrite (STROBE, LOW);  // About 3 uS wide this way 

  Serial.print("DataIn1 = ");
  Serial.println(dataIn1,BIN);
  Serial.print("DataIn2 = ");
  Serial.println(dataIn2,HEX);
  delay(4000);

}//--(end main loop )---

/*-----( Declare User-written Functions )-----*/
//None

//*********( THE END )***********




Output looks like this:

SPI CatBus Test
S_T_A_R_T
DataIn1 = 1110 (Trash)
DataIn2 = BF
S_E_C_O_N_D
DataIn1 = 1100011 (As Jumpers set)
DataIn2 = 55
S_T_A_R_T
DataIn1 = 11000011
DataIn2 = AA
S_E_C_O_N_D
DataIn1 = 11000011
DataIn2 = 55
S_T_A_R_T
DataIn1 = 11000011
DataIn2 = AA
S_E_C_O_N_D
DataIn1 = 11000011
DataIn2 = 55




zz