• Is there a reason you couldn't just go from 0 to 15 for the FOR loop in readReg? Currently you do 10 to 15, then 0 to 9 - but the array is sorted so I don't think it makes much difference? :)

    I think there might be some issue with how you're handling 16 bits numbers... i2c.readFrom and i2c.writeTo will only be expecting and producing arrays of 8 bit numbers, so while you have:

                this.registers[x] = data[x] << 8;
                this.registers[x] |= data[x];
    

    You'd usually want to do something like:

                this.registers[x] = data[2*x] << 8;
                this.registers[x] |= data[(2*x) + 1];
    

    Same thing with this.i2c.writeTo( this.addr, i, this.registers[i] ); in writeReg - you probably want this.i2c.writeTo( this.addr, i, this.registers[i]>>8, this.registers[i]&255 ); or something like that?

    Also, you have if( i > 0x02 ) in writeReg so I guess this.registers[ 0x02 ] = 0x4001; won't do anything, then the one command that might have worked:

    this.registers[ 0x07 ] = 0x8100;
    

    Has the bottom 8 bits (which would be all that gets set currently) as 0 - which is what you're reading.

    You could take a look at DataView which has a nicer way of handling 16 bit to 8 bit number conversion in an array - but honestly it may just complicate matters.

  • @allObjects: Perhaps I should have mentioned that I left the volume control out for the moment, since there is no sound to control yet :)

    @Gordon: you make some excellent points on 8 vs 16-bits. I'll have a look at DataView, and some YouTube tutorials on bitwise operators ;-)

About

Avatar for Gordon @Gordon started