SPI Engine help
Jonathan
Posts: 1,023
Hi All,
I am trying to use the SPI Engine, with no sucess so far. I had been using Martin's BS2.Functions, and this snip works:
BS2.Shiftout(mosi,sclk,flag,BS2#MSBFIRST,8)
However, this one doesn't:
Any ideas what I am doing wrong here?
Thanks!
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
I am trying to use the SPI Engine, with no sucess so far. I had been using Martin's BS2.Functions, and this snip works:
BS2.Shiftout(mosi,sclk,flag,BS2#MSBFIRST,8)
However, this one doesn't:
CON #0,MSBPRE,LSBPRE,MSBPOST,LSBPOST 'Used for SHIFTIN routines #4,LSBFIRST,MSBFIRST flag = $AA OBJ spi : "SPI engine" PUB init SPI.start spi.shiftout(mosi,sclk,MSBFIRST,8,flag)
Any ideas what I am doing wrong here?
Thanks!
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
Comments
Try removing the line that reads...
SPI.start
...When you call 'spi.shiftout' the object will automatically start. To turn the cog off, set the bits to 0 and send a 'spi.shiftout' or call a 'spi.stop'
When I wrote this demo, I tested it with a 74HC595 and a 74HC165... for these two chips, the clock pulse runs VERY fast, and might be to fast for
other IC's to cope with. In which case a delay needs to be added to the code around the code that reads...
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.
Removing the spi.start did the trick. Shiftin is working fine without the delay, but good to know. So the shiftin routine does not sit and wait for a response like a BS2's serin command? How long do you have intil it hangs if that is the case?
Thanks for the help!
Jonathan
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
www.madlabs.info - Home of the Hydrogen Fuel Cell Robot
"...So the shiftin routine does not sit and wait for a response like a BS2's serin command?..."
The difference between SHIFTIN and SERIN is like apples and oranges. One is asynchronous communication (SHIFTIN) while the other is synchronous communication (SERIN). The SHIFTIN function provides a clock signal to the device sending the data. This clock signal instructs the device that is sending the data to increment to the next available bit. The SERIN function does not provide a clock signal to the device sending the data, but instead the clock signal is kept internal to both the device sending the data and the device receiving the data. In this case both clocks are synchronized by a precision time base that both devices are running on. With SERIN, there are usually 2 extra bits that are associated with the signal a START bit and a STOP bit. Although in some cases the STOP bit is not used, the START bit is used to set the correct framing position of the incoming data. With SERIN, there can also be a 3rd bit known as a·PARITY bit. For all practical purposes it is a crude form of a CRC (Cyclic Redundancy Check) to help minimize transmission errors but is very seldom used.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe
IC Layout Engineer
Parallax, Inc.