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;
}