regarding SPi communication

I have 2 doubts in this:

  1. why softwareserial.in library is used
  2. value += digitalRead(DBIT) << i; // what does this line mean ?

This code is for SPI communication for reading values of thermocouple using max6675

#define CLK 9
#define DBIT 10 // so
#define CS 13

#include <SoftwareSerial.h>

int v = 0;
float Ctemp, Ftemp;

void setup() {
Serial.begin(9600);
pinMode(CLK, OUTPUT);
pinMode(DBIT, INPUT);
pinMode(CS, OUTPUT);
digitalWrite(CS, HIGH);
digitalWrite(CLK, LOW);
}

void loop() {
v = spiRead();
if (v == -1) {
Serial.print(“No sensor \n”);
}
else {
Ctemp = v * 0.25;
Ftemp = (Ctemp * 9 / 5) + 32;
Serial.println(Ftemp);
// Serial.print("\n");
}
delay(100);
}
//to read the voltage from thermocouple
int spiRead() {
int value = 0;
digitalWrite(CS,LOW);
delay(2);
digitalWrite(CS,HIGH);
delay(220);

/* Read the chip and return the raw temperature value /
/
Bring CS pin low to allow us to read the data from
the conversion process /
//to send for serial communication.
digitalWrite(CS,LOW);
/
Cycle the clock for dummy bit 15 */
digitalWrite(CLK,HIGH);
delay(1);
digitalWrite(CLK,LOW);

/*
Read bits 14-3 from MAX6675 for the Temp. Loop for each bit reading
the value and storing the final value in ‘temp’
*/

for (int i=14; i>=0; i–)
{
digitalWrite(CLK,HIGH);
value += digitalRead(DBIT) << i;
digitalWrite(CLK,LOW);
}
// check bit D2 if HIGH no sensor
if ((value & 0x04) == 0x04) return -1;

// shift right three places
return value >> 3;
}

  1. why softwareserial.in library is used

Nobody knows, ask the programmer. SoftwareSerial is a crippled piece of software anyway and should not be used in most cases other than some trivial demos.

  1. value += digitalRead(DBIT) << i; // what does this line mean ?

It reads a pin value and adds that to ‘value’ at the "i"th bit position. The for loop it is in emulates an SPI interface in software. If the original programmer used bitwise OR instead of the addition the resulting code would be a bit faster.