LTC2498 Temperature Sensor Chip Code via SPI

I would be very grateful for your tips for my present problem definition:

I have a microcontroller ATmega128RFA1 with integrated Zigbee with UART-USB(TTL Converter) attached to the PC.

From the ATmega128RFA1 I have connected via SPI a LTC2498 Temperature Sensor Chip.

I need to read The Temperature from LTC2498 on The Terminal Program in my PC. The scheme is as follows:

LTC2498–SPI–uC(Programmed with code Read_ltc2498)–UART_USB–PC.

The code with which I am working is as follows:

`#include <avr/io.h>
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
#include <util/delay.h>

#define DD_MISO 3
#define DD_MOSI 2
#define DD_SCK 1
#define DD_SS 0

void uart_init()
{
uint16_t temp = ((8000000)/(9600.0*16)-1); //Calculation transmission rate

UBRR0L = temp; //Transmitting transmission rate
UBRR0H = temp>>8;

UCSR0B |= (1<<TXEN0)|(1<<RXEN0)|(1<<RXCIE0); //Sending and receiving Free


UCSR0C |= (1<<UCSZ00)|(1<<UCSZ01);  //Assignment format: 8 bit

}

int sendestring(char *s)
{
int i=0;

for(i=0; s[i] != '\\0'; i++)
{
    while bit_is_clear(UCSR0A, UDRE0); //wait, until UDRE0 = 1 (Send free)

    UDR0 = s[i]; //send sing

}

return 0;

}

void SPI_MasterInit(void)
{
//Outputs: MOSI, SCK, SS
DDRB = (1<<DD_MOSI)|(1<<DD_SCK)|(1<<DD_SS);

//Enable SPI, Master-Mode, set clock rate fck/16
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);

}

int SPI_MasterTransmit(char MOSI)
{
//start Transmission
SPDR = MOSI;

//wait for transmission complete
while(!(SPSR & (1<<SPIF)));

//returned data from slave to master
return SPDR;

}

int main()
{

char str[20];

// Thermoelement an CH0 und CH1
char masterOut1 = 0b10100000;

// interne Temperaturmessung:
char masterOut2 = 0b10000000;

char result;
uint32_t masterIn = 0;
uint32_t Temp = 0;

uart_init();    

SPI_MasterInit();


for(;;)
{

    _delay_ms(500);

    //CS des Thermochips to low
    PORTB &= !(1<<DD_SS);


    //Byte1
    result = SPI_MasterTransmit(masterOut1);        
    masterIn = (result & 0b00011111);  /*last 3 bits lost/*
    sendestring(str);

    //Byte2
    result = SPI_MasterTransmit(masterOut2);
    masterIn = (masterIn<<8) + result;


    //Byte3
    result = SPI_MasterTransmit(0);
    masterIn = (masterIn<<8) + result;


    //Byte4
    result = SPI_MasterTransmit(0);
    masterIn = (masterIn<<8) + result;


    //CS des Thermochips to high
    PORTB |= (1<<DD_SS);


    masterIn = (masterIn>>5) & 0b00000000111111111111111111111111; /*Last 5 bits lost/*

    sendestring(" masterIn: ");
    sprintf(str, "%ld", masterIn);
    sendestring(str);

    //bei interner Temperaturmessung: Temperatur in °C berechnen laut Datenblatt Seite21
    Temp = (masterIn*4/1570)-273;

    sendestring(" Temp: ");
    sprintf(str, "%ld", Temp);
    sendestring(str);

    _delay_ms(2000);
}


return 0;

}`

I have tried change in SPI function the 4 modes for CPOL and CPHA bits and DORD in the SPCR Register but doesn´t work.

With the next chars I have LTC2498 configured as follows:

32 bits: Byte1= 10100000; Byte2= 10000000; Byte3= 00000000; Byte4= 00000000;

The results are around this:
result1: 11111111 masterIn: 16777215 Temp: 42471

masterIn = DATAOUT according to the LTC2498 DataSheet has to be around 80000, so is too high.

Could anyone help me with this problem please? I have tried all, but is impossible.

Thanks in advance,
Hector.

I’m afraid as this problem doesn’t involve an imp in any way that I can see, it’s probably a question best asked on an AVR forum…