• var accx = SPI1.send([0xA9,0], E3)[1]; What is the trailing [1] designation for?

    Yes. SPI.send is sending an array with 2 bytes, and is returning an array with 2 bytes. But we only care about the second byte.

    In SPI the bytes are received as they are sent, so the first element (array index 0) is almost always useless since the device you're talking to hasn't even had a chance to know what you were asking for yet.

    var data = this.spi.send([C.R_REGISTER | reg, 0,0,0,0,0], this.CSN);

    Yes, it's exactly as you say.

    Would this be a possible format to receive a string?

    Not with that code, but SPI1.send("a string", CS_PIN); will return a string as the docs imply.

    Realistically I think in pretty much all cases it makes more sense and is more readable to ignore that functionality and instead just convert the received array to a String:

    var ary = new Uint8Array(16); // send 16 bytes - so we get 16 bytes back
    var result = SPI1.send(ary, CS_PIN);
    console.log(E.toString(result));
    

    Whether the data is a String, a Uint8Array or an Array makes no real difference to how it is transferred over SPI. At the end of the day it's just a stream of bits.

    BUT a String has a length. So how you receive a String depends on what's on the other end of the SPI link and how they decided to implement it over SPI. Espruino will blindly send/receive the amount of raw data you asked it to.

About

Avatar for Gordon @Gordon started