STM32 checking self-written delay function

Hello,
I am writing OneWire communication between STM32 and DS18B20. There should be applied precise delays in us, as I know, HAL guarantee only ms, so at this play timers came into play.

When I started an application, I saw that values on the oscilloscope not fully matched expected delays.

Is there anyway to ckeck if my delays in us countinng properly? I am using 8 MHz BluePill with 8-1 Prescaler.
 
The simplest and most foolproof one-wire setup is using a UART! That guarantees correct timing regardless of MCU clock speed.

Either:
Set the TX output to open collector, connect that and the RX input to the device and a pullup.
Or, connect RX to the bus feed the pullup from the TX pin.

Use 9600 Baud for initialisation, then 115200 for the bit transfers. Those gives appropriate pulse timing.

More info here:

 
In reality it is easier say than done, I have few STM32F103 boards, but all of them Chinease with not original controller. As you know, from some version Cube IDE doesn't flash them properly, I am doing it via hex file.
Additionally, debug feature also didn't work.
 
My last results is that I use this code, where delay_us is function for microseconds:
float DS18B20_GetTemp(void)
{
uint8_t temp_l, temp_h;
int16_t temp;

//if (!DS18B20_Start()) return -1000; // Error

//DS18B20_WriteByte(0xCC); // Skip ROM
//DS18B20_WriteByte(0x44); // Convert T
HAL_Delay(750); // Wait for conversion

DS18B20_Start();
DS18B20_WriteByte(0xCC); // Skip ROM
// DS18B20_WriteByte(0xBE); // Read Scratchpad

// temp_l = DS18B20_ReadByte();
// temp_h = DS18B20_ReadByte();

// temp = (temp_h << 8) | temp_l;
return (float)temp / 16.0;
}
615 us is reset pulse and 125 presence. This timing across the normal range as I expect:

But when we talk about writing bits, I got minimum 32us where I plan to have a <= 15us:

Up to now I didn't find any way to set it properly... I told with some DIY guys, they said that there is no way to expect from Proteus this accuracy
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…