Transferring temperature from arduino to duet using SPI

  • Hello everybody!

    I was wondering how it would be possible to transfer the temperature data from the thermocouples from arduino to the duet board using the spi channel instead of having the thermocouple directly in contact with the board.

    There's some explanation in ThermocoupleSensor31855.cpp about how the bits should be organized but so far I haven't been able to get anything understandable from duets end.

    the code in arduino looks like this

    #include <SPI.h>
    long data2 = 233832944;
    union {
      long data;
      byte bytes[4];
    } sender;
    void setup (void)
      Serial.begin (115200);   // debugging
      // turn on SPI in slave mode
      SPCR |= bit (SPE);
      // have to send on master in, *slave out*
      pinMode(MISO, OUTPUT);
      // get ready for an interrupt 
      process_it = false;
      // now turn on interrupts
    }  // end of setup
    // main loop - wait for flag set in interrupt routine
    void loop (void)
    { = 233832944;
      digitalWrite(SS, LOW);    // SS is pin 10
      // send test string
      for(int i = 0; i < 4; i++){
      //SPI.transfer(data2);  does not work either
      // disable Slave Select
      digitalWrite(SS, HIGH);
    }  // end of loop

    I derived the 233832944 by looking at the order that was instructed in ThermocoupleSensor31855.cpp and putting test values on bits on supposedly their right place.

    If I understood correctly the sequence consists of 4 bytes or 32 bits, the first three bits are reserved for SVG faults, the fourth bit is just reserved? After that comes 12 bits for reference temperature, then one bit for fault indicator and then one bit reserved. The rest of the bits are for the actual temperature.

    The room temperature should be divided by 0.0625 and the thermocouples temp should be divided by 0.25.

    If we give some test numbers the room temp would be (int)(22.3 / 0.0625) = 3 568 and the sensor temperature would be (int)(124 / 0.25) = 496. in binary these numbers would be: 110111110000 and 111110000

    assigning this to the 32 bit message would be:


    I divided everything into sections so it's easier to read. This sequence converts into an integer of 233832944. I've tried to transfer it as a whole and in four bytes on byte at the time when you look at the temperatures in duet they show really crazy numbers. I don't have much experience in data transfer so there's probably whole lot that I'm missing. Is there anyone who would have the expertise to help me tackle this problem?

    Best regards,

Log in to reply