Here is my code, please tell me where I make mistakes?
I try to write value 0x25 into register 0x24, and then read that value from that register and "print" it.
pin_sda = 15
pin_clk = 19
pin_miso = 25
pin_mosi = 23
_master = spi.master(spi.HSPI, {
sclk = pin_clk,
mosi = pin_mosi,
miso = pin_miso
}, 0)
_device = _master:device({
cs = pin_sda,
mode = 0,
freq = 5000000,
halfduplex = true
})
function write(address, value)
local _addr = bit.band(bit.lshift(address,1), 0x7E)
_device:transfer(string.char(_addr))
_device:transfer(string.char(value))
end
function read(address)
local _addr = bit.bor(bit.band(bit.lshift(address, 1), 0x7E), 0x80)
_device:transfer(string.char(_addr))
return _device:transfer(string.char(0xFF)):byte(1)
end
write(0x24, 0x25)
print( read(0x24) )
--------------------------------------------
E D I T
I find solution in meanwhile. It just need to be:
halfduplex = false
and everything works nice!
--------------------------------------------