Help! I am a newb to the Arduino and I do not have an electronics background. Nor do I have an oscilliscope. I’ve been trying to get the SPI communications working between a 5V Arduino Duemilanove and a 3.3V SCA3000 accelerometer on a breakout board from Sparkfun. But first, I think I first need help with the wiring.
My most “successful” attempt at trying to read information from the SCA3000 has been through the Sparkfun Logic Level converter, BOB-08745. Below is a diagram of how I connected it:
Arduino Logic Level Converter SCA3000 Breakout
------------------ ------------------------- -----------------------
Pin 10 (SS or CS) RXI --> RXO (chnl1) CSB
Pin 11 (MOSI) TXO --> TXI (chnl1) MOSI
Pin 12 (MISO) TXO --- TXI (chnl2) MISO
Pin 13 (SPI clock) RXI --> RXO (chnl2) SCK
3.3V on Low Level side VIN
5V on High Level side
Gnd both Gnds GND
no additional resistors were used
Voltages at CSB: 2.497V (High, or Disabled) & 0.111V (Low, or Enabled)
If connection from CSB to RXO is removed, CSB: 3.256V. RXO: 2.370V & 0.001V.
Voltage at SCA3000 chip after Breakout board voltage regulator: 3.298V. It does not matter whether connected to 5V or 3.3V from the Arduino.
The code I am using is at the bottom of this posting. The code is from another posting by Emdee. It is just trying to get information from the SCA3000.
Below are the results from the last attempt with this diagnostic program. This is using my 2nd SCA3000 Breakout board. (I believe I may have fried my first SCA3000 breakout board by connecting it directly to the Arduino):
Code:
SPCR: 1010011
Mode (address 14h) = 00010000
Status (address 2h) = 00000000
Int_status (i.e. buffer, etc., 16h) = 00000000
Ctrl_Sel (i.e. control register selector, 18h) = 00000000
Int_Mask (i.e. interput mask register, 21h) = 00000000
Temperature (addresses 13h &12h) = 0000000000000000
00000000 00000000 00000000 00000000 00000000 00000000 0 0 0
00000000 00000000 00000000 00000000 00000000 00000000 0 0 0
00000000 00000000 00000000 00000000 00000000 00000000 0 0 0
(mode = 0 just after uploading program. Mode = 16, or Free-fall enabled after
repowering unit.)
I do get differing results after just uploading the program and opening a COM window as opposed to uploading the program, disconnecting the USB from the Arduino, reconnecting the USB, and then opening a COM window. The only difference is the value that is returned from the Mode register.
The most I’ve ever received from reading the X, Y, and Z accelerations is a single line of returned numbers. After that, it starts returning zeroes.
From another forum, I took the suggestion by RuggedCircuits to perform a Loopback test. I connected the MOSI to the MISO on the low voltage side of the Logic Level Converter (just to make sure the TX lines really were bi-directional). This is what I got. (This output does not have some of the reads of the other registers as I showed above – the program was altered slightly.)
SPCR: 1010011
mode = 00010100 (This value of 14h, or 20, is the address sent out on MOSI)
status = 2 (This value of 2 is the address sent out on MOSI)
00000101 00000100 00000111 00000110 00001001 00001000 1284 1798 264
00000101 00000100 00000111 00000110 00001001 00001000 1284 1798 264
00000101 00000100 00000111 00000110 00001001 00001000 1284 1798 264
(The Binaries are addresses 5, 4 (for X), 7, 6 (for Y), and 9, 8 (for Z).)
The results were what I expected. Address In, Address Out. From the SPDR, you can see I’m trying the SPI communications at the slowest speed. That has not made a difference in communicating with the SCA3000.
I’ve tried other configurations, including some of the ones suggested in the Sparkfun Sensor Interfacing tutorial http://www.sparkfun.com/commerce/tutori … ials_id=65. I tried this connection and got some strange results:
Arduino SCA3000 Breakout
------------------ ------------------------- -----------------------
Pin 10 (SS or CS) 1kohm, 10kohm to 3.3V CSB
Pin 11 (MOSI) 10kohm MOSI
Pin 12 (MISO) directly wired MISO
Pin 13 (SPI clock) 10kohm SCK
3.3V VIN
With this voltage divider on CSB, V = 4.078 when high and 0.327V when low. The specs for the SCA3000 chip say V no higher than 3.6V.
SPCR: 1010011
mode = 00000010
status = 4
00010000 00000000 00000100 00000000 01000010 00001110 0 1024 526
00000000 01000000 00000100 00010000 01000000 00000010 64 1040 2
00000000 10000010 00000100 00000000 00000000 00001100 130 1024 12
01000000 00000000 00000000 00000000 01000100 00001100 0 0 1036
00000000 00000000 00000000 01000001 11000000 00000110 0 65 6
00000000 01100010 00000000 00000000 00000000 00010000 98 0 16
00100000 00000000 00000000 00000000 00000010 00001000 0 0 520
00000000 00000000 00000000 01000000 00000000 00000000 0 64 0
On a second attempt on running with this wiring configuration, I got:
SPCR: 1010011
mode = 00000000
status = 0
00000000 00000000 00000000 00000000 00000000 00000000 0 0 0
00000000 00000000 00000000 00000000 00000000 00000000 0 0 0
00000000 00000000 00000000 00000000 00000000 00000000 0 0 0
Instead of the voltage divider set up above, I used a diode in place of the 1k ohm resistor and got the voltages at CSB to 3.434V (High) and 0.212V (low). The COM window returned all zeroes for the modes, status, and accelerometer register reads.
Has anyone hooked up one of these SCA3000 chips to a 5V Arduino board successfully? How did you wire it? Could the 2.5V coming out of the Logic Level Converter be too low for this chip, even though the specs say 0.7 * VIN, or 2.31V min? Are there additional programming commands that are required with this chip to enable it over and above other chips with SPI communications?
Any help would be greatly appreciated!! I’ve been tearing my hair out on this over the last couple of weeks. This accelerometer is the one that is recommended for dead reckoning applications with digitial outputs.
/* Code is from Emdee, dated 2-18-09. It is a test program only.
This code does not include the bit shifting that will be eventually required.
Slight mods from original code with more diagnostic println's.
*/
#include <Spi.h>
#define UBLB(a,b) ( ( (a) << 8) | (b) )
#define UBLB19(a,b) ( ( (a) << 16 ) | (b) )
byte b1,b2;
int Ax,Ay,Az;
unsigned int temp,n;
void setup()
{ Serial.begin(9600);
delay(20);
Spi.mode(0);
delay(2);
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0); //Set SPI communications to slowest speed, or 250kHz
int n = SPCR;
Serial.print("SPCR: ");
binaryPrint(n);
Serial.println();
n = Spi.transfer(0x14);
Serial.print("Mode (address 14h) = ");
binaryPrint(n);
Serial.println();
// n = Spi.transfer(0x00);
// Serial.print("RevID: ");
// binaryPrint(n);
// Serial.println();
n = Spi.transfer(0x02);
Serial.print("Status (address 2h) = ");
binaryPrint(n);
Serial.println();
n = Spi.transfer(0x16);
Serial.print("Int_status (i.e. buffer, etc., 16h) = ");
binaryPrint(n);
Serial.println();
n = Spi.transfer(0x18);
Serial.print("Ctrl_Sel (i.e. control register selector, 18h) = ");
binaryPrint(n);
Serial.println();
n = Spi.transfer(0x21);
Serial.print("Int_Mask (i.e. interput mask register, 21h) = ");
binaryPrint(n);
Serial.println();
delay(1000);
n = Spi.transfer(0x13);
Serial.print("Temperature (addresses 13h &12h) = ");
binaryPrint(n);
n = Spi.transfer(0x12);
binaryPrint(n);
Serial.println();
/*
n = Spi.transfer(0x14);
Serial.print("mode = ");
Serial.println(n);
*/
delay(1000);
}
char* fmtSpace(int i, char *buf)
{
int j,k;
for (j=0;j<7;j++) buf[j]=0;
itoa(i,buf,10);
j=0;
if (i<10000) j=1; // less than 5 characters, 1 space
if (i<1000) j=2;
if (i<100) j=3;
if (i<10) j=4;
for (k=5-1;k>=0 ;k--)
{
buf[k]= (k-j>=0)? buf[k-j] : ' ';
}
return buf;
}
void binaryPrint(byte in_b)
{ int i,j;
byte b;
for (i=7;i>=0;i--)
{
if (in_b & 1<<i)
Serial.print('1');
else
Serial.print('0');
}
}
char ibuf[10];
int c=0;
short s;
void loop()
{
// if (!c) // my loop counter
// Serial.println("Ax Ay Az ");
b1 = Spi.transfer(0x05); //x axis msb
b2 = Spi.transfer(0x04); //x axis lsb
binaryPrint(b1);
Serial.print(' ');
binaryPrint(b2);
b1 &= B00000111; //just 11 bit so clear all but last 3 of msb
Ax = UBLB(b1,b2);
b1 = Spi.transfer(0x07); //y axis msb
b2 = Spi.transfer(0x06); //y axis lsb
Serial.print(" ");
binaryPrint(b1);
Serial.print(' ');
binaryPrint(b2);
b1 = b1 & B00000111; //just 11 bit so clear all but last 3 of msb
Ay = UBLB(b1,b2);
b1 = Spi.transfer(0x09); //z axis msb
b2 = Spi.transfer(0x08); //z axis lsb
Serial.print(" ");
binaryPrint(b1);
Serial.print(' ');
binaryPrint(b2);
b1 &= B00000111; //just 11 bit so clear all but last 3 of msb
Az = UBLB(b1,b2);
fmtSpace(Ax,ibuf);
Serial.print(" ");
Serial.print(ibuf);
fmtSpace(Ay,ibuf);
Serial.print(ibuf);
fmtSpace(Az,ibuf);
Serial.println(ibuf);
delay(10000);
// c++;
// c = c % 20;
}