Closed drahoslove closed 6 years ago
Hey, this looks great! I'll have a look through my parts drawer and see if I can find some device that require MISO.
Hi, have you managed to find something in your drawer? It would be great to merge this.
Hey man! Had some time to play with it tonight. Turns out that most of the devices I hoped were SPI was in fact I2C, however I was able to test:
I had a winbond 16M SPI flash laying around that I tried to use for a write/read test, but I was unable to get the chip to work. Hard to figure out why, possible reasons range from broken chip to maybe I didn't have proper contact on one of the pins (SOIC package in a clamp), or maybe I was using it wrong.
While I couldn't make the SPI flash work, maybe the loopback test + matrix is good enough to ship the code for now?
And maybe we can order up some cheap two way SPI devices from ebay, something that doesn't require tons of setup before you can finally start reading and writing some data.
Great you managed to test something :+1:. I think you can ship it and let potential users test the rest :wink:.
Can you adress the issue https://github.com/stianeikeland/go-rpio/issues/27 when you'll be creating new release?
Also since I'm the ~contributor~ collaborator now. Should I create future contributions in new branches of this repo rather than in my fork?
Hi, I implemented basic SPI functionality.
(I originally wanted to first start a discussion about API and implementation details first, but after writing long, long text in new issue form I accidentally hit back button and lost the text :man_facepalming:. So I decided to just implement it. But we can still run discussion here.)
Summary of what I have done:
(i will be referencing BCM2835-ARM-Peripherals.pdf)
Spi
. I was thinking about implementing it as it's own nested packagespi
, but it would be probably more complicatedAPI
setup/teardown
rpio.SpiBegin(rpio.Spi0)
has to be called first before using any Spi func. It will change pin modes toSpi
and initialize default setting.rpio.SpiEnd(rpio.Spi0)
should be called at the end, it will switch pin modes toInput
.transferring data
rpio.SpiTransmit(byte)
orrpio.SpiTransmit(bytes...)
will transmit byte or bytes to slave.rpio.SpiRecieve(n)
will return n bytes received from slave.rpio.SpiExchange(buffer)
will simultaneously transmit data from the buffer to slave and data from slave to the same buffer in full duplex way.settings
rpio.SpiSpeed(hz)
will set transmit speed of SPIrpio.SpiChipSelect(n)
will select chip/slave (ce0, ce1, or ce2) to which transferring will be donerpio.SpiChipSelectPolarity(n, pol)
set chip select polarity (low enabled is used by default which usually works most of the time)rpio.SpiMode(cpol, cpha)
set clock/communication mode (=combination of clock polarity and clock phase; cpol=0, cpha=0 is used by default which usually works most of the time)issues
I only have resources now to test MOSI transfer, but not MISO - only have a ouptup-only device. So if somebody with some "readable" slave SPI chip could test the recieving functionality, that would be great.