在线时间4 小时
UID3942499
注册时间2023-9-23
NXP金币0
该用户从未签到
新手上路
- 积分
- 45
- 最后登录
- 2023-12-5
|
我使用S32K144芯片,使用s32ds开发环境。使用i2c的时候,在示例项目中已经调通,但放到生产项目的时候,执行I2C_MasterSendDataBlocking函数的时候,返回状态STATUS_I2C_ARBITRATION_LOST,执行失败。执行的代码市一致的,生产项目中多了很多其他的外设使用,但是在代码中还没调用。
下面是关键代码:
[color=#**da]
static bool isInit = false;
void my_i2c_init()
{
if (isInit)
return;
/* Initialize LPI2C Master configuration
* - Slave address 0x01
* - Fast operating mode, 400 KHz SCL frequency
* - See LPI2C components for configuration details
*/
I2C_MasterInit(&i2c1_instance, &i2c1_MasterConfig0);
isInit = true;
}
bool my_i2c_read_bytes(uint8_t chip_addr, uint8_t data_addr, uint8_t *out_buff, uint8_t len)
{
if (!isInit)
my_i2c_init();
status_t status;
I2C_MasterSetSlaveAddress(&i2c1_instance, chip_addr, false);
status = I2C_MasterSendDataBlocking(&i2c1_instance, &data_addr, 1, true, OSIF_WAIT_FOREVER);
DEV_ASSERT(status == STATUS_SUCCESS);
/* Request data from the bus slave */
status = I2C_MasterReceiveDataBlocking(&i2c1_instance, out_buff, len, true, OSIF_WAIT_FOREVER);
DEV_ASSERT(status == STATUS_SUCCESS);
return status == STATUS_SUCCESS;
}
/*!
\brief The main function for the project.
\details The startup initialization sequence is the following:
* - startup asm routine
* - main()
*/
int main(void)
{
/* Variable used for status of changing mode */
status_t retV = STATUS_SUCCESS;
/* Allocate memory for the LPI2C driver state structure */
lpi2c_master_state_t lpi2c1MasterState;
/* Declaration of the LPI2C transfer buffer */
uint8_t buffer[TRANSFER_SIZE];
/* Variable used for the loop that initializes the data buffer */
uint16_t i;
/*** Processor Expert internal initialization. DON'T REMOVE THIS CODE!!! ***/
#ifdef PEX_RTOS_INIT
PEX_RTOS_INIT(); /* Initialization of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of Processor Expert internal initialization. ***/
/* Initialize and configure clocks
* - Configure system clocks and dividers
* - Configure LPI2C clock gating
* - see clock manager component for details
*/
CLOCK_SYS_Init(g_clockManConfigsArr, CLOCK_MANAGER_CONFIG_CNT,
g_clockManCallbacksArr, CLOCK_MANAGER_CALLBACK_CNT);
CLOCK_SYS_UpdateConfiguration(0U, CLOCK_MANAGER_POLICY_AGREEMENT);
/* Initialize pins
* - Configure LPI2C pins
* - See PinSettings component for more info
*/
PINS_DRV_Init(NUM_OF_CONFIGURED_PINS, g_pin_mux_InitConfigArr);
for (i = 0u; i < TRANSFER_SIZE; i++)
{
my_i2c_read_bytes(0x77, 0x10 + i, &buffer[i], 1);
// buffer[0] = 0x10 + i;
// LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, buffer, 1, true, OSIF_WAIT_FOREVER);
// buffer = 0u;
// /* Request data from the bus slave */
// LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buffer, 1, true, OSIF_WAIT_FOREVER);
}
/* End of the driver example */
/*** Don't write any code pass this line, or it will be deleted during code generation. ***/
/*** RTOS startup code. Macro PEX_RTOS_START is defined by the RTOS component. DON'T MODIFY THIS CODE!!! ***/
#ifdef PEX_RTOS_START
PEX_RTOS_START(); /* Startup of the selected RTOS. Macro is defined by the RTOS component. */
#endif
/*** End of RTOS startup code. ***/
/*** Processor Expert end of main routine. DON'T MODIFY THIS CODE!!! ***/
for(;;) {
if(exit_code != 0) {
break;
}
}
return exit_code;
/*** Processor Expert end of main routine. DON'T WRITE CODE BELOW!!! ***/
} /*** End of main routine. DO NOT MODIFY THIS TEXT!!! ***/
|
|