Hi,
I'm a bit confused. I wrote the following code to get an Analog Devices ADXL362 triple axis accelerometer working. It uses SPI to communicate with the outside world. The weird thing is that I have to have the SPI mode set differently for send and receive to make it work - as per the code below. Can anyone tell me why? It's not a problem - the setup works fine for read and write - it just seems rather odd. (The code puts a very basic display on the screen showing the readings from the X, Y and Z axes.)
As an example of what I mean, in the section which says:
...the mode settings of 1 and 0 are different and the setup doesn't work if you make them both either 1 or 0.
Here's the whole program:
I'm a bit confused. I wrote the following code to get an Analog Devices ADXL362 triple axis accelerometer working. It uses SPI to communicate with the outside world. The weird thing is that I have to have the SPI mode set differently for send and receive to make it work - as per the code below. Can anyone tell me why? It's not a problem - the setup works fine for read and write - it just seems rather odd. (The code puts a very basic display on the screen showing the readings from the X, Y and Z axes.)
As an example of what I mean, in the section which says:
Code:
shiftout 1,2,1, (11,45)
shiftin 1,3,0, (b0)
Here's the whole program:
Code:
'The setup uses:
'- Analog Devices ADXL362 3-Axis Accelerometer
'- PICAXE 28X1 IC
'- TextStar display
init:
symbol lcd=0 'LCD output port
symbol cs=b.7 'Chip Select line
high cs 'Set the chip select high (off)
high 0 'Set the LCD line high (because it idles high)
pause 100
'Put a title on the display
serout lcd,2400,(12)
pause 2000 'Wait for LCD to initialise
serout lcd,2400,(" ADXL362 ")
serout lcd,2400,(" Accelerometer ")
pause 1000 'Wait for 1 second
serout lcd,2400,(12)
'Set up the power register
low cs
shiftout 1,2,1, (10,45,2) 'Bits 0 and 1 set to a value of decimal '2' sets the device to make measurements
high cs
pause 250
'Read the power register and display it
low cs
shiftout 1,2,1, (11,45)
shiftin 1,3,0, (b0)
high cs
serout lcd,2400,(254,"H")
serout lcd,2400,("Power Byte = ",#b0," ")
pause 1000
serout lcd,2400,(12) 'Clear the screen
main:
x:
low cs 'Chip select on
shiftout 1,2,1, (11,8) 'Send 11 (read) and 8 (X-axis register address) 1=Clock Pin 2=Output Pin 1=Mode
shiftin 1,3,0, (b0) 'Shift the result into b0
high cs 'Chip select off
serout lcd,2400,(254,"H") 'Move the LCD's cursor to the home position
serout lcd,2400,("X",254,"b",7,b0) 'Display a bar graph on the LCD
y:
low cs
shiftout 1,2,1, (11,9)
shiftin 1,3,0, (b0)
high cs
serout lcd,2400,("Y",254,"b",7,b0)
z:
low cs
shiftout 1,2,1, (11,10)
shiftin 1,3,0, (b0)
high cs
serout lcd,2400,("Z",254,"b",7,b0)
goto main