Set RIIC0.CR2 to 1 to start RIIC to enter INTRIIC0TI and INTRIIC0TEI interrupts, but both SCL and SDA produce falling edges, while the manual describes that SCL should delay producing falling edges for a while and will enter INTRIIC0EE error interrupts. I used the master mode of the RIIC0 module and selected the Alt2 mode with P10.2 and P10.3 pins. Here are my initialization Settings
INTC2MKRIIC0TI = 1U;
INTC2RFRIIC0TI = 0U;
INTC2TBRIIC0TI = 0U;
INTC2MKRIIC0TEI = 1U;
INTC2RFRIIC0TEI = 0U;
INTC2TBRIIC0TEI = 0U;
INTC2MKRIIC0RI = 1U;
INTC2RFRIIC0RI = 0U;
INTC2TBRIIC0RI = 0U;
INTC2MKRIIC0EE = 1U;
INTC2RFRIIC0EE = 0U;
INTC2TBRIIC0EE = 0U;
RIIC0.CR1.UINT32 &= 0xFFFFFF7FUL;
RIIC0.CR1.UINT32 |= 0x00000040UL;
RIIC0.CR1.UINT32 |= 0x00000080UL;
RIIC0.SER.UINT32 = 0x00000001UL;
RIIC0.MR1.UINT32 |= 0x00000040UL; /* 8MHz / 16 */
RIIC0.BRH.UINT32 = 30; /* 10kbps */ RIIC0.BRL.UINT32 = 20;
// RIIC0.MR1.UINT32 |= 0x00000040UL; /* 40MHz / 8 */
// RIIC0.BRH.UINT32 = 0xF6U; /* 100kbps */ // RIIC0.BRL.UINT32 = 0xF9U;
RIIC0.MR2.UINT32 = 0x00000006UL;
RIIC0.MR3.UINT32 = 0x00000010UL;
RIIC0.FER.UINT32 = 0x00000010UL;
RIIC0.IER.UINT32 = 0x000000E8UL;
/* Alternative function port settings */ /* RIIC0SDA(P10_2:CN1D-110pin) 2'nd Alternative (output/input) */ /* RIIC0SCL(P10_3:CN1D-109pin) 2'nd Alternative (output) */ uint32_t reg32_value = PORTPODC10 | 0x0000000CUL; do { reg32_value = PORTPODC10 | 0x0000000CUL; PORTPPCMD10 = 0xA5U; PORTPODC10 = reg32_value; PORTPODC10 = (uint32_t)(~reg32_value); PORTPODC10 = reg32_value; } while (PORTPPROTS10 != 0x00000000UL); PORTPIPC10 &= 0xFFF3U; // must be 0 PORTPBDC10 |= 0x000CU; PORTPFCAE10 &= 0xFFF3U; PORTPFCE10 &= 0xFFF3U; PORTPFC10 |= 0x000CU; PORTPMC10 |= 0x000CU; PORTPM10 &= 0xFFF3U; PORTPU10 |=0x000C;
/* I2C Bus Interface Internal Reset RIICnCR1 - I2C Bus Control Register 1 b31:b 8 - Reserved set to 0 b 7 ICE - I2C Bus Interface Enable - not change. b 6 IICRST - I2C Bus Interface Internal Reset - Clears the RIIC reset or internal reset. set to 0 b 5 CLO - Extra SCL Clock Cycle Output - not change. b 4 SOWP - SCLO/SDAO Write Protect - not change. b 3 SCLO - SCL Output Control/Monitor - not change. b 2 SDAO - SDA Output Control/Monitor - not change. b 1 SCLI - SCL Line Monitor - not change. b 0 SDAI - SDA Line Monitor - not change. */ RIIC0.CR1.UINT32 &= 0xFFFFFFBFUL;
SetTableBit((uint16*)R_ICRIIC0EE); UnmaskInterrupt((uint16*)R_ICRIIC0EE);
SetTableBit((uint16*)R_ICRIIC0RI); UnmaskInterrupt((uint16*)R_ICRIIC0RI);
SetTableBit((uint16*)R_ICRIICTI0); UnmaskInterrupt((uint16*)R_ICRIICTI0);
SetTableBit((uint16*)R_ICRIICTEI0); UnmaskInterrupt((uint16*)R_ICRIICTEI0);
/*****************************************/
This is my transmitter
void R_IIC_Master_Transmit(uint8 slave_addr, uint32 len , uint8 *transmission_data){
while( RIIC0.CR2.UINT32 & 0x00000080UL ); // Wait to a bus-free state iic_prm.iic_state = ADDR_W_STATE; iic_prm.tx_data_p = transmission_data; iic_prm.tx_len = len; iic_prm.tx_count = 0UL; iic_prm.slave_addr = slave_addr; RIIC0.CR2.UINT32 |= 0x00000002UL; //Startup RIIC
}
Hello,
Which IDE are you using ? If it is e2studio or CS+, you can use the generated code from Smart Configurator for the IIC peripheral.
If you are using MULTI IDE and GHS you can also refer to the generated code for the IIC.
I am using GHS, and the above is the program that refers to the official routine configuration
Please help me analyze the reason and whether there is any problem with my configuration
Hello,this problem is solved,it is the pin problem,thank you very mcuh