Page 4 of the DATA SHEET describes the process. First DT must be read LOW when SCK is LOW to know the ADC is ready to be read. I cannot seem to read DT as anything but HIGH, signifying that the ADC is not ready, and when I attempt to toggle SCK HIGH and LOW DT remains HIGH according to output in LUA. I have the ADC powered by 5v and the data lines bi-directional logic shifted between 5v and 3.3.
Here's a code snippet:
DT = 3
SCK = 4
gpio.mode(DT, gpio.INPUT)
gpio.mode(SCK, gpio.OUTPUT)
out = "" -- 24 bit word
while gpio.read(DT) == 1 do end -- wait until DT goes LOW and ADC is ready to be read
for i=1,24 do
gpio.write(SCK, gpio.HIGH)
out = out .. gpio.read(DT)
gpio.write(SCK, gpio.LOW)
end
print(tonumber(out, 2))
Basically DT is always HIGH so the while loop never terminates and the MCU reboots.
Is there something wrong with the speed of LUA when trying to read/toggle these data lines? I hope this makes sense, as I have only recenctly started working in this framework. I appreciate any feedback/advice regarding this situation or bit banging with NodeMCU in general.
Thanks!