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

1 Like

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