• Hello,

    I want to access the TI TRF7960 (a 13.56MHz RFID reader/writer) with Espruino running on a nucleo STM32F401RE. The TI chip can be accessed with SPI, but with an exotic trick : clock polarity has to change between a write and a read instruction. Below is a drawing from the application report "Using the SPI Interface With TRF7960" (http://www.ti.com/lit/an/sloa140a/sloa140a.pdf).

    How could I do that ? I tried the following but it doesn't work.

    var spi = new SPI();
    spi.setup({sck:B6, miso:A6, mosi:A7, mode:integer=0, order:'msb'});
    
    digitalWrite(SS, 0);
    spi.write(0b01000100);
    spi.setup({sck:B6, miso:A6, mosi:A7, mode:integer=3, order:'msb'});
    d = spi.write(0b01000100);
    
    digitalWrite(SS, 1);
    

    Thank you :)


    1 Attachment

    • Capture (1).PNG
  • Any idea ?

  • not really, because this is odd... may be it saves a line or a few bytes / instructions, but it's more about proprietary than solution.

    Adding a new version of soft SPI based on the existing one in the firmware is the only solution I can see. working... or use a attiny## slave with bitbanging...

  • Hi - I was on holiday last week, hence the lack of replies.

    While it's unlikely to be your problem, you'd want to remove integer= from your code, as that's not doing what you expect :)

    SPI.setup might be resetting pin states to their default values which would throw things off - you could try a slightly hacky method of just updating the software SPI values directly:

    var spi = new SPI();
    spi.setup({sck:B6, miso:A6, mosi:A7, mode:integer=0, order:'msb'});
    digitalWrite(SS, 0);
    spi.write(0b01000100);
    spi._options.mode=3;
    d = spi.write(0b01000100);
    digitalWrite(SS, 1);
    

    Otherwise I'd say to just manually create the waveform using for loops and digitalWrite. Some kind of oscilloscope would probably really help you do see what's going on though.

  • Hi, sorry for the delay to reply.

    I tried and it seems to work, thank you very much ! I will post my code when I will be able to make all the necessary tests to confirm the trick.

    Best regards

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Change SPI clock polarity between a WRITE and a READ instruction

Posted by Avatar for benoit @benoit

Actions