• Mon 2019.07.29

    I am attempting to make sense of several examples. At this point it is learning only.

    Stumbled across this note, and thought I'd give strings a try:

    "Sending an integer will return an integer, a String will return a String, and anything else will return a Uint8Array."
    "For maximum speeds, please pass either Strings or Typed Arrays as arguments."

    Searching churned up these examples:


    SPI1.send([0x20,0b01000111], E3);

    var accx = SPI1.send([0xA9,0], E3)[1];

    I was not able to determine the following as the syntax appears odd, having square brackets attached to function parenthesis:
    What is the trailing [1] designation for?

    Is it an array indexer, or an array of one byte that is passed, the container for the return data?

    Sanity check please:
    Using the source:


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

    shows a comma delimited list. As it appears inside the square brackets, does this command effectively say:     'Send an array of six elements initialized to zero, with element zero containing the bitwise mask of the contents of the parameter 'reg' OR'd with flags constant R_REGISTER, and apply this to the chip select pin?'

    Note if 'yes' then I'm on the right track, 'no' lots more reading to comprehend.

    Would this be a possible format to receive a string? (making the assumption the slave is sending of course)

    var ary = new Uint8Array(16);

    ary = SPI1.send([CMD_SEND_STRING], CS_PIN);
    or perhaps?
    ary = SPI1.send([CMD_SEND_STRING], CS_PIN)[16];

    What are the max buffer sizes in both directions?

    Are there any other more suitable examples that might demonstrate these techniques?


Avatar for Robin @Robin started