From db49b6007c63b3af397f276540528f0d0f13991b Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Mon, 15 Jul 2019 00:16:09 +0200 Subject: [PATCH] Aircon: DS magic... --- aircon/config.h | 2 +- aircon/main.c | 1 + lib/ds18b20.c | 8 ++++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/aircon/config.h b/aircon/config.h index a73fe50..2a577a3 100644 --- a/aircon/config.h +++ b/aircon/config.h @@ -42,4 +42,4 @@ #define DS_NUM_SENSORS 8 #define DS_DEBUG -#define DS_DEBUG2 +#undef DS_DEBUG2 diff --git a/aircon/main.c b/aircon/main.c index db09ae1..6bb3528 100644 --- a/aircon/main.c +++ b/aircon/main.c @@ -186,6 +186,7 @@ int main(void) delay_ms(50); modbus_loop(); + ds_step(); } #if 0 diff --git a/lib/ds18b20.c b/lib/ds18b20.c index 8f6b550..30ad08e 100644 --- a/lib/ds18b20.c +++ b/lib/ds18b20.c @@ -73,8 +73,16 @@ static bool ds_reset(void) // Set timer period to the length of the whole transaction (1 ms) timer_set_period(DS_TIMER, 999); + // XXX: We do not know why this is needed... + static bool once; + if (!once) { + for (int i=0; i<10000; i++) __asm__ volatile ("nop"); + once = 1; + } + // Pull line down and start timer cm_disable_interrupts(); + timer_generate_event(DS_TIMER, TIM_EGR_UG); timer_enable_counter(DS_TIMER); timer_set_oc_mode(DS_TIMER, TIM_OC2, TIM_OCM_INACTIVE); cm_enable_interrupts(); -- 2.39.2