First spiread return false read, other are good

Status
Not open for further replies.

Manu

Well-known member
Hello,

I'm work on a project using a Teensy 3.2. With this project 4 MAX31855 are used. Each MAX chip use the same spi bus with a different CS pin. All is fine, except the very first spiread.

I use a part of adafruit max38155 library. My current The code is :

Code:
void lectureMAX (uint8_t TKtoRead) {
  uint32_t TKFrame = infoTK[TKtoRead].instance->spiread32();
  uint32_t temp = TKFrame;
  Serial.println(temp);

Code:
uint32_t MAX31855::spiread32(void) {
  uint32_t d = 0;
  pinMode(cs, OUTPUT);
  digitalWrite(cs, LOW);
  delay(2);
  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
  d = SPI.transfer(0);
  d <<= 8;
  d |= SPI.transfer(0);
  d <<= 8;
  d |= SPI.transfer(0);
  d <<= 8;
  d |= SPI.transfer(0);
  SPI.endTransaction();
  digitalWrite(cs, HIGH);
  return d;
}

Here what happen :
Code:
First spiread result => 54540960
Calculated Value => 52.00
Average[0] : 52.00

28057072
26.75
[1] : 26.75

27532688
26.25
[2] : 26.25

26745936
25.50
[3] : 25.50

27270496
26.00
[0] : 39.00

As you can notice, the first spiread is false. How can I solve this ? I think I need to initialise spi before the first read, but I'm unsure how to do it.

Thank you fao any advice.
Manu
 
Solved,
I added just after the spi.begin() this :
Code:
SPI.begin();
  delay(2);
  SPI.beginTransaction(SPISettings(4000000, MSBFIRST, SPI_MODE0));
  delay(2);
  SPI.endTransaction();

I'm unsure it is the best method and if someone have a better answer ;-)
 
Status
Not open for further replies.
Back
Top