|
- errCode = nrf_drv_twi_tx(&s_twiHandle, slaveAddr, ®Addr, 1, true);
- if(errCode != NRF_SUCCESS)
- {
- return 1;
- }
- while((!s_twiTxDone) && --timeout);
- if(!timeout)
- {
- return 2;
- }
- s_twiTxDone = false;
复制代码 用17.0.2的库,写I2C的时候,看波形显示发了两次从机地址再发寄存器地址,这是为什么?以下是配置- void I2C_Init(void)
- {
- uint32_t errCode;
-
- // 初始化TWI配置结构体
- const nrf_drv_twi_config_t twiConfig =
- {
- .scl = BOARD_TWI_SCL_IO, // 配置TWI SCL引脚
- .sda = BOARD_TWI_SDA_IO, // 配置TWI SDA引脚
- .frequency = NRF_DRV_TWI_FREQ_100K, // 配置TWI时钟频率
- .interrupt_priority = APP_IRQ_PRIORITY_HIGH // TWI中断优先级设置
- };
-
- // 初始化TWI
- errCode = nrf_drv_twi_init(&s_twiHandle, &twiConfig, twi_handleEvent, NULL);
- APP_ERROR_CHECK(errCode);
-
- // 使能TWI
- nrf_drv_twi_enable(&s_twiHandle);
- }
复制代码 |
|