Closed JoniDS closed 6 years ago
According to the user manual:
Data transfer between the microcontroller and additional board is performed via the Serial Peripheral Interface (SPI), whereas the operation of the board is controlled by the microcontroller via I2C communication
This link isn't the datasheet, so it doesn't seem to go into specific detail how this is accomplished. But you should be able to connect your Android Things board to this peripheral over I2C and then send commands to it. If you want to transfer data, you can also connect an SPI line and read/write data.
@Fleker I can see the device as an SPI interface and set it up as an audio device output. However I can't turn the DAC on. From their spec docs this is how it should be done -> https://www.rockbox.org/wiki/pub/Main/DataSheets/WM8731_8731L.pdf (page 42) Yet I don't really understand how I can do this from https://developer.android.com/things/sdk/pio/i2c
So if 15:9 are the addresses, and you have 9 bits (8:0) of data, you'll need to use the generic write method. So you may want to start with something like this:
byte byte1 = i2cAddress << 1; // Need to shift address 1 to the left
byte byte2 = data && 0xFF; // Need to mask so only first 8 bits are used
byte1 |= (data >> 8) && 0xFF; // Need to shift and mask so you can get the 9th bit
i2cDevice.write([byte1, byte2], 2);
So, if I want to avoid manipulating bits I could do something like this?
device.write(byteArrayOf(0x12, 0x1), 2) // R9 (12h)
I'm not sure if that will work, as sending [0x12, 0x01] wouldn't correspond to register 0x12. Bits 15 - 8 must be your first byte, and bits 7 - 0 must be your second byte.
It does work. Turns out my problem was that the board was not powering the DAC. The register 0x12 accounts for the first 8 bits (not 7), so it's 0001 0010 which is correct. Thanks for your help.
Anyone knows what is required to make Android Things work with this board? e.g https://www.mikroe.com/audio-codec-proto-board
Thank you