As the title says... Chat on...

User avatar
By ReinholdHiller
#16462 Hi again.

I have a pressure sensor (something roughly compatible to the HCEB005xU3) and want to get the data from it. If I wire it up stand alone and pull the SS/CS to low I can see it spitting out some clock and data pulses with about 25kHz. According to the specification it shall be 3 bytes... looks good to me.

I try to grab these data with SPI and implemented the following:

Code: Select all-- MTDI GPIO12 MISO (DIN)
-- MTCK GPIO13 MOSI (DOUT)
-- MTMS GPIO14 CLOCK
-- MTDO GPIO15 CS / SS

-- GPIO15: Chip Select
pincs = 8
-- GPIO14: Clock
pinclk = 5
-- GPIO13: Data
pindataout = 7
-- GPIO12: Data
pindatain = 6

-- set pin modes
gpio.mode(pincs, gpio.OUTPUT)
gpio.mode(pinclk, gpio.INPUT)
gpio.mode(pindatain, gpio.INPUT)

spi.setup(1, spi.SLAVE, spi.CPOL_LOW, spi.CPHA_LOW, spi.DATABITS_8, 0);

gpio.write(pincs, 0)

-- 5 Sekunden warten
for i=1,5,1 do
  tmr.delay(1000000)
end 

read = spi.recv(1, 3)
print(read)
for i=1,3,1 do
  print(string.byte(read,i))
end

gpio.write(pincs, 0)
tmr.delay(1000000)

print("done");


It simply does not work. I checked the wiring, looks good (MOSI of sensor to MISO of ESP..., Clock to Clock and CS), poking around shows that it should work...

In my despair I tried to read it via a interrupt routine. It works but not very well, LUA seems to be to slow for that speed.

Any ideas?