1
#include<spi.h>
byte val;     // variabe for storing temp data
#define PIN_SPI_SS    (9)
#define PIN_SPI_MOSI  (10)
#define PIN_SPI_MISO  (11)
#define PIN_SPI_SCK   (12)

void setup();
pinMode(SS,output);
pinMode(SCLK,output);
pinMode(MOSI,output);
spi.setBitorder(MSBFIRST);
SPI.setDataMode(SPI_MODE3);
serial.begin(9600);
spi.begin();

void loop();
  digitalWrite(SS,LOW);
  uint8_t b1 = SPI.transfer(0x00);
  uint8_t b2 = SPI.transfer(0x00);
  uint8_t b3 = SPI.transfer(0xFF);
  digitalWrite(SS,HIGH);
  int16_t val = b1 | b2 ;
  serial.print("val=");
  serial.println(val,DEC); 

refer for DATA SHEET//https://www.ti.com/lit/ds/symlink/lm74.pdf?ts=1591436049550&ref_url=https://www.ti.com/product/LM74 my problem is i am not able to know what command should i use in SPI.transfer function for writing & reading temperature data here i use 0x00 for reading 16 bit data of temperture register,but what about writing in configuration register ,LM74 use 0xFF command for shutdown mode,but how we came to know that 0xFF refer only to configuration register.

1 Answer 1

1

In the LM74 the third byte you send (or more specifically the last 8 bits of up to 32 bits past the 16th bit that you send) is read and used as the configuration register setting.

Since the configuration register only has two states 0xFF is go to sleep sleep and 0x00 is do conversions (as shown in table 1 of the datasheet).

So:

0x00 0x00 0xFF

means get one result then go to sleep.

0x00 0x00 0x00

means get one result and stay awake.

If the LM74 is currently asleep from an 0x00 0x00 0xFF sequence the result you get returned is not a temperature but the chip's manufacturer ID.

It's not an obvious method of controlling a chip, and it's actually pretty poorly written in that datasheet, so don't feel bad about not understanding it, it took me a few moments to understand it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.