0

Help please

I am trying to connect an Arduino Due via a SPI bus to a MAXIM31855 thermocouple sensing chip. I am using Arduino IDE version 1.6.11. The problem I am having is that the code will only read the SPI bus once, it will not loop, regardless of how many times I call the function to read the SPI bus.

I have connected the clock and the MISO to the pin header just below the SAM processor chip its labeled SPI and I have connected the CS to pin 4.

Each time I press the reset button on the Due, the SPI will read once. I have confirmed this by using a Salae logic analyser. The Due doesn't lock up as other functions continue normally, it simply will not repeat the SPI read.

The 4 bytes that are returned from the Max are consistent with the specification for the chip as are the timing of the clk (4kHz) and the MISO logic levels (there is no MOSI in this MAX chip).

If anyone has a clue as to why this will not loop I would appreciate their input.

Cheers

#include <SPI.h>
//Give convenient names to the control pins

#define slaveAPin 10
// set up the speed, data order and data mode
SPISettings settingsA(4000000, MSBFIRST, SPI_MODE1);

void setup() {

  Serial.begin(9600);
  pinMode(slaveAPin,OUTPUT);
  SPI.begin(slaveAPin);

}

uint8_t  val1, val2, val3, val4;

void loop() {
// read four bytes from device A
 Serial.println(ReadTemp());
 delay(1000);


 }

uint8_t ReadTemp(void)
{
  SPI.beginTransaction(settingsA);
  digitalWrite (slaveAPin, LOW);
  // reading only, so data sent does not matter
  val1 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val2 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val3 = SPI.transfer(slaveAPin,0x00,SPI_CONTINUE);
  val4 = SPI.transfer(slaveAPin,0x00,SPI_LAST);
  digitalWrite (slaveAPin, HIGH);
  SPI.endTransaction();

  return val2;

}

migrated from electronics.stackexchange.com Aug 24 '16 at 10:17

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • Where's your main function? Does it have a forever loop? – Iancovici Aug 24 '16 at 10:14
  • Call the SPI Transaction in void loop and then print val2 and let us know the results. I don't know if Serial.println can take functions as an argument. – ammar.cma Aug 24 '16 at 12:19
  • @ammar.cma it's not taking function as an argument. It's taking result from function call (type is uint8_t). – KIIV Aug 24 '16 at 12:49
  • Check this bug report; github.com/arduino/Arduino/issues/1406. Might need to update the Arduino IDE with the latest Due version. – Mikael Patel Aug 24 '16 at 14:29
  • @KIIV yeah. Function call :/ – ammar.cma Aug 24 '16 at 14:44

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy