CT77 temp sensor with SPI

I have problem with read data from a CT77 temp sensor.

#include "SPI.h"
 int CSPin = 4;      // 
 byte byte1;
 byte byte2;
 int32_t temp;

void setup() {
   pinMode(CSPin, OUTPUT); // 
   digitalWrite(CSPin, HIGH);

   SPI.begin(); // wake up the SPI bus.
   SPI.setBitOrder(MSBFIRST);
   SPI.setClockDivider(SPI_CLOCK_DIV16);
   SPI.setDataMode(SPI_MODE0);
   Serial.begin(9600);
}

void loop() {

    digitalWrite(CSPin, LOW);
    delay(10);
    byte1 = SPI.transfer(0);
    byte2 = SPI.transfer(0);
    delay(1);
    digitalWrite(CSPin, HIGH);
    temp = byte1<<8;
    temp |= byte2;
    temp = temp >> 3;
  
    float temp2 = temp * 0.0625;
  
    Serial.println(temp, BIN);
    Serial.println(temp2);
    Serial.println("****");
    delay(2000);
}

And the output

10000100
8.25
****
10011001
9.56
****
11000010
12.13
****
11001000
12.50
****
110001111
24.94
****
11010000
13.00
****
110000001
24.06
****
11011001
13.56
****

What am I doing wrong

CT77 ?? What is that? datasheet?

The TC77 is a digital temperature sensor with SPI bus

temp can be INT ( signed 16 bits)

Convert to float BEFORE the division! (by 16.0)

as this SPI-interface use a single pin for I/O, try shiftIn

Here is my modifyed code

 int CSPin = 4;      // 
 int MISOPin = 14;
 int SCKPin = 15;
 byte byte1;
 byte byte2;
 int temp;

void setup() {
  pinMode(CSPin, OUTPUT); // 
  digitalWrite(CSPin, HIGH);

  pinMode(SCKPin, OUTPUT);
  pinMode(MISOPin, INPUT);
  Serial.begin(9600);
}

void loop() {

    digitalWrite(CSPin, LOW);
    delay(1);
    byte1 = shiftIn(MISOPin, SCKPin, MSBFIRST);
    byte2 = shiftIn(MISOPin, SCKPin, MSBFIRST);
    delay(1);
    digitalWrite(CSPin, HIGH);
    if(byte2 & 4){
    temp = byte1<<8;
    temp |= byte2;
    temp = temp >> 2;
    Serial.println(temp, BIN);
    temp = temp >> 1;
    float temp2 = (float)temp * 0.0625;
  
    Serial.println(temp2);
    Serial.println("****");
    
    delay(2000);
}

And the output

10010010101
36.63
****
10001100001
35.00
****
10000110000
33.50
****
10000000001
32.00
****
10010000000
36.00
****
0
0.00
****
10010000000
36.00
****
0
0.00
****
10010000010
36.06
****
10001011
4.31
****
10010000000
36.00
****
1001
0.25

As described in the data sheet I can use Bit2 to test the conversion

4.2
Temperature Register (TEMP)
The Temperature register is read only and holds the
temperature conversion data. Bits 0 and 1 are unde-
fined and will be tri-state outputs during a read
sequence. Bit 2 is set to a logic ‘1’ after completion of
the first temperature conversion following a power-up
or reset event. Bit 2 is set to a logic ‘0’ during the time
needed to complete the first temperature conversion.
Therefore, the status of bit 2 can be monitored to indi-
cate that the TC77 has completed the first temperature
conversion.

If I do that

 if(byte2 & 4){
    temp = byte1<<8;
    temp |= byte2;
    temp = temp >> 2;
  Serial.println(temp, BIN);
  temp = temp >> 1;
    float temp2 = (float)temp * 0.0625;
  
    
    Serial.println(temp2);
    Serial.println("****");
    
//    temp = byte2 & 0x04;
//    Serial.println(temp, BIN);
//    Serial.println("****");
    delay(2000);
    }

And the output

10000011
4.06
****
10000001
4.00
****
10000001011
32.31
****
10001
0.50
****
10010010001
36.50
****
10000010001
32.50
****
10010010011
36.56
****
10001
0.50
****
10000000001
32.00
****
10000010011
32.56
****
10010010011
36.56
****

I can not understand why I do not get more reliable data

my best shot:
Negative temps OK (2’s compl)

int CSPin = 4;    
int MISOPin = 14;
int SCKPin = 15;
byte byte1;
byte byte2;
int temp;

void setup()
{
  pinMode(CSPin, OUTPUT); //
  digitalWrite(CSPin, HIGH);
  pinMode(SCKPin, OUTPUT);
  pinMode(MISOPin, INPUT_PULLUP);
  Serial.begin(9600);
  // EDIT
  delay(350); // Allow sensor to do its 1.st reading after powerUp. (I guess this can be removed)
}

void loop()
{
  digitalWrite(CSPin, LOW);
  delay(1); // EDIT: This may be removed ???
  byte1 = shiftIn(MISOPin, SCKPin, MSBFIRST);
  byte2 = shiftIn(MISOPin, SCKPin, MSBFIRST);
  // EDIT. Add:
  byte2 = byte2 & 0xF8; // mask away 3 bits. You dont need them
  digitalWrite(CSPin, HIGH);
  temp = (int) byte1 << 8;
  temp |= byte2;
  float temp2 = (float)temp / 128; // EDIT equals >>3 and  * 0.0625;
  temp = temp >> 3; // Edit
  Serial.println(temp, BIN);
  Serial.println(temp2);
  Serial.println("****");
  delay(2000);
}

If still trouble…: Make a while_loop.
Test ‘conversion_ready’-bit.
exit loop with the good values.

void loop()
{
  do while (true)
    {
      digitalWrite(CSPin, LOW);
      delay(1); // EDIT: This may be removed ???
      byte1 = shiftIn(MISOPin, SCKPin, MSBFIRST);
      byte2 = shiftIn(MISOPin, SCKPin, MSBFIRST);
      // EDIT. Add:
      digitalWrite(CSPin, HIGH);
      if (byte2 & 4) break;
    }
  byte2 = byte2 & 0xF8; // mask away 3 bits. You dont need them
  temp = (int) byte1 << 8;

It's the best here until now

11111111111111111111011000010011
-158.81
****
1000010000
33.00
****
11111111111111111111100010000000
-120.00
****
1000010001
33.06
****
11111111111111111111011000000000
-160.00
****
1000010000
33.00
****
11111111111111111111101010010111
-86.56
****
1000010000
33.00
****
11111111111111111111011000011000
-158.50
****
1000010000
33.00
****
11111111111111111111011000011000
-158.50
****
1000010000
33.00
****
11111111111111111111011010010000
-151.00
****
1000010000
33.00
****

I think 33 degrees is too much.
I supply the sensor with 3.3v, but it should not mean anything.
If I make a sorting and removes the data that make no sense it looks sensible out

I had not seen your last code before now

void loop()
{
  
 do 
 {
   digitalWrite(CSPin, LOW);
   delay(1); // EDIT: This may be removed ???
   byte1 = shiftIn(MISOPin, SCKPin, MSBFIRST);
   byte2 = shiftIn(MISOPin, SCKPin, MSBFIRST);
   // EDIT. Add:
   digitalWrite(CSPin, HIGH);
   if (byte2 & 4) break;     
    }while (true);
    
  byte2 = byte2 & 0xF8; // mask away 3 bits. You dont need them
  temp = (int) byte1 << 8;
  temp |= byte2;
  float temp2 = (float)temp / 128; // EDIT equals >>3 and  * 0.0625;
  temp = temp >> 3; // Edit
  Serial.println(temp, BIN);
  Serial.println(temp2);
  Serial.println("****");
  delay(2000);
}

And the output

****
1000110011
35.19
****
1000100000
34.00
****
1000000011
32.19
****
1000100001
34.06
****
110001
3.06
****
10000
1.00
****
1000010010
33.13
****
10001
1.06
****

I'd like to see those signals on a scope..
It seems like you miss a single bit (value 32)

Noise ?? -> add a capacitor Ucc-Gnd close to sensor

from the Arduino reference:

If you're interfacing with a device that's clocked by rising edges, you'll need to make sure that the clock pin is low before the first call to shiftIn(), e.g. with a call to digitalWrite(clockPin, LOW).

That means: add a sentence in Setup

Hope you succeed..

Note the datasheet figures 2.6 and 2.7
Indicate you should use the correct Ucc for the sensor, (to get correct temp)
A 5V sensor @ 3v3 will be 'far off''

You are probably right with the noise problem.

We are creating a shield where we had problems with an analog temperature sensor (we use a stepup), so my CT77 sitting with wiring without external capacitor

I think my problems are solved with a new pcb with capacitor Ucc-Gnd and 5V suppy.

Many thanks for the help, you've been a great help.