You are reading a single comment by @Thijsmans and its replies.
Click here to read the full conversation.
-
@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 ;-)
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
andi2c.writeTo
will only be expecting and producing arrays of 8 bit numbers, so while you have:You'd usually want to do something like:
Same thing with
this.i2c.writeTo( this.addr, i, this.registers[i] );
inwriteReg
- you probably wantthis.i2c.writeTo( this.addr, i, this.registers[i]>>8, this.registers[i]&255 );
or something like that?Also, you have
if( i > 0x02 )
inwriteReg
so I guessthis.registers[ 0x02 ] = 0x4001;
won't do anything, then the one command that might have worked: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.