RAK3172 + DS18B20!

I connected the temperature sensor DS18B20.
My observations: delayMicroseconds() - does not work correctly.
pinMode(), digitalRead() - work very slowly.
I used the microDS18B20 library using HAL (changed the microOneWire.cpp file):
Temperature sensor connected to pin PB5

void pinModeOutput(){
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_PULLDOWN;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}

void pinModeInput(){
GPIO_InitTypeDef GPIO_InitStruct;
GPIO_InitStruct.Pin = GPIO_PIN_5;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_PULL_UP;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH;
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
}

void delayMicros(int m){
uint32_t d = 0;
while ( d < 9 * m) {
asm ("\t nop");
d++;
}
}

bool oneWire_reset(uint8_t pin) {
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
pinModeOutput();
delayMicros(600);
pinModeInput();
MOW_CLI();
delayMicros(60);
bool pulse = HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5) == GPIO_PIN_SET;
MOW_SEI();
delayMicros(600);
return !pulse;
}

void oneWire_write(uint8_t data, uint8_t pin) {
for (uint8_t i = 8; i; i–) {
pinModeOutput();
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
MOW_CLI();
if (data & 1) {
delayMicros(5);
pinModeInput();
delayMicros(60);
} else {
delayMicros(60);
pinModeInput();
delayMicros(5);
}
MOW_SEI();
data >>= 1;
}
}

uint8_t oneWire_read(uint8_t pin) {
uint8_t data = 0;
for (uint8_t i = 8; i; i–) {
data >>= 1;
MOW_CLI();
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_RESET);
pinModeOutput();
delayMicros(2);
pinModeInput();
delayMicros(8);
if (HAL_GPIO_ReadPin(GPIOB, GPIO_PIN_5) == GPIO_PIN_SET) data |= (1 << 7);
delayMicros(60);
MOW_SEI();
}
return data;
}

Welcome to RAK forum @ipssoft ,

It seems you are using a custom firmware with functions you created yourself. We cannot fully support you on this however your issue could be related on how you setup the RCC of STM32WL (if you think it is timing related).

One wire library for DS18B20 will be supported by RUI3 on the next firmware release btw. There is no definite time yet though.

Then my question is - how to set up RCC using Arduino + RUI?
So as not to go beyond the Arduino framework? Thank you.

Hi @ipssoft ,

Setting up the RCC internal is done internally by RUI3 on the default firmware of RAK3172. We do not encourage users to mixed low level HAL modifications with the abstractions created by RUI3 specially RCC.

If ever you decide you want to create your own firmware using STM32WL SDK, we can only provide the necessary radio source files to update since examples of the SDK is based on Nucleo STM32WL Dev Board. Other peripheral setup will be handled by the you or your SW engineer/s.

while(1){
digitalWrite(…, HIGH);
delay(1);
digitalWrite(…, LOW);
delay(1);
}

On the oscilloscope, I do not see what should be.
If you increase the delay to 5ms, then at the output I see PWM with a period of 10ms. It doesn’t work with a small delay. Therefore, I concluded that either delay() was not working correctly, or digitalWrite() was too slow.

Thanks for sharing your observation. Can you give me the RUI3 firmware you use on this test? Via AT+VER=?

Unfortunately, I do not have access to devices. I did a job for a local university, the devices work well (only two). But I used RAKwireless RUI STM32 Boards v 3.5.3 for Arduino IDE. I correctly understood that along with the sketch, RUI3 is also uploaded?

Hi Mr.Carlrowan, can you share with me about plan release packed support One-wire?

Hey! @carlrowan

Trying to read data from OneWire DS18B20 like on that example for ESP32 Guide for DS18B20 Temperature Sensor with Arduino | Random Nerd Tutorials

But it is do nothing :frowning:
It is possible to do anything please?

Thank you!

Can you please share some kind of working example how you made OneWire work with 3172 please?

Thanks a lot!

Take the library GitHub - GyverLibs/microDS18B20: Легкая и удобная в обращении библиотека для работы с 1-Wire термометрами DS18B20 and change it as I described in the first topic

2 Likes

Hi @ipssoft ,

Thank you for sharing this library. It works well!

Hi @Nam @Diaver ,

You can try the library shared by ippsoft. It is ok on my test. I only have 1 sensor though so t2 shows error.

1 Like

Hello Mr. @carlrowan , we can use library GitHub - GyverLibs/microDS18B20: Легкая и удобная в обращении библиотека для работы с 1-Wire термометрами DS18B20 without change anything?

I use pin PA12, so just need change WB_IO1 is PA12 right?
And need use resistor pull up or not?
Im try with pin PA11 and PA12 also, but not yet success.

Hi @Nam ,

I did quick test today to check this again.

WB_IO1 is working. It is not PA12. It is PB5.

PA11 and PA12 are I2C pins. I tried these pins but not working. Maybe the library has conflict on the I2C :man_shrugging:

Thanks to @ipssoft input, I changed the DS18B20 One Wire library to work with RAK3172 with any GPIO.
Tested with 2 sensors on 2 GPIO’s. Multiple sensors on 1 GPIO is not tested.

As this is a temporary solution (OneWire support is still on the task list of our R&D team), the library files are merged with the source codes in the project folder.

Example code is available in RUI3-Best-Practice - RUI3-RAK3172-OneWire

Test setup:

Log output:

RAKwireless RUI3 Node
------------------------------------------------------
Setup the device with WisToolBox or AT commands before using it
Version RUI3-OneWire-V1.0.0
------------------------------------------------------
[AT_CMD] Got flag: AA
[AT_CMD] Got send interval: 0000EA60
[AT_CMD] Send interval found 60000
+EVT:JOINED
[JOIN-CB] LoRaWan OTAA - joined! 

[SETUP] Sensor #1 ID: 0x28, 0xEE, 0xD2, 0x2B, 0x73, 0x23, 0xB, 0xA2
[SETUP] Sensor #2 ID: 0x28, 0x2E, 0x1B, 0x43, 0x73, 0x23, 0xB, 0x60
[SETUP] Confirmed disabled
[SETUP] Retry = 0
[SETUP] DR = 2
[SETUP] LINKCHECK = 0
Current Work Mode: LoRaWAN.
[UPLINK] Start
[UPLINK] DS18B20 sensor #1 31.25
[UPLINK] DS18B20 sensor #2 31.06
[UPLINK] Sending 12 bytes
0267013803670136017401A4
[UPLINK] LPW Packet enqueued
[TX-CB] TX status 0
[RX-CB] RX, port 0, DR 3, RSSI -37, SNR 10

+EVT:TX_DONE