For st-conect
Fork of DS1820 by
Diff: DS1820.cpp
- Revision:
- 16:178194eadd46
- Parent:
- 15:236eb8f8e73a
--- a/DS1820.cpp Sat Mar 11 20:35:59 2017 +0000 +++ b/DS1820.cpp Mon Oct 15 07:35:26 2018 +0000 @@ -1,37 +1,11 @@ #include "DS1820.h" -#ifdef TARGET_STM -//STM targets use opendrain mode since their switching between input and output is slow - #define ONEWIRE_INPUT(pin) pin->write(1) - #define ONEWIRE_OUTPUT(pin) - #define ONEWIRE_INIT(pin) pin->output(); pin->mode(OpenDrain) -#else - #define ONEWIRE_INPUT(pin) pin->input() - #define ONEWIRE_OUTPUT(pin) pin->output() - #define ONEWIRE_INIT(pin) -#endif +#define ONEWIRE_INPUT(pin) pin->input() +#define ONEWIRE_OUTPUT(pin) pin->output() +#define ONEWIRE_INIT(pin) -#ifdef TARGET_NORDIC -//NORDIC targets (NRF) use software delays since their ticker uses a 32kHz clock - static uint32_t loops_per_us = 0; - - #define INIT_DELAY init_soft_delay() - #define ONEWIRE_DELAY_US(value) for(int cnt = 0; cnt < (value * loops_per_us) >> 5; cnt++) {__NOP(); __NOP(); __NOP();} - -void init_soft_delay( void ) { - if (loops_per_us == 0) { - loops_per_us = 1; - Timer timey; - timey.start(); - ONEWIRE_DELAY_US(320000); - timey.stop(); - loops_per_us = (320000 + timey.read_us() / 2) / timey.read_us(); - } -} -#else - #define INIT_DELAY - #define ONEWIRE_DELAY_US(value) wait_us(value) -#endif +#define INIT_DELAY +#define ONEWIRE_DELAY_US(value) wait_us(value) LinkedList<node> DS1820::probes; @@ -390,9 +364,11 @@ float answer, remaining_count, count_per_degree; int reading; read_RAM(); - if (RAM_checksum_error()) + if (RAM_checksum_error()) { // Indicate we got a CRC error + printf("checksum error\r\n"); answer = invalid_conversion; + } else { reading = (RAM[1] << 8) + RAM[0]; if (reading & 0x8000) { // negative degrees C @@ -424,5 +400,3 @@ onewire_byte_out(0xB4); // Read power supply command return onewire_bit_in(&this->_datapin); } - -