Can some1 help to port library

zouk199
Tue Apr 25, 2017 9:48 am
https://github.com/adafruit/MAX6675
I want it to work with stm32f401.
Thanks in advance

BennehBoy
Wed Apr 26, 2017 10:48 am
I think the best approach would be to try it yourself and ask for specific help on issues which arise.

zouk199
Wed May 03, 2017 3:28 am
hi mr ben
i tried https://github.com/JChristensen/Thermocouple

can compile

n upload

but doesnt run for some reason.

can u pls help##


Riva
Wed May 03, 2017 7:00 am
How have you got the MAX7765 device connected to your f401 and what f401 are you using?

zouk199
Fri May 05, 2017 3:45 am
i have max6675 board from ebay and i am using f103rb.original arduino library is attached@@

Riva
Fri May 05, 2017 7:28 am
zouk199 wrote:i have max6675 board from ebay and i am using f103rb.original arduino library is attached@@

zouk199
Fri May 05, 2017 7:41 am
thanks riva for trying d library

i connect spi sck to pin d13/pa5
spi cs to d10/pb6
spi miso to d12/pa6


edogaldo
Fri May 05, 2017 9:03 am
zouk199 wrote:i have max6675 board from ebay and i am using f103rb.original arduino library is attached@@

Riva
Fri May 05, 2017 9:26 am
The MISO/SCK appear to be on the right pins, SS is user definable though the F103R variant file places it on PA4.
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


ag123
Fri May 05, 2017 10:24 am
hi zouk199,

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


zouk199
Mon May 08, 2017 1:36 am
hi riva

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.


ag123
Mon May 08, 2017 6:36 am
i’d suggest copy and place Thermocouple.cpp and Thermocouple.h in the same folder as your sketch. i.e. use it as source rather than as a ‘library’

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


longjam
Mon Jul 03, 2017 4:03 pm
#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;
}
}


stevestrong
Mon Jul 03, 2017 6:05 pm
???

zmemw16
Mon Jul 03, 2017 8:13 pm
for some daft idea i think i recognize parts of that from a library. i found 2 max6675 libraries, difference bar one not working, was the capitalisation of the library name.
even then when subsequently i wanted to use it i had to try both again 50/50 chance :D
i don’t recall any problems using it on a BP or MM.
also are we back at school/college this early ?
stephen

RogerClark
Tue Jul 04, 2017 9:14 pm
I can’t remember what I used, but I have used a thermocouple before with the STM32.

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


MakcYan
Tue Nov 07, 2017 7:21 pm
English variant:
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);

После этих изменений работает дисплей и два термодатчика.


victor_pv
Tue Nov 07, 2017 10:03 pm
Thanks MakcYan. I was about to use this library. Found I made the same modifications, but haven’t tested it yet. Your post confirms that should be all that’s needed. :)

There are some more updated forks that use the HW SPI port. Did you test any of those?


MakcYan
Wed Nov 08, 2017 5:17 am
victor_pv
No, I did not check, the rest of my pins are busy.

Leave a Reply

Your email address will not be published. Required fields are marked *