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

User avatar
By Dam747
#52536 Hello guys,
I am writing a small lua script to test the SPI of nodemcu. I have shorted the MOSI and MISO pins of nodemcu to go for a self loop test.
I tested the clk, ss and mosi signals on the oscilloscope and they seem to be good.
But, I am getting problem in receiving the data when I do loop test.
I am have used following lua script for this:

spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8,8, spi.FULLDUPLEX);
s= {spi.send(1,0,0x05, 0x40,0x33, 0x54)}
read = spi.recv(1,1)
= s[1]
= s[2]

print(string.byte(read))


The output of this;
s[1] as 5 because 5 bytes were sent.
But I constantly receive 255 from spi.recv, no matter how many bytes i send, i still receive the read value as 255.
after writing this script, I use Send to ESP to view the outputs.
Can someone suggest where I am going wrong ?
Am I missing something ?
Any help will be appreciated
Thanks a lot
User avatar
By Dam747
#52594 I would like to attach the waveforms of Slave select and sclock.
The yellow line in the waveform is slave select and the blue line is the clock.
It can be clearly seen that slave select goes low, and at that time 8 clock pulses are seen which are meant for transferring data of 8 bits.
It seems the clock, slave select, MOSI graphs are seen properly, but not receiving back the data in loop test.
It would be very great if someone can suggest or help on this.
Thanks
Attachments
13925724_1055648997804577_2373269109809029730_o.jpg
13923613_1055648947804582_93780295809393877_o.jpg
User avatar
By devsaurus
#52706 spi.send() and spi.recv() each execute an SPI transaction on their own.
When you look at the output of spi.read() you see the 255 because this command will always send 0xff via MOSI.

The output of spi.send() should provide what you're looking for: What's in s[2], s[3], ...?

Also see the API variant for full-duplex mode: http://nodemcu.readthedocs.io/en/latest ... i/#spisend
User avatar
By Dam747
#52712
devsaurus wrote:spi.send() and spi.recv() each execute an SPI transaction on their own.
When you look at the output of spi.read() you see the 255 because this command will always send 0xff via MOSI.

The output of spi.send() should provide what you're looking for: What's in s[2], s[3], ...?

Also see the API variant for full-duplex mode: http://nodemcu.readthedocs.io/en/latest ... i/#spisend


Hi,
Thanks for replying.
s[2] and s[3] are coming as NIL.
The API for data transmission using full duplex mode is :
wrote[, rdata1[, ..., rdatan]] = spi.send(id, data1[, data2[, ..., datan]])
but I dont understand how to exactly use it.
is it like this for sending and receiving two bytes of data ?
wrote[rdata1, rdata2] = spi.send(1, 0x12, 0x13)

Thanks for the help.