Go Down

Topic: BI-Directional Clock (3 Wire Serial) (Read 2697 times) previous topic - next topic

purduefiji

Hi all,

I am currently working with a 3 wire serial communication interface (SCLOCK, DIN, DOUT). I am having issues setting up the bidirectional SCLOCK. I am not sure how to achieve this in Arduino.

Any suggestions or literature on this topic would be very much appreciated.

Thanks in advance...

Nick Gammon

More information? Are you looking at async serial, SPI, I2C, or some other protocol?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

purduefiji

Nick,

Thanks for your prompt response.

It looks to me as if it doesn't adhere to any well known serial interface (that I can think of)... I have been successful with reading the configuration register (verified on oscilloscope) through bit banging on the pin ports but that does not require the use of a bidirectional clock.

This is the module I am working with...
http://www.ti.com/lit/ug/scbu030/scbu030.pdf

Any insight would be very appreciated.

purduefiji

Can I switch the PinMode outside of the setup?

Could this be done by adjusting the DDR of the PORT in the middle of a function?

Nick Gammon

You can change pinMode as many times as you want, where you want.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

purduefiji

Would you suggest using the PinMode function over manipulating the I/O Register's & Ports?

Nick Gammon

I almost always use pinMode/digitalRead/digitalWrite unless I think that last microsecond will make a difference.

You get readability, portability (to other chips), faster programming etc.

The only time I fool with the ports for writing/reading is when time is absolutely critical - which isn't often.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

purduefiji

Hi all,

Still having issues here.

Progress
I have been able to write data to the configuration register and read it back.
The data was clocked out of the transceiver using a clock coming from the micro.

Need Help
Where I run into issues is when SCLOCK needs to be bi-directional. Meaning SCLOCK needs to be used by both the controller and the transceiver.

After sending my request using the controller the transceiver needs to generate the SCLOCK so I can read back the tag data.

If anyone has a similar project or literature I can refer to regarding a possible solution I would greatly appreciate it.

Thanks,
Brian


retrolefty

Quote
Need Help
Where I run into issues is when SCLOCK needs to be bi-directional. Meaning SCLOCK needs to be used by both the controller and the transceiver.


I would suggest, if you are not already doing so, that you use an external pull-up resistor (say 10k ohms) to +5vdc on the SCLOCK line if you require bidirectional control, otherwise there is bound to be glitches as you switch from input to output modes on the arduino digital pin, and however your remote devices switches direction control

Lefty

Nick Gammon


After sending my request using the controller the transceiver needs to generate the SCLOCK so I can read back the tag data.


You are bumping but not posting code. How are we supposed to help you with some hypothetical code?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

purduefiji

Nick,
Attached is the code and a screen shot of the register read back.

I am writing a value 0x27 or 0010-0111 and then reading it back and verifying this value on the oscilloscope. I tried reading and storing this value using the controller but haven't had any luck there.

Any suggestions?

Code: [Select]
/*****************************************************
Purpose: Read/Write to RI-R6C-001A Register
*****************************************************/


int SCLK = 7; // SCLOCK
int DIN = 4; //Data from main controller to transceiver ic
int DOUT = 8; //Data from transceiver ic to main controller
/*****************************************************/
void setup()
{
 
  Serial.begin(9600);
  //Serial1.begin(9600);
  Serial.println("Setting up Serial I/O");
 
  pinMode(SCLK, OUTPUT);      // sets SCLK digital pin as output
  pinMode(DIN, OUTPUT);      //sets DIN digital pin as output
  pinMode(DOUT, INPUT);



/*****************************************************
Write configuration register command 0x7D
*****************************************************/
Serial.println("Write 0x7D");
  digitalWrite(SCLK, HIGH);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);

  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);

  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
 
/*****************************************************
Write configuration register content 0x27
*****************************************************/
Serial.println("Write content 0x27");
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(DIN, LOW); 
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
 
 

/*****************************************************
Read configuration register command 0x71
*****************************************************/
Serial.println("Read Command 0x71");
  digitalWrite(SCLK, HIGH);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);

  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
 
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
 
/*****************************************************
Read back configuration register using controller clock = 0x27
*****************************************************/ 
Serial.println("Read Register");
  digitalWrite(SCLK, HIGH);
delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);

  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);

  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
}

void loop()
{
}

Nick Gammon

I can't see anywhere in the code below where you are reading anything:

Code: [Select]

  /*****************************************************
   * Read configuration register command 0x71
   *****************************************************/
  Serial.println("Read Command 0x71");
  digitalWrite(SCLK, HIGH);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);

  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);

  digitalWrite(DIN, LOW);
  delayMicroseconds(1);


There's a lot of digitalWrite, no digitalRead.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

purduefiji

Nick,

Attached is code with digitalread as well as my output from the serial monitor.

I should be reading 0010-0111 but am instead reading 0001-0011.


Code: [Select]
/*****************************************************
Purpose: Read/Write to RI-R6C-001A Register
*****************************************************/


int SCLK = 7; // SCLOCK
int DIN = 4; //Data from main controller to transceiver ic
int DOUT = 3; //Data from transceiver ic to main controller
int val;
/*****************************************************/
void setup()
{
 
  Serial.begin(9600);
  //Serial1.begin(9600);
  Serial.println("Setting up Serial I/O");
 
  pinMode(SCLK, OUTPUT);      // sets SCLK digital pin as output
  pinMode(DIN, OUTPUT);      //sets DIN digital pin as output
  pinMode(DOUT, INPUT);      //sets the digital pin as input

/*****************************************************
Start Bit
*****************************************************/
  Serial.println("Start Bit");
  digitalWrite(SCLK, HIGH);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);

/*****************************************************
Write configuration register command 0x7D
Data - > MSB; Latched on Rising Clock Edge
*****************************************************/   
  Serial.println("Write 0x7D");
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);

  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
 
/*****************************************************
Write configuration register content 0x27
This is the value I am storing in the register
*****************************************************/
  Serial.println("Write content 0x27");
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(DIN, LOW); 
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
 
/*****************************************************
Stop Bit
*****************************************************/ 
  Serial.println("Stop bit");
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
 

/*****************************************************
Start Bit
*****************************************************/
  Serial.println("Start Bit");
  digitalWrite(SCLK, HIGH);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);

/*****************************************************
Read configuration register command 0x71
*****************************************************/
  Serial.println("Read Command 0x71");
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
 
/*****************************************************
Read back configuration register using controller clock = 0x27
*****************************************************/ 
Serial.println("Read Register");
  digitalWrite(SCLK, HIGH);
  delayMicroseconds(5);
Serial.println(digitalRead(DOUT)); //1
delayMicroseconds(1);
  //var = digitalRead(DOUT);  //read the pin and save it into var
  //Serial.println(var);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(5);
Serial.println(digitalRead(DOUT)); //2
delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(5);
Serial.println(digitalRead(DOUT)); //3
delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
Serial.println(digitalRead(DOUT)); //4
delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
Serial.println(digitalRead(DOUT)); //5
delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
Serial.println(digitalRead(DOUT)); //6
delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
Serial.println(digitalRead(DOUT)); //7
delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
Serial.println(digitalRead(DOUT)); //8
delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);

/*****************************************************
Stop Bit
*****************************************************/ 
  Serial.println("Stop bit");
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH); 
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);

}

void loop()
{
}

Nick Gammon


After sending my request using the controller the transceiver needs to generate the SCLOCK so I can read back the tag data.


Your code is not consistent with that remark.

Code: [Select]

  Serial.println("Read Register");
  digitalWrite(SCLK, HIGH);
  delayMicroseconds(5);
  Serial.println(digitalRead(DOUT)); //1
  delayMicroseconds(1);


You are writing SCLK not reading it.

I strongly suggest you read up on doing loops. This is unnecessary to write 8 bits:

Code: [Select]

  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH); 
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //0
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, HIGH);
  delayMicroseconds(1);
  digitalWrite(SCLK, HIGH);  //1
  delayMicroseconds(1);
  digitalWrite(SCLK, LOW);
  delayMicroseconds(1);
  digitalWrite(DIN, LOW);
  delayMicroseconds(1);


That is just clutter. It hides what is really going on. Make a function that outputs a byte by looping through each bit.
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

Go Up