2012-12-28 11:38 PM
Could not find a ready solution for using 1-wire protocol with STM32 in C (working wiwth IAR), so I decided to rework the C++ library that came with arduino.
So, if anyone needs it - here it is a fully working solution (compiled wit IAR, tested on STM32F103VET6 processor running at 72 Mhz - Delay functions need to be modified for other frequencies). I have not yet add comments to functions in code, but it should not be hard to understand, as it is 1:1 ported from arduino library. Sample code:OWire OneWire;
unsigned char DeviceAddress[8];
int nCount = 0;
OWInit(&OneWire, GPIOB, GPIO_Pin_14);
while(OWSearch(&OneWire, DeviceAddress))
{
printf(''Device %d: %02X %02X %02X %02X %02X %02X %02X %02X \n\r'',
nCount+1,
DeviceAddress[7],DeviceAddress[6],
DeviceAddress[5],DeviceAddress[4],
DeviceAddress[3],DeviceAddress[2],
DeviceAddress[1],DeviceAddress[0]);
nCount++;
}
printf(''DeviceCount: %d'',nCount);
Output:
May be someone finds the Delay library useful too.
Working on DallasTemp library now - will post here when finished..
Any comments, suggestions are welcome...
#1wire #delay #1-wire
2013-01-03 07:00 AM
''rework the C++ library that came with arduino''
I guess it's a result of this that the code contains variable declarations intermixed with executable statements - which is allowed in C++, but not in so-called ''ANSI'' C. Therefore compiling this code will require C++/C99, or some option to ''allow C++ extensions'' - or a bit of reorganisation to move all the delcarations before the code...http://stackoverflow.com/questions/2896177/mixed-declarations-and-codes
If no-one else beats me to it, I'll post an update sometime...2013-12-31 06:17 AM
Why is there no lightbulb icon to ''like'' this contribution??
2016-09-06 08:09 AM
Hello,
Hello, I am using STM32F0 microcontroller and currently implementing DS18S20 using one wire protocol. I am searching for delay and one wire library but not able to find, I have made my own delay library using Systick timer but it is not making precise delay in microseconds? Help in this regard would be highly appreciated.2016-09-06 08:42 AM
Hi,
Maybe thishttp://stm32f4-discovery.net/2015/07/hal-library-05-onewire-for-stm32fxxx/
is helpful for you.Regards2016-09-06 09:27 AM
For micro-second delays on the CM0 I'd recommend using a TIM configured in a free-running mode, and pacing bus transitions with spin-loops against that.
The micro-controller isn't going to be able to interrupt at 1 MHz, so those types of software counters used by SysTick, etc, are not viable.On STM32 M3/M4 designs there is also the DWT_CYCCNT often providing nano-second level resolutions.2017-01-27 10:40 PM
can connect two micro stm32f103xxxx whit this protocol ?
have a sample fore this ?
thanks
2017-01-28 05:07 AM
Not sure this is an efficient way. Wouldn't it be far easier to use a USART and let the peripheral hardware do all the work rather than doing it a bit at a time managing the timing?
2017-02-03 03:29 AM
my usart pin used ...
2017-02-03 04:41 AM
Two suggestions:
1. Use I2c to 1-wire adapter: DS2482
https://www.maximintegrated.com/en/products/interface/controllers-expanders/DS2482-100.html
This way you can i2c library for easy handling of 1-wire
2. My favorite solution: connect the 1-wire device to the uart as per maxim app note:
https://www.maximintegrated.com/en/app-notes/index.mvp/id/214
This way you can access the 1-wire device the same as you use the uart.
Here is the project in Russion:
http://we.easyelectronics.ru/STM32/stm32-1-wire-dma.html
I made a few project using UART for the purpose of handling 1-wire thermometer e.g. DS18B20
Bogdan