Freescale MMA7455 accelerometer module to SX28
mspeedie
Posts: 12
I am trying to program an SX28 to read a Freescale MMA7455 (Parallax item code: 28526). The Parallax store has code for the Basic Stamp but I'm having trouble porting the code to the SX28 chip.
(Incidently, I also have the Hitachi H48C module from Parallax. If this is easier to program with the SX, I can switch. Also, I've gotten the Memsic 2125 accel to work but it doesn't provide accurate enough results, and the pulsin duration is too long for my application.)
Anyways, back to the Freescale, the subroutines I'm using for DataOut and DataIn are...
(I can post all of my code if that would be more helpful)
SUB DataOut
Address1 = Address1|%10000000
LOW CSPin 'Pull chip select pin low to start transmission
SHIFTOUT DATAPin, CLKPin, MSBFIRST, Address1<<1 '(Address1|%1000000)<<1 'Select register Address1
SHIFTOUT DATAPin, CLKPin, MSBFIRST, SendData '[SendData] 'Write value to Address1
HIGH CSPin 'End transmission
ENDSUB
SUB DataIn
LOW CSPin 'Pull chip select pin low to start transmission
SHIFTOUT DATAPin, CLKPin, MSBFIRST, Address1<<1 'Select register Address1
SHIFTIN DATAPin, CLKPin, MSBPRE, ReceiveData '[ReceiveData] 'Read value from Address1
HIGH CSPin 'End transmission
ENDSUB
(Incidently, I also have the Hitachi H48C module from Parallax. If this is easier to program with the SX, I can switch. Also, I've gotten the Memsic 2125 accel to work but it doesn't provide accurate enough results, and the pulsin duration is too long for my application.)
Anyways, back to the Freescale, the subroutines I'm using for DataOut and DataIn are...
(I can post all of my code if that would be more helpful)
SUB DataOut
Address1 = Address1|%10000000
LOW CSPin 'Pull chip select pin low to start transmission
SHIFTOUT DATAPin, CLKPin, MSBFIRST, Address1<<1 '(Address1|%1000000)<<1 'Select register Address1
SHIFTOUT DATAPin, CLKPin, MSBFIRST, SendData '[SendData] 'Write value to Address1
HIGH CSPin 'End transmission
ENDSUB
SUB DataIn
LOW CSPin 'Pull chip select pin low to start transmission
SHIFTOUT DATAPin, CLKPin, MSBFIRST, Address1<<1 'Select register Address1
SHIFTIN DATAPin, CLKPin, MSBPRE, ReceiveData '[ReceiveData] 'Read value from Address1
HIGH CSPin 'End transmission
ENDSUB
Comments
It works like this. I hooked up a small speaker to a data pin on my proto board. I set the pin to switch on and off using the Freescale MMA7455 output value as a pause (I'm only using one axis). Therefore, the lower the accelerometer value, the faster the speaker clicks.
I started with the code Parallax has for the Basic Stamp. This speaker test works fine on the Basic Stamp but all I get on the SX is the speaker clicking on and off at a regular frequency that doesn't change when I rotate the accelerometer.
Any help would be great.
Also, you need to have the \16 or \12 or however many bits you need to shiftout for the device register address (I didn't check the docs for the device; I'll leave that to you).