1-Wire tester, shows ROM code and temperature on an LCD screen

onewire.h 1.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #pragma once
  2. //
  3. // Utils for Dallas OneWire bus (DS1820 etc)
  4. //
  5. #include <stdint.h>
  6. #include <stdbool.h>
  7. #define SKIP_ROM 0xCC
  8. #define CONVERT_T 0x44
  9. #define READ_SCRATCHPAD 0xBE
  10. /** Perform bus reset. Returns true if any device is connected */
  11. bool ow_reset(uint8_t pin);
  12. /** Send a single byte */
  13. void ow_write(const uint8_t pin, const uint8_t byte);
  14. /** Read a single byte */
  15. uint8_t ow_read(uint8_t pin);
  16. /** Wait until the device is ready. Returns false on timeout */
  17. bool ow_wait_ready(uint8_t pin);
  18. /** Read bytes into an array */
  19. void ow_read_arr(uint8_t pin, uint8_t* array, uint8_t count);
  20. /** Compute a CRC16 checksum */
  21. uint16_t crc16(uint8_t *data, uint8_t len);
  22. /** Compute a CRC8 checksum */
  23. uint8_t crc8(uint8_t *addr, uint8_t len);
  24. // --- utils for DS1820 ---
  25. #define TEMP_ERROR (-32768)
  26. /**
  27. * Read temperature in 0.0625°C, or TEMP_ERROR on error
  28. * Use this where you'd normally use READ_SCRATCHPAD
  29. */
  30. int16_t ds18s20_read_temp(uint8_t pin);
  31. /**
  32. * Read temperature in 0.1°C, or TEMP_ERROR on error
  33. * Use this where you'd normally use READ_SCRATCHPAD
  34. */
  35. int16_t ds18s20_read_temp_c(uint8_t pin);
  36. int16_t ds18b20_read_temp_c(uint8_t pin);
  37. /**
  38. * Perform a temperature measurement with single DS1820 device on the line
  39. * Can be followed by a call to read temperature (READ_SCRATCHPAD).
  40. *
  41. * Returns false on failure (device not connected)
  42. */
  43. bool ds18x20_single_measure(uint8_t pin);