R_RIIC_MasterReceive function is stuck.

Hello,

I have device IO expander TCA9535PWR with address 0x21. When MCU try to set output to the device it's works.

But when try to read Input, iic_info_m.dev_sts status is always RIIC_COMMUNICATION. So it's stuck in while loop.

Here my code :

#define ADDR_IOCTRL_FRONT		0x21
#define ADDR_IOCTRL_REAR		0x20

BYTE addr_IOCtrl[2] = { ADDR_IOCTRL_REAR, ADDR_IOCTRL_FRONT  };

BYTE readInput_Front()
{
	volatile riic_return_t ret; /* Return value */
	BYTE receive_data[8] = { 0xFF };

	iic_info_m.dev_sts = RIIC_NO_INIT;	//Device state flag
	iic_info_m.p_slv_adr = addr_IOCtrl + 1; /* Pointer to the slave address Front IO Expander */
	iic_info_m.p_data1st = RegAddr; /* Pointer to Register Input Port 0 */
	iic_info_m.cnt1st = 1;
	iic_info_m.p_data2nd = receive_data;
	iic_info_m.cnt2nd = 1;
	iic_info_m.callbackfunc = &CallbackMaster;

	ret = R_RIIC_Open(&iic_info_m);
	/* RIIC receive start */
	ret = R_RIIC_MasterReceive(&iic_info_m);
	if (RIIC_SUCCESS == ret)
	{
		while(	 != iic_info_m.dev_sts); //Stuck here
	}
	else
	{
		/* error */
	}

	ret = R_RIIC_Close(&iic_info_m);
	/* RIIC receive complete */
	return receive_data[1];

}

Could you help me ??

Thank you

Parents Reply
  • Hello Sergey,

    Thank you for reply.

    addr_IOCtrl is pointer to array so addr_IOCtrl + 1 is ADDR_IOCTRL_FRONT address value.

    I think problem is with IO expander it self. Sample code already work. One IC can read input but other one cannot read.

    EDIT

    I found the cause , when call R_RIIC_MasterReceive function from interrupt it will get stuck but when call it from loop run normal and can read Input correctly.

    It's look like this

    void r_Config_ICU_irq6_interrupt(void)
    {
        /* Start user code for r_Config_ICU_irq6_interrupt. Do not edit comment generated here */
    	//Read Front switch and light on led switch
    	BYTE input = 0;
    
    	input = readInput_Front();  //stuck after call R_RIIC_MasterReceive
    	//Light LED Switch
    	setOutput_Front(input);
        /* End user code. Do not edit comment generated here */
    }

Children
No Data