• I really think compiled is a bad idea here - execution speed really will not be your issue at all.

    Specifying SS_PIN for spi.send will automatically set it low and then high after, so you shouldn't need the d(SS_PIN, LOW); anyway.

    Please could you try just:

    function echo(){
        var r=spi.send(0x55,SS_PIN);
       print("echo response:",r);

    Do you have SS_0 pulled high? It seems that if it wasn't the chip might go into UART mode which might cause some pretty strange behaviour.

    HOWEVER looking at http://www.solutions-cubed.com/content/D­ownloads/Breakout%20Modules/DATASHEET_BM­019.pdf I don't think just sending 0x55 should work anyway...

    That's the command, but it looks like commands need to be wrapped up - see page 20 of that document. For example their Arduino code does:

     digitalWrite(SSPin, LOW);
     SPI.transfer(0x00); // SPI control byte to send command to CR95HF
     SPI.transfer(0x04); // Send Receive CR95HF command
     SPI.transfer(0x03); // length of data that follows is 0
     SPI.transfer(0x26); // request Flags byte
     SPI.transfer(0x01); // Inventory Command for ISO/IEC 15693
     SPI.transfer(0x00); // mask length for inventory command
     digitalWrite(SSPin, HIGH);

    In fact it's kind of obvious that just sending 0x55 wouldn't return the right response because data on SPI is clocked in as it is clocked out... So the data you're receiving is being sent by the device even before it has received the command.

    You could try this - which is just the Arduino code that's been hastily converted to Espruino. It might work - if called after your initial setup stuff?

    function Inventory_Command() {
     var i = 0;
    // step 1 send the command
     spi.write([0x00, // SPI control byte to send command to CR95HF
      0x04, // Send Receive CR95HF command
      0x03, // length of data that follows is 0
      0x26, // request Flags byte
      0x01, // Inventory Command for ISO/IEC 15693
      0x00], SS_PIN); // mask length for inventory command
     // ignoring delay(1); 
    // step 2, poll for data ready
    // data is ready when a read byte
    // has bit 3 set (ex: B'0000 1000')
     digitalWrite(SS_PIN, 0);
     // Write 3 until bit 3 is set
     while ((spi.send(0x03) & 0x08) != 8);
     digitalWrite(SS_PIN, 1);
     // ignoring delay(1); 
    // step 3, read the data
     digitalWrite(SS_PIN, LOW);
     var rx = spi.send([0x02,0,0]); // SPI control byte for read
     var data = spi.send(new Uint8Array(rx[2]));
     digitalWrite(SS_PIN, HIGH);
     console.log("Got data", data);

Avatar for Gordon @Gordon started