-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
spi.send()/receive() send/receive one byte a time #1745
Comments
I confirm your observation but would propose a different solution: Why?
If you need SS/CS to span multiple bytes, then use the following approach: node.setcpufreq(node.CPU160MHZ)
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 80, spi.HALFDUPLEX)
-- disable HSPICS
gpio.mode(8, gpio.INPUT, gpio.PULLUP)
-- enable SS/CS pin as output
gpio.mode(ss_pin, gpio.OUTPUT, gpio.FLOAT)
gpio.write(ss_pin, gpio.LOW)
spi.send(1, {0x12, 0x34, 0x56, 0x78, 0x90})
spi.send(1, "abcdefg")
spi.recv(1, 4)
gpio.write(ss_pin, gpio.HIGH) |
Thanks for quick reply.
In fact, spi.transaction() works for me. But I need a string version of get_miso() and set_mosi() for performance. I thought |
Ah, I see. The two definitely focus on versatile usage regarding word/bit length and neglect performance aspects. Guess, that can be addressed. How about: spi.set_mosi()spi.set_mosi(id, offset, bitlen, data1[, data2[, ..., datan]])
spi.set_mosi(id, offset, string) With the restrictions that spi.get_miso()data1[, data2[, ..., datan]] = spi.get_miso(id, offset, bitlen, num)
string = spi.get_miso(id, offset, num) Same restrictions as above apply the variant returning a string. |
Great to have them. 8-bit is the most common case in real world. However, I still think it is more reasonable to keep HCS low during all bytes in send(). |
Ok, I'll look into the mosi/miso functions.
I'm not fully comfortable with this as a new requirement to |
Expected behavior
A spi.send() should enable HCS pin, send all bits and disable HCS.
spi.receive() should do the similar thing.
I can use transaction(), but converting between bytes/chars is a little slow for me...
Actual behavior
HCS is endabled/disabled for every byte.
Test code
NodeMCU version
NodeMCU custom build by frightanic.com
branch: master
commit: 81ec366
SSL: true
modules: adc,bit,cjson,crypto,encoder,file,gpio,i2c,net,node,ow,pcm,rtctime,spi,struct,tmr,wifi,tls
build built on: 2017-01-16 08:37
powered by Lua 5.1.4 on SDK 1.5.4.1(39cb9a32)
Hardware
NodeMCU DEVKIT V1.0
The text was updated successfully, but these errors were encountered: