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
Hello iamno3,
In this line
iic_info_m.p_slv_adr = addr_IOCtrl + 1;
why do you add 1 to the address? Is it the real address of the device or are you trying to add the "Read" bit to it? In the last case I think you don't need to do this, as it is added by the hardware. For more information please refer to this application note https://www.renesas.com/us/en/document/apn/rx-family-i2c-bus-interfaceriic-module-using-firmware-integration-technology-rev260#%5B%7B%22num%22%3A99%2C%22gen%22%3A0%7D%2C%7B%22name%22%3A%22XYZ%22%7D%2C56%2C764%2Cnull%5D.
Kind regards,
Sergey
If this response, or one provided by another user, answers your question, please verify the answer. Thank you!
Renesas Engineering Community Moderatorhttps://community.renesas.com/https://academy.renesas.com/https://en-support.renesas.com/knowledgeBase/
Hello Sergey,
Thank you for reply.
addr_IOCtrl is pointer to array so addr_IOCtrl + 1 is ADDR_IOCTRL_FRONT address value.
addr_IOCtrl
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 */ }