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:
    // (?)same as­w.js(?)
    // using SPI2 and A2 for CS as used before and posted about experience
    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;
     function(add,bytes) {
    	if (add===undefined) {;
    	var ov=this.spi.send(t,this.cspin);
    	var o=new Uint8Array(ov.buffer,(this.cap>65536?4:3­),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));
    		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);

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

     1v72 Copyright 2014 G.Williams
    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

    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


Avatar for allObjects @allObjects started