Multiple SPI devices (on separate SPI channels) interfere with each other

13 Nov 2010

I have two separate SPI devices connected to completely different SPI buses. Each device has its own driver library / class based on the pattern of the LIS302 driver by Simon Ford. Both the drivers work great on their own. If I have only one device, I can instantiate it (once) at the top of the file and then call its member functions e.g., sample the sensor in a loop. However, instantiating a second device makes the first device stop working. I can only get both devices to work if I re-instantiate the devices before each communication attempt.

In other words, this works:

int main() {
    Sensor1 s1(p5,p6,p7);
    while(1) {
        s1.sample();
    }
}
But this doesn't:

int main() {
    Sensor1 s1(p5,p6,p7);
    while(1) {
        s1.sample();
    }
}
And this does:

int main() {
    Sensor1 s1(p5,p6,p7);
    Sensor2 s2(p11,p12,p13);
    while(1) {
        s1.sample(); //blocks forever
        s2.sample(); //we never get here
    }
}
Has anyone seen this kind of behavior before?

Matt

16 Nov 2010

Somehow I messed up the previous post (copy-n-paste in the compiler in Safari sometimes acts a little weird!). I meant to show these three examples...

int main() {
    Sensor1 s1(p5,p6,p7);
    Sensor2 s2(p11,p12,p13);
    while(1) {
        s1.sample(); //blocks forever! somehow initializing the second sensor breaks the first!
        s2.sample(); //we never get here
    }
}

int main() {
    Sensor1 s1(p5,p6,p7);
    while(1) {
        s1.sample(); //works just fine
    }
}

int main() {
    while(1) {
        Sensor s1(p5,p6,p7);
        s1.sample(); //works
        Sensor s2(p11,p12,p13);
        s2.sample(); //works
    }
}