• I got past the 8-bits vs 16-bits issue and I was just listening to my first song on the si4703; Phil Collings I believe...

    
    	/*
    		si4703 begins reading from register upper register of 0x0A and reads 
    		to 0x0F, then loops to 0x00. Since register 0x0A comes in first 
    		we have to shuffle the array around a bit.
    	*/
    
    	si4703.prototype.readReg = function ( verb ) {
    		//this.i2c.writeTo( this.addr, 0 );
    		data = this.i2c.readFrom( this.addr, 32 );
    
    		for( var i=0; i<data.length; i+=2 )
    		{
    			bits = data [ i ] << 8;
    			bits |= data[ i+1 ];
    
    			reg = ( i < 12 ? i+(10-i/2) : (i/2)-6 );
    			this.registers[reg] = bits;
    		}
    
    		if( verb !== false )
    			this.printReg();
    	};
    
    	/*
    		Write the current 9 control registers (0x02 to 0x07) to the Si4703. 
    		It's a little weird, you don't write an I2C addres, The Si4703 assumes 
    		you are writing to 0x02 first, then increments.
    	*/
    	si4703.prototype.writeReg = function () {
    		bytes = [];
    		for( i=0x02; i<0x08; i++ )
    		{
    			var high = this.registers[ i ] >> 8;
    			var low  = this.registers[ i ] & 0x00FF;
    			bytes.push(high, low);
    		}
    		this.i2c.writeTo( this.addr, bytes );
    	};
    
    	si4703.prototype.printReg = function () {
    		console.log( 'Register    | Dec     | Hex    | Bits');
    		fill   = String('.');
    
    		for( var i in this.r )
    		{
    			label = i;
    			dec = this.registers[ this.r[i] ];
    			hex = dec.toString(16);
    			bits = dec.toString(2);
    
    			console.log( label + fill.repeat(10-label.length ) 		+ '  | ' +
    						 dec   + fill.repeat(6-String(dec).length)  + '  | ' +
    						 hex   + fill.repeat(5-hex.length)  		+ '  | ' + 
    						 fill.repeat(18-bits.length) + bits
    				);
    		}
    		console.log(" ");
    	};
    

    This is working just fine:

    Register    | Dec     | Hex    | Bits
    DEVIDEID..  | 4674..  | 1242.  | .....1001001000010
    CHIPID....  | 2640..  | a50..  | ......101001010000
    POWERCFG..  | 50433.  | c501.  | ..1100010100000001
    CHANNEL...  | 0.....  | 0....  | .................0
    SYSCONFIG1  | 6144..  | 1800.  | .....1100000000000
    SYSCONFIG2  | 21....  | 15...  | .............10101
    SYSCONFIG3  | 0.....  | 0....  | .................0
    TEST1.....  | 48132.  | bc04.  | ..1011110000000100
    TEST2.....  | 6.....  | 6....  | ...............110
    BOOTCONFIG  | 1.....  | 1....  | .................1
    STATUSRSSI  | 28693.  | 7015.  | ...111000000010101
    READCHAN..  | 205...  | cd...  | ..........11001101
    RDSA......  | 255...  | ff...  | ..........11111111
    RDSB......  | 0.....  | 0....  | .................0
    RDSC......  | 0.....  | 0....  | .................0
    RDSD......  | 0.....  | 0....  | .................0
    

    So now onwards to an Espruino-port of the Arduino sketch!

About

Avatar for Thijsmans @Thijsmans started