This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

DS1722 SPI temperature sensor

Hello, i am trying to read SPI temp from DS1722. Read OK but, values is not linear. Code and example of value:

void DS1722_Init();
int Read_Temp();

int MSB, LSB;
int i_Temp;
float f_Temp;
int Temp_for_print;

void DS1722_Init()
{
    CS_DS1722_1;
    SPI_Write(0x80);
    SPI_Write(0xE8);
    CS_DS1722_0;
}

int Read_Temp()
{
    CS_DS1722_1;
    SPI_Write(0x01);
    SPI_Write(0x00);
    LSB = UCA0RXBUF;
    SPI_Write(0x00);
    MSB = UCA0RXBUF;
    while((UCA0STAT&UCBUSY));
    CS_DS1722_0;

    i_Temp = ((MSB << 8) | LSB);
    f_Temp = i_Temp;
    Temp_for_print = ((f_Temp / 128) * 10);  //   I now this value using to print display

    return Temp_for_print;
}

    x = Temp_for_print / 100;
    y = (Temp_for_print % 100) / 10;
    z = (Temp_for_print % 100) % 10;

Value (xy , z):

26,4

26,3

26,2

26,1

26,0

24,7

24,6

24,5

Where is 25th value? I am try to MSB, LSB set as unsigned char or long... always same problem


Thank You

  • Marek,

    Can you take a look at your unprocessed data (straight form the DS1722 SPI interface) and see if it has the same issue? If the data out of the DS1722 is correct, but the formatted data is not, then you need to check your formatting algorithm (remember, the MSP430 does integer math by default, so you might be losing some precision here. If the data out of the DS1722 has the same gap, then you should contact the manufacturer for the sensor.

    Mike
  • Thank You. Problem resolved. All complication was in SPI configure. CPHA is must set to 0 not to 1. I lost Lsb of MSB and LSB. Therefore is lost 25th value, this MSB LSb is "1" against 26 and 24 have LSb "0". Now is all OK. Right calculate is i_Temp / 256. Not / 128. Previously gained value is "cheating" :-)

**Attention** This is a public forum