diff options
author | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-06-02 10:01:33 -0400 |
---|---|---|
committer | Eugeniy E. Mikhailov <evgmik@gmail.com> | 2021-06-02 10:01:33 -0400 |
commit | 981413b1aee00dd143fdab08b4fa983f801d652e (patch) | |
tree | 0943042b3cf5ef6d2984cdc39e8c268a8b6352fd /microwire.lua | |
parent | 059f99917703078c94489b8fd023058f64e95cc7 (diff) | |
download | nodeMCU_rf_source_lmx2487-981413b1aee00dd143fdab08b4fa983f801d652e.tar.gz nodeMCU_rf_source_lmx2487-981413b1aee00dd143fdab08b4fa983f801d652e.zip |
more files written with Charris
Diffstat (limited to 'microwire.lua')
-rw-r--r-- | microwire.lua | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/microwire.lua b/microwire.lua index d6c1ff4..ef64a2f 100644 --- a/microwire.lua +++ b/microwire.lua @@ -1,3 +1,8 @@ + --[[ +Eugeniy Mikhailov +1 June 2021 +(copied over from past work) ]] + -- functions to write registers over microwire interface -- it resembles SPI but need extra pin which sends Load Enable (LE) pulse -- otherwise SPI sequence is sent into 24 bit FIFO latch register on chip @@ -8,7 +13,11 @@ microwire_spiID = 1; -- ID=1 --> HSPI in nodemcu language microwire_databits=24; -- LMX2487 loads 24 bits sequence per write into a register -- lmx2487 can handle up to 20 MHz speed (50 nS per clock) but optocoupler is good for 240kHz -- so let's aim for 100 kHz -microwire_interface_speed = 100000; -- in Hz +-- value of 1000 Hz is too slow and does not engage the spi clock +-- values of 10 kHz is not sensed by lmx2487 chip +-- 100 kHz is shown to work reliably +-- 1 MHz works too +microwire_interface_speed = 1000000; -- in Hz -- we will use SPI ChipSelect pin for LoadEnable pin microwire_LE_pin = 8; -- microwire Load Enable pin. 8 --> GPIO15 @@ -28,7 +37,7 @@ function microwire_setup_interface () -- HSPI /CS | 8 | GPIO15 -- HSPI MOSI | 7 | GPIO13 -- HSPI MISO | 6 | GPIO12 - + -- Load Enable pin settings -- note that it overwrite unused ChipSelect if pin=8, i.e. GPIO15 gpio.mode(microwire_LE_pin, gpio.OUTPUT) @@ -39,14 +48,14 @@ end 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, it should be low but just to be sure gpio.write(microwire_LE_pin, gpio.LOW) -- second send the data local nBytes = spi.send(microwire_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 -- Note manual toggle like below is quite slow, the shortest duration is 160 uS @@ -55,4 +64,3 @@ function microwire_send_data( data ) end microwire_setup_interface() - |