polihedron / DIY-Reflow-Oven

DIY Reflow Oven, mcu: STM32F103 dev board, Display: Nextion Basic 3.5", PID controller.
BSD 3-Clause "New" or "Revised" License
27 stars 10 forks source link

Temp (t0) returns zero #9

Closed planestoner closed 1 year ago

planestoner commented 2 years ago

'temp' & t0 returns/displays zero (0.0) on Nextion display and serial logging when flashing release and debug Reflow_Oven_STM32.bin

Multiple resolutions attempted to no avail including:

When testing MAX6675 module with ESP32 it shows this: ESP32 trace

When testing MAX6675 module with STM32F103 with Reflow_Oven_STM32.bin it shows this: Polihedron debug trace

When debugging Reflow_Oven_STM32.bin with ST-Link V2 'temp' reads 0.0 when setting breakpoint on main.c line 793

        if (ReflowEnable == 1) {

However, 'temp' reads correctly when setting breakpoint on main.c after line 779 (after HAL_SPI_Receive)

        //Thermocouple alle 500ms auslesen:
        HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, 0);      // 778
        HAL_SPI_Receive(&hspi1, data, 2, 100);           // 779
// Breakpoint
        HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, 1);      // 780

When adding HAL_Delay(1); the code runs fine (with CS being pulled low horribly long), although, this is merely a work around and not a proper fix. I tried the delay in a few placed but this seems the best location for the workaround.

        //Thermocouple alle 500ms auslesen:
        HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, 0);
        HAL_SPI_Receive(&hspi1, data, 2, 100);
        HAL_Delay(1);
        HAL_GPIO_WritePin(CS_GPIO_Port, CS_Pin, 1);

I considered raising a PR with the added delay but STM32 documentation doesn't include it nor does the MAX6675 datasheet. I'm not entirely sure this is an issue with the code, however, raising an issue as there are no doubt better minds than mine out there with a lot more experience. Also raising this for those in the future that run into this problem. Suggested possible causes:

polihedron commented 2 years ago

thanks @planestoner, I like your effort, can you check what HAL_SPI_Receive() returns? like: HAL_StatusTypeDef errcode; errcode = HAL_SPI_Receive(&hspi1, data, 2, 100);

Data from logic analyser seems to be fine in both cases:

0321 reads 1100100 = 100dec *0.249 = 24.9C

02D1 reads 1011010 = 90dec *0.249 = 22.4C

that hal_delay fix is quite strange anyway..

planestoner commented 2 years ago

Thanks @polihedron for the reply. I've tried a few things and long story short I only get a good temp reading is the the inclusion of the hal_delay.

With errcode = HAL_SPI_Receive(&hspi1, data, 1, 100); and without delay I get these: Debug with errcode trace with errcode

Setting HAL_SPI_Receive(&hspi1, data, 1, 100); seems to pull CS low for too short a time unless I introduce the delay and I get this (errcode returns HAL_OK): trace with data,1 and delay

polihedron commented 2 years ago

@planestoner maybe spi is not ready then?

this code is a bit messy, and since my oven is working I don't have time and motivation for general refactoring. so my another idea is to use library like: https://github.com/ipa64/MAX6675-STM32-library-using-HAL

or check this: while ((HAL_SPI_GetState(&hspi1) != HAL_SPI_STATE_READY)); put it before spi read.

planestoner commented 2 years ago

I'm in the same boat regarding time and since my device works with the included delay I'm happy for you to close the issue.

If the code is the issue maybe we or someone will be able to spot it and re-open this issue. In the mean time the work around is to add in the delay.

Gokhanto commented 1 year ago

@planestoner @polihedron Hi Guys, i havent seen the issue here, i managed to buy all the parts and assembled all the parts and noticed that the temperature reading is stable 0.0 Degrees. Can you please help me? Can i use your bin file with the delay to fix my issue?

polihedron commented 1 year ago

Hi there @Gokhanto

Gokhanto commented 1 year ago

@polihedron Thanks for the quick reply. I started to open the project file but the main.c document looked like a chineese document with weird sysmbols, not much to read. But i managed to open the main.c file by it self and added the delay, but im getting an error "Failed to connect to device., Failed to start GDB server." error1

polihedron commented 1 year ago

@Gokhanto I'm sorry I can't help you with this, please read or watch some tutorials on internet how to flash stm32 bluepill with st-link.

planestoner commented 1 year ago

I've checked and sadly I don't have any of those files any more. Sorry

Gokhanto commented 1 year ago

@planestoner @polihedron Just for your information, i found out that the stm32, i had were a clone, so i ordered a new one and it solved all the problems, everything works.