Can some1 help to port library

Can someone help me port this library?
zouk199
Posts: 15
Joined: Thu Aug 04, 2016 1:47 am

Re: Can some1 help to port library

Post by 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
Posts: 810
Joined: Thu Jul 21, 2016 4:24 pm

Re: Can some1 help to port library

Post by 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

Code: Select all

tcData = SPI.transfer(0x00) << 8;
tcData |= SPI.transfer(0x00);

Serial.println(tcData); << add print statements to check the data read 
zouk199 wrote:i connect spi sck to pin d13/pa5
spi cs to d10/pb6
spi miso to d12/pa6
u'd need to be sure of your board and pin assignments and update the codes e.g.

Code: Select all

#define MOSI  PA7    //master out slave in (not connected)
#define MISO  PA6    //master in slave out
#define SCK PA5 //serial clock
try a low speed SPI clock

Code: Select all

SPI.setClockDivider(SPI_CLOCK_DIV64); //72 mhz / 64
interestingly stm32f4 use the same paxx pin assignments as stm32f1 for spi1, so in principle it should work if u connect to the right pins :lol:

longjam
Posts: 1
Joined: Mon Jul 03, 2017 3:58 pm

Re: Can some1 help to port library

Post by longjam » Mon Jul 03, 2017 4:03 pm

Code: Select all

#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
Posts: 1835
Joined: Mon Oct 19, 2015 12:06 am
Location: Munich, Germany

Re: Can some1 help to port library

Post by stevestrong » Mon Jul 03, 2017 6:05 pm

???

zmemw16
Posts: 1491
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Can some1 help to port library

Post by 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

User avatar
RogerClark
Posts: 7494
Joined: Mon Apr 27, 2015 10:36 am
Location: Melbourne, Australia
Contact:

Re: Can some1 help to port library

Post by 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
Posts: 15
Joined: Tue Oct 24, 2017 6:27 pm

Re: Can some1 help to port library

Post by 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
Posts: 1750
Joined: Mon Apr 27, 2015 12:12 pm

Re: Can some1 help to port library

Post by 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
Posts: 15
Joined: Tue Oct 24, 2017 6:27 pm

Re: Can some1 help to port library

Post by MakcYan » Wed Nov 08, 2017 5:17 am

victor_pv
No, I did not check, the rest of my pins are busy.

Post Reply