音声認識ボードのI2C slave動作の代わりをEPS 32で試行しました。
コードはこんな感じです。
#define I2C_BUFFER_LENGTH 16 #include "Wire.h" #define I2C_SDA 14 #define I2C_SCL 12 #define I2C_DEV_ADDR 0x28 uint32_t i = 0; uint32_t sts_f_req = 0; uint32_t cmd_f_req = 0; uint32_t cmd_i = 0; uint32_t cmd_sed_f = 100; uint32_t cmd_sed_fast_f = 1; uint8_t cmd_table[10] = { 26 , 27 , 39 , 41 , 35 , 90 , 23 , 125 , 25 }; TwoWire I2CSensors = TwoWire(0); uint8_t onnseists[3] = { 0x00, 0x00, 0x00 }; uint8_t onnseicmd[2] = { 0x00, 0x00 }; void onRequest(){ if (sts_f_req == 1 ) { if (cmd_sed_f != 0 ) { onnseicmd[1] = cmd_i ; cmd_sed_f -- ; Serial.printf("onRequest sts int in %x",onnseicmd[1]); Serial.println(""); } else { onnseicmd[1] = 00 ; } I2CSensors.slaveWrite(onnseicmd,2); } if (cmd_f_req == 1 ) { if ( cmd_sed_f != 0 ) { onnseists[2] = 0x01 ; } else { onnseists[2] = 0x00 ; } I2CSensors.slaveWrite(onnseists,3); } } void onReceive(int len){ while(I2CSensors.available()){ char robi_cmd_data = I2CSensors.read(); if ( robi_cmd_data == 0x0c ) { sts_f_req = 1; } else { sts_f_req = 0; } if ( robi_cmd_data == 0x20 ) { cmd_f_req = 1; } else { cmd_f_req = 0; } } Serial.println(); } void setup() { Serial.begin(115200); Serial.setDebugOutput(true); I2CSensors.onReceive(onReceive); I2CSensors.onRequest(onRequest); Serial.println("onXend"); delay(10000); Serial.println("delayend"); I2CSensors.begin((uint8_t)I2C_DEV_ADDR,I2C_SDA,I2C_SCL,400000); Serial.println("setupend"); } void loop() { uint8_t i; cmd_i =0 ; cmd_sed_f = 100; delay(1000); for (i=0; i < 10 ; i++ ) { cmd_sed_f = 100 ; Serial.printf("Robi i2c cmd %d ",cmd_table[i]); Serial.println(); if (cmd_sed_fast_f == 1) { cmd_i = cmd_table[i]; cmd_sed_fast_f =0; } else { cmd_i = cmd_table[i] ; } delay(10000); } }
シリアルのログはこんな感じです。
18:53:36.392 -> rst'⸮⸮ (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT) 18:53:36.392 -> configsip: 0, SPIWP:0xee 18:53:36.392 -> clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00 18:53:36.426 -> mode:DIO, clock div:1 18:53:36.426 -> load:0x3fff0030,len:1344 18:53:36.426 -> load:0x40078⸮⸮bb⸮⸮⸮13516 18:53:36.426 -> load:0x40080400,len:3604 18:53:36.426 -> entry 0x400805f0 18:53:36.524 -> [⸮⸮mum⸮⸮⸮⸮2-hal-cpu.c:214] setCpuFrequencyMhz(): PLL: 480 / 2 = 240 Mhz, APB: 80000000 Hz 18:53:37.376 -> [ 842][I][esp32-hal-psram.c:96] psramInit(): PSRAM enabled 18:53:37.414 -> onXend 18:53:47.401 -> delayend 18:53:47.401 -> [ 10881][I][esp32-hal-i2c-slave.c:234] i2cSlaveInit(): Initialising I2C Slave: sda=14 scl=12 freq=400000, addr=0x28 18:53:47.401 -> [ 10881][D][esp32-hal-i2c-slave.c:498] i2c_slave_set_frequency(): Fifo thresholds: rx_fifo_full = 20, tx_fifo_empty = 12 18:53:47.450 -> setupend 18:53:47.450 -> onRequest sts int in 0 ... 18:53:48.430 -> Robi i2c cmd 26 18:53:48.430 -> 18:53:48.430 -> 18:53:48.430 -> onRequest sts int in 1a 18:53:48.430 -> 18:53:48.430 -> 18:53:48.430 -> onRequest sts int in 1a 18:53:48.430 -> 18:53:48.463 -> 18:53:48.463 -> onRequest sts int in 1a 18:53:48.463 -> 18:53:48.463 -> 18:53:48.463 -> onRequest sts int in 1a 18:53:48.463 -> 18:53:48.498 -> 18:53:48.498 -> onRequest sts int in 1a 18:53:48.498 -> 18:53:48.498 -> 18:53:48.498 -> onRequest sts int in 1a ...
初期のリード 認識語のリード