From 93329d7a663117d31f8d983b67b101b858008638 Mon Sep 17 00:00:00 2001 From: "Eugeniy E. Mikhailov" Date: Wed, 18 Dec 2019 11:34:31 -0500 Subject: get rid of timers, pin toggling is slow enough --- microwire.lua | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'microwire.lua') diff --git a/microwire.lua b/microwire.lua index d50b395..c6d97e8 100644 --- a/microwire.lua +++ b/microwire.lua @@ -41,24 +41,18 @@ function microwire_send_data( data ) -- essentially send data via spi interface -- and raise Load Enable pin for a bit (at least for 25 nS) at the end of transmission - -- first low LE pin + -- first low LE pin, it should be low but just to be sure gpio.write(microwire_LE_pin, gpio.LOW) -- second send the data local nBytes = spi.send(spiID, data) + -- finally raise LE pin for at least 25 ns, + -- note that it takes about 300 uS on ESP8266 before LE will be HIGH after spi.send gpio.write(microwire_LE_pin, gpio.HIGH) - -- but since optocoupler is limiting us we will do it for longer - local microwireLEonTime = 100; -- time is in uS - - -- the easiest to use tmr.delay( timeIn_uS ) but this halts everything - -- tmr.delay( microwireLEonTime ) - -- so we use timer but unfortunately the smallest time is 1ms - microwireLEonTime = 1; -- time is in mS for timers - microwire_tmr = tmr.create() - microwire_tmr:register(microwireLEonTime, tmr.ALARM_SINGLE, function() gpio.write(microwire_LE_pin, gpio.LOW) end) - microwire_tmr:start() + -- we immediately drop LE pin to low, Scope shows that the pin will be on for 80 uS + gpio.write(microwire_LE_pin, gpio.LOW) end microwire_setup_interface() -- cgit v1.2.3