2024-10-10 08:24 AM - last edited on 2024-10-10 08:43 AM by Andrew Neil
2024-10-10 08:22 AM
Hi, where can I find a working One-Wire protocol? Is there an example provided by STM? I wrote code for a program to detect the temperature from a DS18B20 sensor, but I can’t detect the sensor, even though the debug shows everything is fine. Can someone help me? Thanks
2024-10-10 08:40 AM - edited 2024-10-10 08:40 AM
@Emanuele78 wrote:where can I find a working One-Wire protocol?
From the manufacturer:
See also:
Useful background info:
https://www.analog.com/en/resources/technical-articles/advanced-1-wire-network-driver.html
There are also UART-to-1-Wire and I2C-to-1-Wire hardware bridge chips.
@Emanuele78 wrote:even though the debug shows everything is fine.
What "debug" is that?
Did you look at the 1-Wire line with an oscilloscope to see what was actually happening?
A useful feature of 1-Wire is that the timing between "Slots" (ie, bits) is non-critical - so you can step your code one complete Slot at a time ...
#1Wire
2024-10-10 08:58 AM - last edited on 2024-10-11 12:49 AM by SofLit
Thanks, I will try to compare the links with my code.
Unfortunately, I don't have an oscilloscope, but if necessary, I will make sure to get one
I performed a debug with CUBEIDE using F6, placing breakpoints to check if the microcontroller detects the sensor, but it never finds it. The quantity variable in the following code is always zero.
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
DS18B20_ReadAll();
HAL_GPIO_WritePin(Test_GPIO_Port, Test_Pin, 1);
DS18B20_StartAll();
HAL_GPIO_WritePin(Test_GPIO_Port, Test_Pin, 0);
uint8_t ROM_tmp[8];
uint8_t i;
int quantity = DS18B20_Quantity(); // quantity always = 0
2024-10-10 09:04 AM
Please see the Posting Tips for how to properly post source code:
@Emanuele78 wrote:I performed a debug with CUBEIDE using F6, placing breakpoints to check if the microcontroller detects the sensor, but it never finds it. T= 0
Getting the correct timing on the wire is critical to 1-Wire operation - the CubeIDE debugger will not tell you anything about that.
It's also essential that your external hardware is correct - again, the CubeIDE debugger will not tell you anything about that.
This is why an oscilloscope is an essential tool for embedded firmware development: you need to be able to see what's happening in the real world of the hardware - not just the software.
2024-10-10 09:31 AM
2024-10-10 11:11 PM
2024-10-11 03:13 AM
Please post a schematic
2024-10-11 07:37 AM