Skip to content

Releases: FilipImre/OneWire

Read_UID() and FindAllDevices() implemented; Examples updated with all ROM commands

11 Mar 23:40

Choose a tag to compare

Library functions

  • void OneWireSetup();
  • uint8_t OneWire_Init();
  • void OneWire_WriteByte();
  • uint8_t OneWire_ReadByte();
  • void OneWire_Read_UID();
  • void OneWire_FindAllDevices();

Don't forget to

  1. Include 'OneWire.h' in 'main.c'
  2. Configure your GPIO pin in CubeMX as GPIO_OUTPUT in PUSH-PULL mode, without PULL-UP (more stable to use external resistor)
  3. Setup the library with 'OneWireSetup(GPIOX, GPIO_PIN_X, X);' using your PORT and PIN. For example: For PB10 pin use 'OneWireSetup(GPIOB, GPIO_PIN_10, 10);'
  4. Initialize the BUS before read/write. Then write the ROM-COMMAND. The correct order is:
    • WRITE: OneWire_Init(); OneWire_WriteByte(ROM_CMD); OneWire_WriteByte(YOUR_BYTE);
    • READ: OneWire_Init(); OneWire_WriteByte(ROM_CMD); OneWire_WriteByte(READ_SCRATCHPAD_CMD); uint8_t myByte = OneWire_ReadByte();

Note

If you read all bytes 0xFF (255) your device (slave) has been disconnected or/and the bus has been failed.
To detect that the slave device is even 'hearing' stm32, I have modified the OneWire_Init(); function to validate the slave device presence pulse. If the function detects a valid slave presence pulse pattern it return 1 otherwise 0

By the next release I'm planning to

  • Implement software interlocks when the library is reading or writing on the bus to achieve code compatibility when using interrupts
  • Implement advanced communication validation and error detection methods with implementing a CRC-8 validator function

Issues solved

  • Bit read/write timing optimized. A complete temperature reading with 2 bytes costs ~2.5 msec
  • ROM-commands definitions added to 'OneWire.h' for all ROM-commands
  • Added device UID reading and all device UID discovering functionalities
  • Updated examples in 'main.c' to contain an example for all ROM-commands and Temperature calculation
  • Implemented slave device presence detection in 'OneWire_Init()' to return 1 on valid slave presence detected, 0 if not

First stable version of OneWire bit-banging library on STM32F103C8T6

09 Mar 14:13
b9e1621

Choose a tag to compare

Currently

This version holds a working bit-banging implementation of the library. Currently the library is relying on software-generated micro-second generating mechanism being vulnerable to custom interrupts. The current version is recommended to be used for stand-alone DS18B20 or any other OneWire sensor/actuator measurement program only. It is recommended to avoid using interrupts/time blocking mechanisms. The "OneWire_Init", "OneWire_WriteByte" and "OneWire_ReadByte" functions should be executed atomically, otherwise it ruins bit timing.

Public functions

  • *void OneWireSetup(GPIO_TypeDef port, uint16_t pinMask, uint8_t pin); Must be called just before the "while(1)" loop
  • uint8_t OneWire_Init(void); Must be called before each write
  • void OneWire_WriteByte(uint8_t data); Please ensure that before any writing/reading you initialized and addressed the slave device
  • uint8_t OneWire_ReadByte(void); Please ensure you have written the READ-REQUEST command (0xBE) before reading

Examples

  • A typical write sequence to a OneWire slave device
    OneWire_Init();
    OneWire_WriteByte(0xCC); // Skip ROM (ROM-CMD)
    OneWire_WriteByte(0x44); // Measure Temp
  • A typical read sequence from a OneWire slave device
    OneWire_Init();
    OneWire_WriteByte(0xCC); // Skip ROM (ROM-CMD)
    OneWire_WriteByte(0xBE); // Read Scratchpad (F-CMD)
    uint8_t Recvd = OneWire_ReadByte();

By next release I'm committed to solve the following issues:

  • Implement locking mechanisms to avoid interference with interrupts
  • Builtin PRESENCE-BIT detection and CRC verification for error-detection
  • Examples for all ROM commands, including the automatized search of all OneWire devices and retreiving their UID