s32k144 i2c don't work under freertos

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

s32k144 i2c don't work under freertos

1,165 Views
alice_th
Contributor III

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, &reg, 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,&regval, 1);
regval = 0x00;
test_tmf882x_i2c_read(0x39,0x80, &regval, 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;
}

0 Kudos
Reply
7 Replies

1,102 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @alice_th,

The driver must be initialized within a task after the scheduler is started.

Discussed here:

https://community.nxp.com/t5/S32K/S32K142-lpi2c-is-not-working-with-freeRTOS-integration/m-p/875035

 

Regards,

Daniel

0 Kudos
Reply

1,049 Views
alice_th
Contributor III

Hello @danielmartynek 

thank you, init i2c after vTaskStartScheduler i2c works fine.

there is another issues, when create 4 task to test printf, it will stock. when create 2 task to test printf it works fine.

please see attached code, could you please have a look, thank you!

alice_thanks_0-1693812035009.png

 

Tags (1)
0 Kudos
Reply

1,042 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @alice_th,

Since this is not related to the I2C issue, can you create a new thread?

 

Thanks,

Daniel

0 Kudos
Reply

1,040 Views
alice_th
Contributor III

Hi @danielmartynek 

actually i raise it before, but no response, can you check it with below link, thanks.

how to process multi-task access printf ? - NXP Community

0 Kudos
Reply

1,009 Views
danielmartynek
NXP TechSupport
NXP TechSupport

Hi @alice_th,

A colleague of mine is assigned to it.

I have sent a reminder.

 

Regards,

Daniel

0 Kudos
Reply

1,164 Views
alice_th
Contributor III
 
0 Kudos
Reply

1,163 Views
alice_th
Contributor III

see attached code

0 Kudos
Reply