You are reading a single comment by @allObjects and its replies. Click here to read the full conversation.
  • Had some time to spend with new serial memory modules.

    Loaded AT25 from git, placed it inline as below, and tried to run it (in 1v72). First, the editor complained about several things... mostly just missing semicolons (see screen shot attachment). To get the statement in the wait loop accepted by the IDE, I added a dmy variable.

    // using AT25 (copy - inline) to write/read to/from 256KBit FRAM:
    // https://github.com/SpenceKonde/EspruinoD­ocs/blob/master/devices/AT25.js
    // (?)same as http://drazzy.com/e/espruino/etc/AT25_ne­w.js(?)
    
    // using SPI2 and A2 for CS as used before and posted about experience
    // http://forum.espruino.com/comments/11937­103/
    
    var exports = {};
    (function() {
      
    // AT25 module code
    
    exports.connect = function(spi, pgsz, cap, cspin) {
    	if (cap > 4096 || !cap || pgsz > cap || !cspin) {
    		throw "Unsupported or invalid options";
    	}
        return new AT25(spi, pgsz, cap, cspin);
    };
    
    function AT25(spi, pgsz, cap, cspin) {
      this.spi = spi;
      this.cspin=cspin;
      this.pgsz=pgsz;
      this.cap=cap<<7;
      this.ca=0;
    }
    
    
    AT25.prototype.read= function(add,bytes) {
    	if (add===undefined) {
    		add=this.ca;
    	}
    	t=(this.cap>65536)?E.toString(3,add>>16&­0xff,add>>8&0xff,add&0xff):E.toString(3,­add>>8&0xff,add&0xff);
    	var ov=this.spi.send(t,this.cspin);
    	var o=new Uint8Array(ov.buffer,(this.cap>65536?4:3­),bytes);
    	this.ca=add+bytes;
    	return o;
    };
    
    
    AT25.prototype.write= function(add,data,num) {
    	if(typeof data!="string"){data=E.toString(data);}
    	var idx=0,dmy;
    	while (idx < data.length) {
    		this.spi.send(6,this.cspin); //WREN
    		var i=this.pgsz?(this.pgsz-(add%this.pgsz)):­data.length;
    //      console.log(this.spi.send([5,0],this.csp­in));
    		t=(this.cap>65536)?E.toString(2,add>>16&­0xff,add>>8&0xff,add&0xff):E.toString(2,­add>>8&0xff,add&0xff);
    		t=t+data.substr(idx,i);
    		this.spi.send(t,this.cspin);
    		var et=getTime()+0.012;
    		while (getTime() < et && this.pgsz) {dmy="";}
    		idx+=i; add+=i;
    	}
    	return data.length;
    };
    
    // /AT25 module code
    
    }());
    SPI2.setup({sck:B13, miso:B14, mosi:B15, baud: 18000000});
    var fram = exports.connect(SPI2,0,256,A2);
    
    console.log(fram.read(0,256));
    

    The tries did not go that well. The console complained:

     1v72 Copyright 2014 G.Williams
    >echo(0);
    undefined
    =undefined
    Uncaught Error: Field or method does not already exist, and can't create it on String
     at line 7 col 28
        var o=new Uint8Array(ov.buffer,(this.cap>65536?4:3­),byte...
                                ^
    in function "read" called from line 1 col 28
    console.log(fram.read(0,256));
    

    Furthermore, I wondered about several items:

    1. Why is t in the write() not declared?
    2. Does it matter - for ESPRUINO's JS interpreter implementation if declarations of variables are inside or outside a loop?
    3. The console.log() in write() must be a left over... :}

    I'll look a bit more into the code...


    2 Attachments

About

Avatar for allObjects @allObjects started