Anyone use an SCA3000 with SPI?

04 Feb 2010 . Edited: 04 Feb 2010

http://www.sparkfun.com/commerce/product_info.php?products_id=8791

http://www.sparkfun.com/datasheets/Sensors/Accelerometer/SCA3000-Manual.pdf

Just got mine from FedEx today...  Looks pretty straight forward, anyone have fun with it yet?

04 Feb 2010

looks good!, what are you planning?

05 Feb 2010 . Edited: 05 Feb 2010

Trying to suppliment some data I'm gathering with 3 analog gyro's so I can experiment a little with orientation, etc...  =)

10 Feb 2010

Ok..  I'm new to SPI, and new to the mbed..  Can someone guide me in the right direction... ?  My code below, as sad as it is...  doesn't get me much.  I'm not sure I understand the spi command, and the device I'm talking to seems difficult even if I did..  I've tried about a hundred iterations with this, and I am declaring myself stuck... =/  Any nudge in the right direction would be appreciated!

#include "mbed.h"

SPI spi(p5, p6, p7);
DigitalOut led1(LED1);
DigitalOut SCA_RESET_PIN(p23);
DigitalOut SCA_CSB_PIN(p22);
Serial pc(USBTX, USBRX); // tx, rx

int main() {
    int result;
    SCA_RESET_PIN = 0;
    spi.format(16, 0);
//    spi.frequency(1000000);
    pc.baud(921600);
    pc.printf("\033[2J");
    wait(1);
    SCA_RESET_PIN = 1;
    wait(2);
    while(1) {
        SCA_CSB_PIN = 0;
        wait(0.1);
        led1 = 1;
        spi.write(0x05);
        wait(0.1);
        result = spi.write(0x00 | result);
        result = result << 8;
        pc.printf("Accel: %d\r\n",result);
        SCA_CSB_PIN = 1;
        led1 = 0;
        wait(.2);
    }
}
10 Feb 2010

Hi Mark,

Without looking at what you are exactly sending/doing, from the timing diagram I'd suggest the format should perhaps be format(8,0) i.e. you are sending two 8-bit "words" = 16 bits total.

Also, I'd probably consider having CS held at 1 as you come out of reset, else it might not see the first edge.

Simon

10 Feb 2010

Thanks Simon for the response!  I will give those things a try.. 

21 Feb 2010 . Edited: 21 Feb 2010

Ok, I tried format(8,0) amongst a million other things...  Luckily I got my logic analyzer today and have been able to see some mistakes and make some progress as it has an SPI Protocol Analyzer in it..  Fun...

Anyway, from what I can tell with my limited SPI experience is that I am having trouble with LSB/MSB order...  I cannot seem to figure out how to get the mbed to send LSB first...

The datasheet (to expand on the portion I posted above) shows something of what I interpret as a non-"standard" configuration... ??

Here's my code:

 

#include "mbed.h"

SPI spi(p5, p6, p7);
DigitalOut led1(LED1);
DigitalOut SCA_RESET_PIN(p23);
DigitalOut SCA_CSB_PIN(p22);
Serial pc(USBTX, USBRX); // tx, rx

int main() {
    int result;
    spi.format(16, 0);
//    spi.frequency(1000000);
    pc.baud(921600);
    pc.printf("\033[2J");

    SCA_RESET_PIN = 0;
    wait(0.01);
    SCA_CSB_PIN = 1;
    SCA_RESET_PIN = 1;
    wait(1);
    
    while(1) {
        led1 = 1;
        SCA_CSB_PIN = 0;
        spi.write(0x05);
        result = spi.write(0x04);
        wait(0.000001);
        SCA_CSB_PIN = 1;
        result = result << 8;
        pc.printf("Accel: %d\r\n",result);
        led1 = 0;
    }
}

 

Here's what I get with my code on the analyzer....

 

Can someone help!!??!?!?   Please?  =)

21 Feb 2010

One quick note about the above.. I am probably totally wrong about the MSB/LSB order...  And if I switch the analyzer to read MSB first, it displays everything except what I expect the accelerometer wants....  If I look at the first earlier image, the 05h X_MSB is 000101 followed by a 0 and a 0....  I'm not getting that, I get the following.....

 

21 Feb 2010 . Edited: 21 Feb 2010

Ok, so I figured part of this out.. I shifted the 05h left by 10bits to get it in the right spot, which is what it seems they are doing.....

 

    int data;
    
    while(1) {
        led1 = 1;
        data = 0x05 << 10;
        SCA_CSB_PIN = 0;
        spi.write(data);
        SCA_CSB_PIN = 1;
wait (0.000001);

        data = 0x04 << 10;
        SCA_CSB_PIN = 0;
        spi.write(data);
        SCA_CSB_PIN = 1;

        result = result << 8;
        pc.printf("Accel: %d\r\n",result);
        led1 = 0;
    }
}

 

 

Problem is, it looks exactly like the datasheet now....but my analyzer doesn't agree....

21 Feb 2010 . Edited: 21 Feb 2010

MISO signal definitely doesn't look right. Are you sure you connected the correct pin?

21 Feb 2010 . Edited: 21 Feb 2010

Thanks for the reply Igor...  Right pin on the mbed, yep... Just not connected to the SCA3000 yet...  I was trying to get my ducks in a row before accidentally writing something harmful to the device unintentionally...  =)

I just can't seem to make heads or tails of this thing yet..

Here's what I get when I do the same thing with the SCA3000 connected...  I guess it looks like it's responding... I just haven't a clue if it's what I should expect... hah...

 

I'm still confused... sadly....

21 Feb 2010

Ok...  As if I haven't posted enough... I do believe I've figured it out.... With one last mystery...  Using the code below, I get three spectacular results as I move the device in three dimensions..  However, somehow...I think I'm not displaying them as they should be..  I don't think I'm doing something right, using int/float/whatever....  Am I on the right track?

 

#include "mbed.h"

SPI spi(p5, p6, p7);
DigitalOut led1(LED1);
DigitalOut SCA_RESET_PIN(p23);
DigitalOut SCA_CSB_PIN(p22);
Serial pc(USBTX, USBRX); // tx, rx

int main() {
    int result;
    spi.format(16, 1);
//    spi.frequency(1000000);
    pc.baud(921600);

    SCA_RESET_PIN = 0;
    wait(0.01);
    SCA_CSB_PIN = 1;
    SCA_RESET_PIN = 1;
    wait(1);
    
    int data;
    
    while(1) {
        led1 = 1;
        data = 0x05 << 10;
        SCA_CSB_PIN = 0;
        result = spi.write(data);
        SCA_CSB_PIN = 1;
        result = result << 8;
        pc.printf("\033[2J");
        pc.printf("X_MSB: %d\r\n",result);

        data = 0x04 << 10;
        SCA_CSB_PIN = 0;
        result = spi.write(data);
        SCA_CSB_PIN = 1;

        result = result << 8;
        pc.printf("X_LSB: %d\r\n",result);

//

        led1 = 1;
        data = 0x07 << 10;
        SCA_CSB_PIN = 0;
        result = spi.write(data);
        SCA_CSB_PIN = 1;
        result = result << 8;
        pc.printf("Y_MSB: %d\r\n",result);

        data = 0x06 << 10;
        SCA_CSB_PIN = 0;
        result = spi.write(data);
        SCA_CSB_PIN = 1;

        result = result << 8;
        pc.printf("Y_LSB: %d\r\n",result);

//

        led1 = 1;
        data = 0x09 << 10;
        SCA_CSB_PIN = 0;
        result = spi.write(data);
        SCA_CSB_PIN = 1;
        result = result << 8;
        pc.printf("Z_MSB: %d\r\n",result);

        data = 0x08 << 10;
        SCA_CSB_PIN = 0;
        result = spi.write(data);
        SCA_CSB_PIN = 1;

        result = result << 8;
        pc.printf("Z_LSB: %d\r\n",result);

wait(0.05);
        led1 = 0;
    }
}

21 Feb 2010

I'm still lost apparently..  I get a solid MSB that only changes when I tilt the device, not showing anything that makes sense (45' angle would be the same as a 15', move it and the value jumps again..)  At rest it says MSB = 1013 and LSB = 640..  Tilt it and MSB changes to 740, jumps to 1040 and back to 710 and back to 1040, etc...

#include "mbed.h"

SPI spi(p5, p6, p7);
DigitalOut led1(LED1);
DigitalOut SCA_RESET_PIN(p23);
DigitalOut SCA_CSB_PIN(p22);
Serial pc(USBTX, USBRX); // tx, rx

int main() {
    spi.format(16, 0);
//    spi.frequency(1000000);
    pc.baud(921600);

    SCA_RESET_PIN = 0;
    wait(0.01);
    SCA_CSB_PIN = 1;
    SCA_RESET_PIN = 1;
    wait(2);
    
    int X_MSB;
    int X_LSB;
    int BYTE;
    int Address;

    while(1) {
        Address = 0x05;
        BYTE = Address << 10;
        led1 = 1;
        SCA_CSB_PIN = 0;
        X_MSB = spi.write(BYTE);
        SCA_CSB_PIN = 1;
        led1 = 0;
//        X_MSB = X_MSB << 8;
        pc.printf("\033[2J");
        pc.printf("X_MSB: %d\r\n",X_MSB);

        Address = 0x04;
        BYTE = Address << 10;
        led1 = 1;
        SCA_CSB_PIN = 0;
        X_LSB = spi.write(BYTE);
        SCA_CSB_PIN = 1;
        led1 = 0;
//        X_LSB = X_LSB << 8;
        pc.printf("X_LSB: %d\r\n",X_LSB);


wait(0.005);
    }
}

 

I found these conversations about it.. It doesn't look like anyone has figured it out... ??

http://forum.sparkfun.com/viewtopic.php?t=19998&highlight=sca3000

http://forum.sparkfun.com/viewtopic.php?t=19132&highlight=sca3000

http://forum.sparkfun.com/viewtopic.php?t=18777&highlight=sca3000

http://forum.sparkfun.com/viewtopic.php?t=14366&highlight=sca3000

http://www.vti.fi/midcom-serveattachmentguid-f8d0194a36326993efdc5211fbef229a/tn55_c-code_example_for_sca3000_rev_0.1.pdf

 

 

I'm about to give up... =(

21 Feb 2010

Hi Mark,

I don't have one of these, so really can't test, but here is my attempt writing it totally blind from the datasheet:

#include "mbed.h"

SPI spi(p5, p6, p7);
DigitalOut SCA_RESET_PIN(p23);
DigitalOut SCA_CSB_PIN(p22);

DigitalOut led1(LED1);
Serial pc(USBTX, USBRX); // tx, rx

// SCA3000 SPI Format
// [ a(5:0) | nr/w | 0 ] [ d(7:0 ]
int sca3000_read(int address) {
    int nrw = 0;      // we're doing a read
    SCA_CSB_PIN = 0;
    int command = (address << 2) | (nrw << 1); 
    spi.write(command);             // write out the address (1st 8 bits)
    int result = spi.write(0xFF);   // read the result (2nd 8 bits)
    SCA_CSB_PIN = 1;
    return result;
}

int main() {
    pc.baud(921600);
    spi.format(8, 0);
    SCA_RESET_PIN = 0;
    SCA_CSB_PIN = 1;
    wait(0.01);
    SCA_RESET_PIN = 1;
    wait(2);

    // SCA3000 Register Format:
    //  X_MSB @ 0x05   X_LSB @ 0x04
    // [ s | d(11:5) ] [ d(4:0) | x(3) ]
    while (1) {
        int msb = sca3000_read(0x05);
        int lsb = sca3000_read(0x04);
        int16_t result = (msb << 8) | (lsb & 0xF8); // construct result and ignore bottom 3 bits
        pc.printf("X: %d\r\n", result);
        wait(0.005);
    }
}

Not sure it'll actually work, but might give you some hints if you've done anything differently.

Simon

22 Feb 2010

WOW..  Nice job Simon!  I am very impressed!  I tried it and it seems to work with no changes...  I obviously have a bit to learn. 

 

I really appreciate the help, and I think your example will serve to aid my understanding alot...  Looks like I missed something on putting the msb/lsb together too.. =/

 

 

Thanks again!!!!

-mark