1-Wire over UART

Today’s application mostly use somekind of operating system on microcontroller. Since these apps are not really real time anymore, keeping standard 1-Wire protocol developed with delays in software may make programmer’s life much harder and annoying.

UART and 1-Wire protocols have 2 things in common:

  • To reset 1-Wire network, we can use 9600 bauds on UART
  • To read/write 1-Wire bit, we can use 115200 bauds on UART

Detailed timings for the UART reset sequence, write/read bit can be found on official Maxim’s website.

Here I will try to focus on advantages and disadvantages when using UART and 1-Wire.

Advantages

  • UART hardware takes care of timing characteristics. We just need to transmit byte and read it back, then check the value
  • Since UART HW controls time, we can offload CPU to do other tasks
  • Most of new-age MCUs have DMA implemented which makes it easy to implement inside operating systems
  • Makes it easy for low-power apps, where CPU can sleep while HW is transmitting/receiving data

Disadvantages

Every solution has disadvantages and it is the same in this case:

  • Small MCUs have only 1 UART interface which is normally used for debugging or other more important peripherals
  • UART must support open-drain TX pin mode. In case this is not supported, we need external circuit to translate push-pull signal to open-drain with pull-up (this is not limitation for STM32)
  • We need to short-circuit TX and RX pins on UART and we need 1 pin more in final application

 

Library

Library consists of 1-Wire protocol, system functions for OS (mutex) and low-level functions for UART implementation. In the future I will implement DS18B20 library based on this lib and CRC will be added to make sure we have valid data when reading/writing data over 1-Wire.

To review/download/use of library, please follow the links below:

Github repository

API documentation

Project website

tilz0R

Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...

Read before commenting!

Before you make a new comment, make sure you agree with things listed below:

  • - Read post to make sure if it is already posted what you are asking for,
  • - Make sure you have the latest version of libraries used in your project,
  • - Make a clean and grammatically correct written message,
  • - Report as many details as possible, including what have you done so far,
  • - Do NOT post any code here. Use Pastebin,
  • - Do NOT post any error codes here. Use Pastebin,
  • - Specify STM32Fxxx family and used Discovery/EVAL/Nucleo or custom made board,
  • - Make sure your clock is set correct for PLL,
  • - If you are using my HAL drivers, please check this post how to start.
Comment will be deleted on breaking these rules without notification!