diff --git a/sites/en/docs/Sensor/SeeedStudio_XIAO/SeeedStudio_XIAO_SAMD21/Seeeduino-XIAO.md b/sites/en/docs/Sensor/SeeedStudio_XIAO/SeeedStudio_XIAO_SAMD21/Seeeduino-XIAO.md index 3f76f956f8f79b..8e9cef051a8a96 100644 --- a/sites/en/docs/Sensor/SeeedStudio_XIAO/SeeedStudio_XIAO_SAMD21/Seeeduino-XIAO.md +++ b/sites/en/docs/Sensor/SeeedStudio_XIAO/SeeedStudio_XIAO_SAMD21/Seeeduino-XIAO.md @@ -355,6 +355,108 @@ void loop()

pir

+#### 1-Wire + +In this example Dallas/Maxim DS18B20 sensor connected to the line DA2. + +```cpp +#include + +#define OW_PIN 2 + +// Bus control +void ow_low() { pinMode(OW_PIN, OUTPUT); digitalWrite(OW_PIN, LOW); } +void ow_rel() { pinMode(OW_PIN, INPUT); } +int ow_rd() { return digitalRead(OW_PIN); } + +bool ow_reset() { + ow_low(); delayMicroseconds(480); + ow_rel(); delayMicroseconds(70); + bool p = !ow_rd(); + delayMicroseconds(410); + return p; +} + +void ow_write_bit(uint8_t b) { + ow_low(); delayMicroseconds(b ? 6 : 60); + ow_rel(); delayMicroseconds(b ? 64 : 10); +} + +uint8_t ow_read_bit() { + ow_low(); delayMicroseconds(6); + ow_rel(); delayMicroseconds(9); + uint8_t b = ow_rd(); + delayMicroseconds(55); + return b; +} + +void ow_write(uint8_t v) { for(int i=0;i<8;i++) ow_write_bit((v>>i)&1); } + +uint8_t ow_read_byte() { uint8_t v=0; for(int i=0;i<8;i++) v|=ow_read_bit()<>=1; if(m) crc^=0x8C; b>>=1; } + } + return crc; +} + +void print_hex(uint8_t *d, uint8_t len) { + for(int i=0;i