stm32f103rb_hal_ds18b20

Index Commits Files Refs README
commit ea3046037a1cd4f03c74f7f1ded0d61c55a3a7ac
parent 743fe0c5e8cf9473e12ed94a9d64c78070f99ec7
Author: Martin Kloeckner <mjkloeckner@gmail.com>
Date:   Sun, 15 Mar 2026 22:12:14 -0300

add `DS18B20_SetResolution` function

Diffstat:
Mapp/src/ds18b20.c | 28++++++++++++++++++++++++++++
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/app/src/ds18b20.c b/app/src/ds18b20.c
@@ -55,12 +55,40 @@ uint8_t DS18B20_Reset(void)
     return 0;
 }
 
+void DS18B20_SetResolution(uint8_t resolution)
+{
+    uint8_t config;
+
+    switch(resolution)
+    {
+        case 9:  config = 0x1F; break;
+        case 10: config = 0x3F; break;
+        case 11: config = 0x5F; break;
+        case 12: config = 0x7F; break;
+        default: config = 0x7F;
+    }
+
+    DS18B20_Reset();
+    DS18B20_Write(0xCC); // send 'Skip ROM' command
+    DS18B20_Write(0x4E); // send 'write scratchpad' command
+
+    DS18B20_Write(0x00); // TH
+    DS18B20_Write(0x00); // TL
+    DS18B20_Write(config);
+
+    DS18B20_Reset();
+
+    DS18B20_Write(0xCC);   // Skip ROM
+    DS18B20_Write(0x48);   // Write scratchpad to EEPROM
+}
+
 void DS18B20_Init(void)
 {
     if (DS18B20_Reset() == 0)
     {
         LOGGER_INFO("Temperature sensor initialized successfully");
     }
+    DS18B20_SetResolution(10);
 }
 
 void DS18B20_Write(uint8_t data)