• ( See updated version of module)

    Was looking for some serially connected RAM that has to briefly hold on to some processing data (not like EEPROM / SDCard) and has to be very fast. Came across this thing and it has great specs (datasheet attached). Ordered - 2 pieces - and got package yesterday. 'Tin-glued' it to Espruino board, added some more machined socket pins for connecting. With hardware 'complete', I started coding...

    Reading the device ID got pretty quickly going... even though not standard. Everything after that became just rubbish... and still is. Nevertheless, I publish it here...

    // FRAMSPI_inline.js (c) muet.com
    // F RAM SPI Module
    var framspiModule = { connect: function(spi,cs,hd,wp) {
      pinMode(cs,"output"); cs.set();
      if (hd) { pinMode(hd,"output"); hd.set(); }
      if (wp) { pinMode(wp,"output"); wp.set(); }
      var fram = 
    { id: function() {
        var d = spi.send(
         ,cs); // chip select, write 0x9F, send 10*0x00 not working
        return d;
    , stat: function() { 
        var d = spi.send(
        return d;
    , wen: function() {
    , wdi: function() {
    , read: function(a,n){
        var d = new Uint8Array(n);
        while (n>0) { n--; d[n] = spi.send(0x00); } 
        return d;
    , write: function(a,d){
      return fram;
    SPI2.setup({sck:B13, miso:B14, mosi:B15, baud: 1000000});
    var fram = framspiModule.connect(SPI2,B12);
    fram.write(  0,"FRAM@000");
    fram.write(  8,"FRAM@008");
    fram.write( 16,"FRAM@016");
    console.log("@000:",fram.read(  0,  8));
    console.log("@008:",fram.read(  8,  8));
    console.log("@016:",fram.read( 16,  8));
    console.log("@128:",fram.read(128,  8));
    console.log("@256:",fram.read(256,  8));
    console.log("@512:",fram.read(512,  8));

    The challenge is in SPI. Having done some work with the ILI9341 SPI LCD controller, I though: piece of cake... wrong. The FRAM's SPI is behaving weird: bytes get stuck in the output buffer and are read the next time. Also randomly dummy bytes are inserted for no obvious reason. Elaborating and trying to track some of the signals lead to the death of one chip... an so I had hope that the second would fair better. So far I can say: work different... actually more annoying: the broken chip could handle ID-read followed by a status-read. The new chip inserts dummy bytes so that the first status read has just those, as you can see in the output below (chip ID shows on upload, fram.stat() is called with a command n console):

     1v70 Copyright 2014 G.Williams
    [ 255, 127, 127, 127, 127, 127, 127, 194, 34, 0 ]
    =[ 255, 255 ]
    =[ 255, 0 ]

    Tried to add other dummy byte, but this makes it even worse. Somehow, the chip does not follow its own spec which says that when chip select (CS) goes high, the SPI transaction is considered complete, even though send may not have completed yet.

    It seems, that only continuously sending / receiving works to some degree: everything packed in a Uint8Array - including the command and parameters - and SPI.send() it a once. Using a mix and mach of SPI.write() and SPI.send() fails.

    Looking for answers I came across hints that the SPI behavior is a bit unique... something about having to keep the clock going...

    I have not given up yet, but if things do not smoothen out soon, I will look for a different solution.... :(

    5 Attachments


Avatar for allObjects @allObjects started