Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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:
1748438348607.png

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

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 :D
 

Latest threads

New Articles From Microcontroller Tips

Back
Top