i tried https://github.com/JChristensen/Thermocouple
can compile
n upload
but doesnt run for some reason.
can u pls help##
i connect spi sck to pin d13/pa5
spi cs to d10/pb6
spi miso to d12/pa6
static const uint8_t SS = BOARD_SPI1_NSS_PIN;
static const uint8_t SS1 = BOARD_SPI2_NSS_PIN;
static const uint8_t MOSI = BOARD_SPI1_MOSI_PIN;
static const uint8_t MISO = BOARD_SPI1_MISO_PIN;
static const uint8_t SCK = BOARD_SPI1_SCK_PIN;
#define BOARD_SPI1_NSS_PIN PA4
#define BOARD_SPI1_SCK_PIN PA5
#define BOARD_SPI1_MISO_PIN PA6
#define BOARD_SPI1_MOSI_PIN PA7
i think riva is right, check your pin assignments, note that selecting a different board could lead you to different pin assignments in the board.c assignments array, you may need to cross reference a schematic and board layout as well. i often have multiple pictures/files opened so that i could be assured i picked the correct pins. in stm32 it gpios is normally referenced by its PAxx .. Pnxx pins. but boards.c use an index into the array to select the pin and may lead to goofs like you may be expecting PAxx but it is literally Pnxx something else.
the other thing is MAX6675.pdf apparently specify a max clock frequency of 4.3 mhz
https://datasheets.maximintegrated.com/ … AX6675.pdf
the codes seem to target a SPI clock of 1MHZ
https://github.com/JChristensen/Thermoc … le.cpp#L35
SPI.setClockDivider(SPI_CLOCK_DIV16); //Set SPI clock freq to 1MHz
i tried to // those 3 mosi/sck/miso and try to complie and run.still no luck with one tc example
i did chg change #define csTC1 10 to #define csTC1 PB6.
it seems like thermocouple routine is not running.
if i put //on //Thermocouple tc1 = Thermocouple(csTC1); //instantiate the thermocouple object then it run
of coz no result.
it seems our thermocouple() function may be some problem.
then in your copy of Thermocouple.cpp, you could insert Serial.print() statements to examine the variables e.g.
https://github.com/JChristensen/Thermoc … le.cpp#L45
tcData = SPI.transfer(0x00) << 8;
tcData |= SPI.transfer(0x00);
Serial.println(tcData); << add print statements to check the data read
#include <SPI.h>
#define SPI1_NSS_PIN PA4 //SPI_1 Chip Select pin is PA4. You can change it to the STM32 pin you want.
boolean _first = true;
float _temps[6];
void setup() {
Serial2.begin(115200);
// Setup SPI 1
SPI.begin(); //Initialize the SPI_1 port.
SPI.setBitOrder(MSBFIRST); // Set the SPI_1 bit order
SPI.setDataMode(SPI_MODE0); //Set the SPI_2 data mode 0
SPI.setClockDivider(SPI_CLOCK_DIV64); // Slow speed (72 / 16 = 4.5 MHz SPI_1 speed)
pinMode(SPI1_NSS_PIN, OUTPUT);
}
void loop() {
float tempC, tempF;
tempC=readC();
tempF=readF();
Serial2.print("Deg C = ");
Serial2.print(tempC);
Serial2.print("\t Deg F = ");
Serial2.println(tempF);
delay(2000); //Delay 10 micro seconds.
}
float readC(){
unsigned int tcData;
float temp, avgTemp;
digitalWrite(SPI1_NSS_PIN, LOW); // manually take CSN low for SPI_1 transmission
tcData = SPI.transfer(0x00) << 8; //Send the HEX data 0x55 over SPI-1 port and store the received byte to the <data> variable.
tcData |= SPI.transfer(0x00);
digitalWrite(SPI1_NSS_PIN, HIGH); // manually take CSN high between spi transmissions
if (tcData & 0x0004) { //open thermocouple circuit
return -1.0;
}
else {
temp = (tcData >> 3) / 4.0; //calculate deg C
if (_first) { //if first time through, fill the readings array
_first = false;
for (int i=0; i<6; i++) {
_temps[i] = temp;
}
}
for (int i=0; i<5; i++) { //shift prior readings
_temps[i] = _temps[i+1];
}
_temps[5] = temp; //put the new reading in at the top end of the array
avgTemp = 0.0; //calculate the average
for (int i=0; i<6; i++) {
avgTemp += _temps[i];
}
avgTemp /= 6.0;
return avgTemp;
}
}
float readF() {
float tempC;
tempC = readC();
if (tempC < 0.0) {
return tempC;
}
else {
return tempC * 9.0 / 5.0 + 32.0;
}
}
even then when subsequently i wanted to use it i had to try both again 50/50 chance
i don’t recall any problems using it on a BP or MM.
also are we back at school/college this early ?
stephen
I think I just used a library from Adafruit or perhaps Sparkfun, and it worked with no changes at all.
I will have to dig out the code and check precisely what I used
Can to whom be useful my experience.
With the library of Thermocouple for me a display left off to work 3.2′ ILI9341 8bit (library of author of iwalpola).
Decided to try with the library of adafruit max6675, to adapt this library under STM32 it is necessary to make alteration in max6675.cpp:
- #include <util/delay.h> -> //#include <util/delay.h>
- to replace everything _ delay _ ms (1); -> delay (1);
After these changes a display works and two thermo sensor.
Russian variant:
Может кому пригодиться мой опыт.
С библиотекой Thermocouple у меня перестал работать дисплей 3.2′ ILI9341 8bit (библиотека автора iwalpola).
Решил попробовать с библиотекой adafruit max6675, чтобы адаптировать эту библиотеку под STM32 необходимо внести изменения в max6675.cpp:
- #include <util/delay.h> -> //#include <util/delay.h>
- заменить все _delay_ms(1); -> delay(1);
После этих изменений работает дисплей и два термодатчика.
There are some more updated forks that use the HW SPI port. Did you test any of those?
No, I did not check, the rest of my pins are busy.

