I2C Integration Guide*
The main control chip/host acts as an I2C Master device and can perform the following operations by reading and writing to specified addresses and registers:
- Read events
- Reset
- Get version number
- Test link
GX8002 provides two I2C Slave devices: 0x2F
and 0x36
, both devices share the same SCL and SDA pins on the bus.
Device Address | Register (8-bit data) | Description | Operation |
0x2F | 0xA0, 0xA4, 0xA8, 0xAC | Data registers used to store events, status, parameters, and other data | Read/Write |
0xC4 | Interrupt register; writing non-zero data to this register will trigger an interrupt in GX8002 | Write | |
0xB0 | Reset register; writing 1 to this register will reset GX8002 (this reset will not clear some I2C0's own registers). If only B0 is written with 01, in some cases, the reset will fail. The complete procedure should be: I2C address 2F, register 9C write A5; D0 write 5A; CC write 04; B0 write 01, which can achieve a reset in any situation | Write | |
0x36 | None | Firmware download channel | Write |
GX8002 follows the standard 7-bit address I2C operation mode:
- Write
- Read
- Write / Read with repeated start
For slave devices with registers, Write mode must be used to send the register address to specify the register to operate. For reading operations, after sending the register address, switch to Read mode using the repeated start signal.
1. Device Address*
Using a 7-bit address, the address is: 0x2F.
For reading data, the read/write bit is 0, so 7-bit address + read/write bit 0
becomes 0x5E.
For writing data, the read/write bit is 1, so 7-bit address + read/write bit 1
becomes 0x5F.
2. Read Events*
2.1 Read Events*
- Read the specified register
0xA0
of device0x2F
to get the event. - Write Confirm information to interrupt register
0xC4
to clear the event after reading. - If events are not read in time, new events will overwrite old ones.
- In specific applications, polling or responding to external GPIO interrupts can be used to read events.
2.2 Voice Events*
GX8002 generates voice events when it detects wake-up words or short commands.
- Register:
0xA0
- Confirm:
0x10
- Event ID (Same as GX8002 Short Command ID):
ID | Event |
---|---|
100 | Main wake-up word |
102 | Pause playback |
103 | Stop playback |
104 | Play music |
105 | Increase volume |
106 | Decrease volume |
112 | Play previous track |
113 | Play next track |
114 | Answer call |
115 | Hang up call |
Note
The ID values above may vary depending on the specific firmware and need to be confirmed with the corresponding engineer.
2.3 Code Example*
void gx8002_read_voice_event(void)
{
unsigned char event_id = 0;
// read voice event: addr = 0x2f, reg = 0xa0
// Read only one byte
i2c_rx_reg(0x2f, 0xa0, &event_id, 1); // Platform-specific I2C interface, pseudo code provided here
if(event_id > 0)
{
unsigned char confirm = 0x10;
// confirm: addr = 0x2f, reg = 0xc4, value = 0x10
// Clear the event, write only one byte
i2c_tx_reg(0x2f, 0xc4, &confirm, 1); // Platform-specific I2C interface, pseudo code provided here
printf("I get voice event ID = %d\n", event_id);
}
}
2.4 Waveform Example*
The event read here is 0x64, which is 100 in decimal.
3. Reset*
3.1 Reset*
Writing 1 to register 0xB0
of device 0x2F
will reset GX8002.
The complete procedure should be: I2C address 2F, register 9C write A5; D0 write 5A; CC write 04; B0 write 01, which can achieve a reset.
Note
If it is an OTA process, be sure to use the hardware reset method. This reset method is a software reset and can only be used when the software function is normal. Considering that there may be exceptions during the OTA process, resulting in the device becoming a "brick," it will need to be re-upgraded, and only a hardware reset can be used in such a situation.
3.2 Code Example*
void gx8002_reset(void)
{
unsigned char val = 1;
i2c_tx_reg(0x2f, 0x9c, &val, 0xa5);
i2c_tx_reg(0x2f, 0xd0, &val, 0x5a);
i2c_tx_reg(0x2f, 0xcc, &val, 0x04);
// reset: addr = 0x2f, reg = 0xb0, value = 1
i2c_tx_reg(0x2f, 0xb0, &val, 0x01);
}
3.3 Waveform Example*
4. Get Version Number*
4.1 Get Version Number*
Write 0x68
to the interrupt register 0xC4
of device 0x2F
, then read
registers 0xA0
, 0xA4
, 0xA8
, and 0xAC
in sequence to get the version number.
For example, the obtained data may be: 0x01, 0x02, 0x03, 0x4, corresponding to version V1.2.3.4.
4.2 Code Example*
void gx8002_get_version(void)
{
unsigned char val = 1;
unsigned char version[4] = {0, 0, 0, 0};
char reg = 0xa0;
i2c_tx_reg(0x2f, 0xc4, &val, 0x68);
//Increase the delay appropriately, as 8002 takes time to write registers after receiving instructions. If the register is read immediately, there is a high probability that the correct value will not be read
mdaly(200);
for(int i = 0; i < 4; ++i){
i2c_rx_reg(0x2f, reg, &ver, 1);
version[i] = ver;
reg += 4;
}
}
4.3 Waveform Example*
5. Get Microphone Status*
5.1 Get Microphone Status*
Write 0x70
to the interrupt register 0xC4
of device 0x2F
, then read
registers 0xA0
in sequence to get the microphone status.
0xA0
status:
code value | illustrate |
---|---|
0 | abnormal |
1 | normal |
5.2 Code Example*
void gx8002_get_mic_state(void)
{
unsigned char val = 1;
int mic_state = 0;
unsigned char reg = 0xa0;
i2c_tx_reg(0x2f,0xc4,&val,0x70);
//ncrease the delay appropriately, as 8002 takes time to write registers after receiving instructions. If the register is read immediately, there is a high probability that the correct value will not be read
mdaly(200);
i2c_rx_reg(0x2f, reg, &ver, 1);
mic_state = ver;
}
5.3 Waveform Example*
6. Test Link*
6.1 Test Link*
- Write
0x80
to the interrupt register0xC4
of device0x2F
to trigger the GX8002 test link interrupt. - Read register
0xAC
, and if it is 1, the test is successful. - After the successful test, write confirmation information
0x11
to the interrupt register0xC4
.
6.2 Code Example*
int gx8002_test_link(void)
{
unsigned char i2c_irq;
unsigned char val = 0;
int tick_cnt = 100;
i2c_irq = 0x80;
i2c_tx_reg(0x2f, 0xc4, &i2c_irq, 1);
while(tick_cnt--) {
gx_os_sleep(10);
i2c_rx_reg(0x2f, 0xac, &val, 1);
if(val == 1) {
i2c_irq = 0x11;
i2c_tx_reg(0x2f, 0xc4, &i2c_irq, 1);
printf("i2c link ok !\n");
break;
}
}
return val;
}
7. open and close Dmic function*
7.1 open and close Dmic function*
Write '0x72' to the interrupt register '0xC4' of the '0x2F' device to open Dmic, and read the status code of register '0xA0'. Is it '0x72'
Write '0x73' to the interrupt register '0xC4' of the '0x2F' device to open Dmic, and read the status code of register '0xA0'. Is it '0x73'
7.2 Code Example*
int gx8002_open_dmic(void)
{
unsigned char i2c_open_dmic_irq = 0x72;
unsigned char val = 0;
int tick_cnt = 100;
i2c_tx_reg(0x2f, 0xc4, &i2c_open_dmic_irq, 1);
while(tick_cnt--) {
gx_os_sleep(10);
i2c_rx_reg(0x2f, 0xa0, &val, 1);
if(val == i2c_open_dmic_irq) {
printf("open dmic ok !\n");
break;
}
}
return 0;
}
int gx8002_close_dmic(void)
{
unsigned char i2c_close_dmic_irq = 0x73;
unsigned char val = 0;
int tick_cnt = 100;
i2c_tx_reg(0x2f, 0xc4, &i2c_close_dmic_irq, 1);
while(tick_cnt--) {
gx_os_sleep(10);
i2c_rx_reg(0x2f, 0xa0, &val, 1);
if(val == i2c_close_dmic_irq) {
printf("close dmic ok !\n");
break;
}
}
return 0;
}
8. Integration Considerations*
- Ensure that the device address is correct. Our address is 7 bits, 0x2F. Customers need to provide the correct address based on their platform's I2C interface. Some platform driver interfaces require 8 bits (manually append the read/write bit), while others require 7 bits and the driver will automatically append the read/write bit.
- For I2C communication, make sure to interact with GX8002 after it has been powered up and stabilized. Generally, wait for 1-2 seconds after GX8002 is powered up before performing interactions.
- During testing, ensure that the GX8002 firmware supports the I2C communication protocol. If not, please communicate with the engineer to obtain the appropriate firmware. Also, ensure that GX8002 is running normally during the testing process. Connect to the GX8002 serial port and check if the Gx8002 firmware supports I2C and is working properly through printing. It is recommended to use our development board for early debugging to avoid hardware and firmware mismatches that may cause debugging issues.
- If the device address is correct and both the hardware and firmware are correct, but communication is still not successful, refer to the provided waveform example to measure the waveform at the SOC's I2C end and compare it with our example. If they are inconsistent, confirm whether the driver is used correctly or there is peripheral hardware interference. If everything is correct and still not working, measure the I2C on the GX8002 end to see if the waveform matches the example. If it does not match, confirm whether there is peripheral hardware interference. Because debugging with the development board was successful in the previous steps, GX8002 software issues can be ruled out at this stage.