i find this LPI2C_DRV_MasterSendDataBlocking can't used under freertos task,
read is always return 2, seems when write i2c is always busy, can anybody help to check it ?
i2c_test11,TMF882X_STAT=0
tmf882x_i2c_write ret=0
tmf882x_i2c_read,fisrt ret1=0,second ret2=2,recv=0
BTW, when use without freertos i can read i2c slave data correctly.
int test_tmf882x_i2c_read(uint32_t slave_addr, uint8_t reg, uint8_t *buf, int len)
{
//return read_i2c_block(slave_addr, reg, buf, len);
int ret1,ret2;
ret1 = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, ®, 1, false, I2C_TIME_OUT);
ret2 = LPI2C_DRV_MasterReceiveDataBlocking(INST_LPI2C1, buf, len, true,I2C_TIME_OUT);
AMS_TOF_LOG("tmf882x_i2c_read,fisrt ret1=%d,second ret2=%d,recv=%d\n",ret1,ret2,*buf);
return ret2;
}
int test_tmf882x_i2c_write(uint32_t slave_addr, uint8_t reg, uint8_t *buf, int len)
{
int i,ret;
uint8_t send[len+1];
send[0] = reg;
if(len == 1)
send[len] = *buf;
else
{
for(i=0;i<len;i++)
send[i+1] = buf[i];
}
ret = LPI2C_DRV_MasterSendDataBlocking(INST_LPI2C1, send, len+1, true,I2C_TIME_OUT);
AMS_TOF_LOG("tmf882x_i2c_write ret=%d\n",ret);
return 0;
}
void i2c_test11()
{
uint8_t send[2];
uint8_t recv[2];
recv[0] = 0x80;
recv[1] = 0x90;
uint8_t regval = 0;
LPI2C_DRV_MasterSetSlaveAddr(INST_LPI2C1,0x39,false);
while(1)
{
regval = 0x03;
test_tmf882x_i2c_write(0x39,0x80,®val, 1);
regval = 0x00;
test_tmf882x_i2c_read(0x39,0x80, ®val, 1);
printf("i2c_test11,TMF882X_STAT=%x\n",regval);
}
}
int main (void)
{
//initialize System
lpi2c_master_state_t lpi2c1MasterState;
init_sys ();
//WDOG_disable();
// sensor_interface_init();
LPSPI_DRV_MasterInit(LPSPICOM1,&lpspiCom1State,&lpspiCom1_MasterConfig0);
LPUART_DRV_Init(INST_LPUART1, &lpuart1_State, &lpuart1_InitConfig0);
LPI2C_DRV_MasterInit(INST_LPI2C1, &lpi2c1_MasterConfig0,&lpi2c1MasterState);
enable_fault_handlers(); // If not set, all fault are handled by HardFault_Handler
set_fault_handlers_priority(); // priority: MemManage (1), BusFault (1), UsageFault(1)
LPI2C_DRV_MasterSetSlaveAddr(INST_LPI2C1,I2C_SLAVEADDR,false);
INT_SYS_SetPriority( LPI2C0_Master_IRQn, configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 1 );
//while(1)
{
//tof882x_init();
//i2c_test11();
//flash_read_write_test();
}
rtos_start();
return exit_code;
}
can any NXP mcu team members help this case, thanks!
i attached the project here, two issues
1. i2c always busy with rtos(without rtos i2c read data ok)
logs below:
prvQueueSendTask=0
test_i2c000 tmf882x_i2c_read,fisrt ret1=2,second ret2=2,recv=0
prvQueueSendTask,value=0
prvQueueReceiveTask=0
prvQueueSendTask=0
test_i2c000 tmf882x_i2c_read,fisrt ret1=2,second ret2=2,recv=0
prvQueueSendTask,value=0
prvQueueReceiveTask=0
2. when add more task , like prvTestTask / prvNewTestTask, it will blocked, i think it should be printf issue.
please help to check it, thank you!
Hi @alice_th,
I saw that you haven't yet installed the "LPI2C0_Master_IRQHandler" (interrupt function) for I2C Master.
Could you install this interrupt function and re-test your example?
Best regards,
Dan
Hello @alice_th,
Please provide the name of the S32DS versions you are using.
And what are the FreeRTOS package's name and the S32K1 package's name you are using?
Best regards,
Dan
S32 Design Studio for ARM
Version: 2.2
Build id: 200116
Copyright Freescale Semiconductor 2016. All rights reserved.
Copyright 2017-2020 NXP
Hi @alice_th,
I can't find out the link to download the FreeRTOS 10.0.1 version on the NXP.com
Maybe this version is too old. Could you update to use FreeRTOS 10.4.6 (the latest version) instead of 10.0.1 version? If not, please send me the link to download FreeRTOS 10.0.1 version and the SDK package you are using.
Best regards,
Dan
sdk is too big, can't attached, only support 25M
below is what we have
C:\NXP\S32DS_ARM_v2.2\S32DS\software\S32SDK_S32K1xx_RTM_3.0.0
any update or can you help test the project which i already attached to find what is the problem,
thanks a lot!
Hi @alice_th,
If you have an interrupt function in the startup file then you only need to enable LPI2C0_Master_IRQn in your code.
You should put a breakpoint in the LPI2C0_Master_IRQHandler to check whether you can jump into this function or not.
If the LPI2C0 interrupt didn't occur, you should check whether the bits are configured correctly as the below or not.
If not, please modify your configuration to enable the above bits.
Best regards,
Dan
this API LPI2C_DRV_MasterInit already enable irq ,
see below,
Hi @alice_th,
Please double-click into those bits and show me the values of them.
Second, I can't open your configuration to check it because something wrong (I don't know) and so, I enabled the bits in previous comment and it ran OK.
Best regards,
Dan