Using LM70 temperature sensor with Arduino I am trying to sense the temperature using the LM70 temperature sensor with an Arduino Mega. As you can see in the Datasheet, it uses the SPI protocol. I have made the following connections (VSSOP-8 Package):

SI/O pin --&gt; Pin 50 Arduino Mega.
SC pin --&gt; Pin 52 Arduino Mega.
CS pin --&gt; Pin 53 Arduino Mega.
V+ pin --&gt; 3.3V Arduino Mega.
GND pin --&gt; GND Arduino Mega.

My code does not work (it does not print the right temperature), and I think it can be for two reasons:

I am not reading correctly the information from the sensor. It sends 16 bits, from which the 11 first bits store the data for the temperature.
I am not calculating the temperature in the right way.

This is my code:
// the sensor communicates using SPI, so include the library:
#include &lt;SPI.h&gt;

void setup() {
  pinMode(51,OUTPUT); //MOSI
  pinMode(50,INPUT); //MISO
  pinMode(52,OUTPUT); //CLOCK PIN
  digitalWrite(53,HIGH); //slave select stays high. When we set this to low, the sensor will start to send data.
  SPI.begin();
  Serial.begin(9600);

  //time to set up
  delay(500);
}

void loop() {
    //enable Slave
    digitalWrite(A0,LOW); //Enable communication with slave
    delay(500); //wait for conversion
    
    int val = SPI.transfer(0x00); // read from sensor
    Serial.println(val); //display reading on serial monitor
    int temperature = val * 0.25;
    Serial.println(temperature); //display temperature on serial monitor


    //disable Slave
    digitalWrite(53,HIGH); //set to High again
}

Please, if you see something wrong in my code, let me know.
Thank you in advance.
There are several things that are not doing correctly. This is not a complete answer but to provide you some directions on how to get it right.

A0 is pin 54, it is not SS which is pin 53;

On how to use the SPI library properly, I would suggest that you read my blog on SPI, it will also help you to get the data out of data sheet that you need for SPI programming. Based on the timing diagram on the data sheet, you will need to configure the SPI as SPI_MODE2;

LM70 SI/O pin is used as both MOSI and MISO, you will need to connect MOSI to SI/O via a 10k resistor, and connect SI/O direct to MISO, this information is available in the data sheet;

LM70's temperature data is in Two's complement format, To convert it, it needs a little bit work. It is then need to shift down/right using bitshift operator by 5 bits to get ride of the first 5-bits, before finally multiply by 0.25C as per data sheet.


int value = 0x4b1f;  //value from SPI, temp = 125 degree C
int mask = 0x8000;   // mask for MSB
int temp = (-(value &amp; mask) + (value &amp; ~mask)) &gt;&gt; 5;
Serial.print(&quot;Temp&quot;);
Serial.println(temp*.25);

Read all links that I provided to understand the subjects and give it a try. Good luck!