Stuck in while (!nrf_twim_event_check(p_twim, evt_to_wait)) when changing sensor chip based on twi_sensor SDK example.

The example provided in SDK twi_sensor used MPU6050 as TWI slave, I want to use AHT10 which also use TWI to communicate to collect the temperature. After I finished coding the AHT10.c/AHT10.h and main.c and start to  compile and download, there was no error or warning,  However, i found the main function was not running, then i found the program is stuck in a while() in nrf_twim.c, but i didn't use any fuction in that source file but nrf_twi.c,. What should i do to fix that?

following is the while() in nrf_twim.c and some code in my drive of AHT10:

while():

while (!nrf_twim_event_check(p_twim, evt_to_wait))
        {
            if (nrf_twim_event_check(p_twim, NRF_TWIM_EVENT_ERROR))//判断NRF_TWIM_EVENT_ERROR是否已触发,触发返回1
            {
                NRFX_LOG_DEBUG("TWIM: Event: %s.", EVT_TO_STR_TWIM(NRF_TWIM_EVENT_ERROR));
                nrf_twim_event_clear(p_twim, NRF_TWIM_EVENT_ERROR);
                nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_RESUME);
                nrf_twim_task_trigger(p_twim, NRF_TWIM_TASK_STOP);
                evt_to_wait = NRF_TWIM_EVENT_STOPPED;
            }
        }

AHT10.h:

#include "nrf_delay.h"

//I2C引脚定义
#define TWI_SCL_M           25         //I2C SCL引脚
#define TWI_SDA_M           27         //I2C SDA引脚

#define AHT10_ADDRESS_LEN  1         //AHT10地址长度
#define AHT10_ADDRESS     0x38  //AHT10地址
#define AHT10_WHO_AM_I    0x38     //MPU6050 ID


//#define ADDRESS_WHO_AM_I          (0x75) // !< WHO_AM_I register identifies the device. Expected value is 0x68.
#define ADDRESS_SIGNAL_PATH_RESET (0x38) // !<

#define AHT10_WRITE 0x70
#define AHT10_READ 0x71

AHT10.c

#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include "nrf_drv_twi.h"
#include "AHT10.h"

//TWI驱动程序实例ID,ID和外设编号对应,0:TWI0  1:TWI1
#define TWI_INSTANCE_ID     0

//TWI传输完成标志
static volatile bool m_xfer_done = false;
//定义TWI驱动程序实例,名称为m_twi
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);

Related