4-wire SPI Interface
I have a device that uses a 4-wire SPI Interface. I'd like to be able to communicate with this device using the Propeller chip. Is there any object that is already written that can do this? I looked through the object list under the section titled "Protocol: SPI, 1-wire, 12C, asynchronous serial..." and although it mentions SPI in the title I wasn't able to find any objects that actually provide any SPI interface communications. Is one available?
·
·
Comments
As for the setup, I'm actually learning SPI, myself. I know the Propeller CAN do it - how is another story.
So, anyone know where I can get an object to handle that protocol?
I bet you could write simple SPI send/receive for your device in SPIN. Try it. We will watch and help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
A bit of work the first time, but once you do one the next one is easier by far. The propeller can easily handle your device (took a quick peek at the data sheet).
Not the answer you were hoping for I know, but that is SPI.
-tellurian
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com
Con
_clkmode = xtal1 + pll16x
_xinfreq = 5_000_000
cs = 2
clk = 1
reset = 0
Dout = 3
Din = 4
var
byte v ,r,v2,v3
word reg, data, receive,what
obj
bs2 : "BS2_Functions"
Pub Start
'dira[noparse][[/noparse]cs]~ set pin to input
dira[noparse][[/noparse]cs]~~ 'set chip select to out
dira[noparse][[/noparse]clk]~~ 'set chip select to out
dira[noparse][[/noparse]dout]~ 'set dout to input
dira[noparse][[/noparse]Din]~~ 'SET to din output
BS2.Start(31,30)
BS2.Debug_Str(string("Begining Program",13))
repeat
BS2.Debug_Str(string("enter register address then hit enter : ",13)) 'get the register address to query from the user
data := BS2.DEBUGIN_DEC 'get address to send to accel.
'now construct message to send to accelerometer
data := data << 8 'shift the address to the correct byte before sending
write_accel(data)
display(data,1) ' 1= sending data
waitcnt(clkfreq/10 + cnt)
receive := read_accel(data)
display(receive,2)
convert_2_g(recieve,2) 'for now just do 2's complement data
pub write_accel(send_data)
outa[noparse][[/noparse]cs]~~ 'set pin to high
outa[noparse][[/noparse]cs]~ 'set pin to low
outa[noparse][[/noparse]clk]~ 'set clk to low
bs2.pulsout_uS(clk, 210)
bs2.shiftout(Din, CLK, send_data, BS2#MSBFIRST,16) 'most significant bits first
pub read_accel(send_data) : results
outa[noparse][[/noparse]cs]~~ 'set pin to high
outa[noparse][[/noparse]cs]~ 'set pin to low
outa[noparse][[/noparse]clk]~ 'set clk to loW
bs2.pulsout_uS(clk, 210)
results := bs2.shiftin(Dout, clk, BS2#MSBpost,16) 'most significant bits first
{{ PUB SHIFTIN (Dpin, Cpin, Mode, Bits) : Value | InBit
Shift data in, master clock, for mode use BS2#MSBPRE, #MSBPOST, #LSBPRE, #LSBPOST
Clock rate is ~16Kbps. Use at 80MHz only is recommended.
X := BS2.SHIFTIN(5,6,BS2#MSBPOST,8)
PUB PULSOUT_uS(Pin,Duration) | ClkCycles
Produces an opposite pulse on the pin for the duration in 1uS increments
Smallest value is 10 at clkfreq = 80Mhz
Largest value is around 50 seconds at 80Mhz.
BS2.Pulsout_uS(500) ' 0.5 mS pulse
PUB SHIFTOUT (Dpin, Cpin, Value, Mode, Bits)| bitNum
Shift data out, master clock, for mode use ObjName#LSBFIRST, #MSBFIRST
Clock rate is ~16Kbps. Use at 80MHz only is recommended.
BS2.SHIFTOUT(5,6,"B",BS2#LSBFIRST,8)
}}
pub display(value,in_out)
If in_out == 1
bs2.debug_str(string("sending : "))
bs2.debug_bin(value,16)
elseif in_out == 2
bs2.debug_str(string("receiving bin : "))
bs2.debug_bin(value,16)
bs2.debug_str(string("receiving dec : "))
bs2.debug_str(string("dec : "))
bs2.debug_dec(value)
else
bs2.debug_str(string("receiving new data : "))
bs2.debug_bin(value,16)
bs2.debug_str(string("receiving alarm : "))
bs2.debug_bin(value,16)
Attached is an I2C object written by Joe Lucia: http://irobotcreate.googlepages.com/home
Regards,
TCIII
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
If you are going to send·a Robot·to save the world, you·better make sure it likes it the way it is!
If I find myself needing SPI for anything in the near future, I'll write it as a GP object and publish it.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"I have always wished that my computer would be as easy to use as my telephone.· My wish has come true.· I no longer know how to use my telephone."
- Bjarne Stroustrup
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Timothy D. Swieter, E.I.
www.brilldea.com - Prop Blade, LED Painter, RGB LEDs, 3.0" LCD Composite video display, eProto for SunSPOT
www.tdswieter.com