What would be a good pause time? (Note that I am completely new to this)a
What would be a good pause time? (Note that I am completely new to this)a
To obtain clock speed:
Freq [Hz] = 1/period[seconds]
Test it with 1 ms (about 1Khz).
If it doesnt work try with another SPI mode, remember MSB first.
This is my code:
<code>
DEFINE OSC 20
DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_SPBRG 21 ' 57600 Bauds
DEFINE HSER_CLOERR 1
DEFINE SHIFT_PAUSEUS 1000
INCLUDE "modedefs.bas"
Hserout ["ACTIVE",13]
RST var portd.0
SCLK var portd.1
CS var portd.2
DOUT var portd.3 'data from PIC to Gyro
DIN var portd.4 'data from gyro to PIC
temp var word'(2)
index var word
High SCLK
High CS
high RST
pause 1000
main:
low CS
Shiftout DOUT, SCLK, 1, [$3C,$00]
high cs
pause 100
low CS
SHIFTIN DIN, SCLK, 2, [temp\16]
high CS
pause 100
HSEROUT ["Temp: ",HEX4 temp,13]
pause 100
goto main
</code>
And the output I am getting out is (HEX):
ACTIVE
Temp: 0000
Temp: 0900
Temp: 0900
Temp: 0900
Temp: 0900
Thanks
Is it correct? Does it work?
Take a look on Table 41 STATUS Bit descriptions (Datasheet pp. 30):
Address 0x3D, 0x3C
Default 0x0000
Default is valid only until the first register write cycle.
Try reading X-Axis data or another register.
I tried reading the 0x04 register, and it just simply gives me 0x0000. I'm relatively sure my connections are right, but I could be wrong. Do I need any pull-ups? Are there any connections I need other than the SPI, reset, and power connections? Thanks
Last edited by InitialDriveGTR; - 24th September 2006 at 17:35.
I have found that shiftin/out will not work with some devices,its the clock pulse timing I believe.Using the MSSI spi hardware port is an option,more involved though or write your own routine.Below is a sample I used with a Maxim 1270 A/D on a 16F877.
DataAcquisition:
for Indexer = 12 to 0 step -1 ' Output data,13 clock pulses
portc.2 = SerialDataOut.0[Indexer] ' Output data port
gosub Clockout ' Output clock pulse
next Indexer ' Next data bit,next clock pulse
for Indexer = 1 to 12 ' Read data,12 clock pulses
SerialDataIn = SerialDataIn * 2 ' Shift each bit to the left
SerialDataIn = SerialDataIn + portc.3 ' Data in port
gosub Clockout ' Output clock pulse
next Indexer ' Next data bit,next clock pulse
return ' Complete return to main
Clockout: ' Clock pulse
pulsout portc.0,5 ' Clock pulse port, 1 msec
return
With shiftout, how can you use binary format instead of hex? Is there a method for translating binary into hex on the PIC?
Bookmarks