Teensy 4.1 and MAX31865: SPI not working

Math51

New member
Hello,

A few years ago, I realized à projet of a LORA temperature sensor using a PT1000 with an Adafruit MAX31865 amplifier dev board and a CubeCell dev board.
Now I have a new different project (nothing to do with LORA), using a Teensy 4.1 for which I want to acquire a temperature measurement via a PT1000. So for this project, I wanted to reuse an Adafruit MAX31865 development board for the acquisition of the PT1000 by porting to the Teensy 4.1 the part of code that I had written for the CubeCell which allowed communication in SPI with the MAX31865.
Here is the wiring diagram I made on a breadboard to connect the Teensy 4.1 in SPI to the MAX31865:
Teensy-MAX31865.jpg


On the following link, you can find the code that I have made for the Teensy (Using VS Code + PlatformIO, like my CubeCell projet):

The main purpose of the code is to command the MAX31865 to take a one-shot measurement and send the temperature and fault register values over USB for display in a terminal.
In the void setup() function, I first initialized the serial communication and then I call the function bool max31865Init() function.
In the max31865Init(), following task are done :
- Configure the CS pin for MAX31865
- Made some calculation do determine the value of the MAX31865 config register (function of some parameter depending of the PT sensor used)
- Then call the max31865Write() function to send the value of the config register to the MAX31865
The max31865Write() is a function dedicated to write data on MAX31865 via the SPI bus. So max31865Write() receives as input the adress of the register to write and the value to write. Then max31865Write() do the following task :
- Initializes the SPI bus with adapted parameters for transmission to MAX31865
- Set to LOW the CS pin
- Used SPI.transfer(adress) function to send via SPI the MAX31865 register adress in which to write
And at this step the program "crash". Not sure it's literraly crash, but nothing happens after that.
I add in my code some message call "Test point x" to be send to the terminal to identify where the program stop. And the program stop at the call of the function SPI.transfer(adress); (line 175 of max31865.cpp file). The message "Test point 3quater" is never send to the terminal.

I've made some research on the SPI of the Teensy 4.1, but I have not found any information that would allow me to move forward in resolving my problem.
What I find strange is that pin 13 for the SCK is also used for the LED. I wonder if this is a problem ?
But if it was just a CS problem, I don't see why the program would stop: I would expect it to continue and that in the rest I have an error because the rereading of the conf register would have a different value from the written value (function that I implemented in the rest of the program).

Do you have any idea what could be going on?

Note: the MAX31865 code was fully fonctionnal on my previous LORA projet.

Thank in advance for your help.

Math
 
You need SPI. begin() in your setup() or init function.

Also, not 100% sure what compiler will do, but the last line of the read function may be incorrect. dataMSB is a byte. You should either define it as uint16_t or cast it to uint16_t before shifting it left 8. You also might want to use parentheses to indicate the intended order of operations rather than try to remember whether << has higher priority than |.

Code:
    *data = dataMSB << 8 | dataLSB;            // Combine MSB and LSB data
 
Hello,

You need SPI. begin() in your setup() or init function.

Arh yes, you are right, I forgot to copy this line ! Thank you very much !

Also, not 100% sure what compiler will do, but the last line of the read function may be incorrect. dataMSB is a byte. You should either define it as uint16_t or cast it to uint16_t before shifting it left 8. You also might want to use parentheses to indicate the intended order of operations rather than try to remember whether << has higher priority than |.
This worked as is in the previous code. But to be cleaner and avoid potential problems, I fixed it by changing the type to word.

Thank you !

Math
 
Back
Top