I try to us it in STM32 but seems compile passed but not working.
i did move my work to use in Arduino UNO. Then.. code size more than 32kB.
Thanks.
From what I recall, that device has a custom communications protocol, and i suspect as you are running on a 108MHz GD32, that speed may be the problem, i.e you are going too fast.
PS. If you are using the GD32, I presume you read the other thread..
I have mine running ok at 120Mhz
The Lib is from Adafruit/DHT link :-
https://github.com/adafruit/DHT-sensor- … tester.ino
Well, i love speed in GD32 but i am not good in Coding. So, i am working in STM32F103C8T6(RED board).
Thanks,
It uses a function that is not in the STM32 or GD32 core
called
microsecondsToClockCycles
I looked in the Due (SAM) core and it has these defines
#define clockCyclesPerMicrosecond() ( SystemCoreClock / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (SystemCoreClock / 1000L) )
#define microsecondsToClockCycles(a) ( (a) * (SystemCoreClock / 1000000L) )
Please find the library attatched https://github.com/nullydragon/Adafruit_DHT.
Note.
Line 16 of DHT.cpp has maxcycles hard coded at 72000L which works for my maple mini (at 72mhz that should be somewhere in the field of 1-5ms
Line 15 is commented out as there is a type issue (its also redundant with the following change)
Line 240 portInputRegister is passed the output from digitalPinToPort(pin) instead of having it set at the pervious line.
Let me know how it goes.
It may be better to use F_CPU/1000 instead of 72000 as processor clock on some boards is faster e.g GD32 is 120Mhz and on F4 the clock frequency can be up to 180Mhz I think
I thought there was a 180Mhz variant. I only have the 168Mhz F4 Discovery board, but I thought there was a faster one.
Anyway, the main reason for using F_CPU is that the GD32F1 runs at 96Mhz in stable operation, or 120Mhz in overclocked (without any issues) but also some people want to run the STM32F103 at 48Mhz to save power.
I personally dont like hard coded arbitrary values, especially ones that are a derivative of the clock freq.
I recently did a load of tidying up of the STM32F103 after I’d done work on the GD32 core, to try to remove some of the same sort of hard coded values.
There may still be a few references to 72000000 or 72 or 72000 but I think I have replaced most of them with F_CPU derivatives ![]()
I have some error message, when I build the DHTtester.
—————————————————————————————————————————————————-
C:\Users\booker\AppData\Roaming\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE -MMD -ffunction-sections -fdata-sections -nostdlib –param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103c -DVECT_TAB_ADDR=0x8000000 -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10605 -DARDUINO_GENERIC_STM32F103C -DARDUINO_ARCH_STM32F1 -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/include -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/stm32f1/include -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/usb/stm32f1 -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/usb/usb_lib -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\cores\maple -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\variants\generic_stm32f103c -IC:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master r:\TEMP\build3874439298577829562.tmp\DHTtester.cpp -o r:\TEMP\build3874439298577829562.tmp\DHTtester.cpp.o
C:\Users\booker\AppData\Roaming\Arduino15\packages\arduino\tools\arm-none-eabi-gcc\4.8.3-2014q1/bin/arm-none-eabi-g++ -c -g -Os -w -DDEBUG_LEVEL=DEBUG_NONE -MMD -ffunction-sections -fdata-sections -nostdlib –param max-inline-insns-single=500 -fno-rtti -fno-exceptions -DBOARD_generic_stm32f103c -DVECT_TAB_ADDR=0x8000000 -DERROR_LED_PORT=GPIOB -DERROR_LED_PIN=1 -mcpu=cortex-m3 -DF_CPU=72000000L -DARDUINO=10605 -DARDUINO_GENERIC_STM32F103C -DARDUINO_ARCH_STM32F1 -DCONFIG_MAPLE_MINI_NO_DISABLE_DEBUG=1 -DSERIAL_USB -DGENERIC_BOOTLOADER -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -DMCU_STM32F103C8 -mthumb -march=armv7-m -D__STM32F1__ -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/include -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/stm32f1/include -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/usb/stm32f1 -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\system/libmaple/usb/usb_lib -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\cores\maple -IC:\Users\booker\Documents\Arduino\hardware\Arduino_STM32-master\STM32F1\variants\generic_stm32f103c -IC:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master -IC:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master\utility C:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp -o r:\TEMP\build3874439298577829562.tmp\DHT sensor library\DHT.cpp.o
C:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp: In constructor ‘DHT::DHT(uint8_t, uint8_t, uint8_t)’:
C:\Users\booker\Documents\Arduino\libraries\DHT-sensor-library-master\DHT.cpp:18:46: error: ‘microsecondsToClockCycles’ was not declared in this scope
_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for
^
Error compiling.
———————————
I don’t know why ? I find the library attatched https://github.com/nullydragon/Adafruit_DHT.
https://github.com/adafruit/DHT-sensor- … /issues/53
There is a solution in the last post. It was writtein by Roger in the first page of this thread. Better to read it.
However, I dont know if the library would work even if that function was added, because I am not entirely sure how the code is going to be able to count processor cycles.
LOL.
as far as I can tell, that function is only used for debugging
try just commenting out that line.
#define clockCyclesPerMicrosecond() ( F_CPU / 1000000L )
#define clockCyclesToMicroseconds(a) ( ((a) * 1000L) / (F_CPU / 1000L) )
#define microsecondsToClockCycles(a) ( (a) * (F_CPU / 1000000L) )
this is header of the DHT.cpp
/******************************************************************
DHT Temperature & Humidity Sensor library for Arduino.
Features:
- Support for DHT11 and DHT22/AM2302/RHT03
- Auto detect sensor model
- Very low memory footprint
- Very small code
http://www.github.com/markruys/arduino-DHT
Written by Mark Ruys, [email protected].
BSD license, check license.txt for more information.
All text above must be included in any redistribution.
Datasheets:
- http://www.micro4you.com/files/sensor/DHT11.pdf
- http://www.adafruit.com/datasheets/DHT22.pdf
- http://dlnmh9ip6v2uc.cloudfront.net/datasheets/Sensors/Weather/RHT03.pdf
- http://meteobox.tk/files/AM2302.pdf
Changelog:
2013-06-10: Initial version
2013-06-12: Refactored code
2013-07-01: Add a resetTimer method
******************************************************************/
For my DHT22, this lib from Mark Ruys at http://www.github.com/markruys/arduino-DHT was giving only temperature, but humidity was far off.
I like this lib as as advertised, it is very small, and i would add very reliable IME.
The issue was in the different size of “word” type between avr and arm. Changing it to explicit type “uint16_t” solved the issue.
I contacted the author who updated his repo. So current version works out of the box, thanks all !
I contacted the author who updated his repo. So current version works out of the box, thanks all !
I have stm32F103c8t6 blue chineese board and flashed it with stm32duino.
Then, I’ve downloaded that library ozolive wrote:from Mark Ruys at http://www.github.com/markruys/arduino-DHT
I could not use pin number “PC13”, because it is not uint_8 type.
