This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I tried Loopback mode for self test with below code
/* USER CODE BEGIN (2) */
#define own_add 0x75
#define slv_add 0x5A
#define bsize 8
uint8 TX_PACK[16]={0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,0x5A,0x5B,0x5C,0x5D,0x5E,0x5F,0x5A,0x5B,0x5C,0x5D};
uint8 RX_PACK[16]={0};
uint32 data;
void i2cEnableLoopback(i2cBASE_t *i2c);
/* USER CODE END */
int main(void)
{
/* USER CODE BEGIN (3) */
uint32 buf_size = bsize, i, errNum;
uint8 *t_buff = &TX_PACK[0];
uint8 *r_buff = &RX_PACK[0];
/* i2c initialization */
i2cInit();
/* set i2c own address */
i2cSetOwnAdd(i2cREG1,own_add);
/* enable internal loopback */
i2cEnableLoopback(i2cREG1);
/* Initiate Start condition for Transmission */
i2cSetStart(i2cREG1);
/* send data packets */
while(buf_size--)
{
i2cSendByte(i2cREG1,*t_buff++);
/* receive data packets */
*r_buff++ = i2cReceiveByte(i2cREG1);
asm(" nop"); //for breakpoint
}
errNum = 0;
for (i=0; i<bsize; i++){
if (RX_PACK[i] != RX_PACK[i])
errNum++;
}
/* Clear Stop Condition detect flag */
i2cClearSCD(i2cREG1);
while(1){}; /* wait forever after tx-rx complete. */
/* USER CODE END */
return 0;
}
in RX buffer, only first byte is copied .
RX_PACK[16]={0x5A,0x0,0x0,.........}
then code gets struck at below line
while ((i2c->STR & (uint32)I2C_RX_INT) == 0U)
{
} /* Wait */
inside uint8 i2cReceiveByte(i2cBASE_t *i2c) function.
What could be problem?
2) Please find the attached snapshot
what is meaning of "stop condition is generated by the device"?
how it impact the coding?
Hello,
I2C bus drivers are open-collect or open-drain, meaning that they can pull the corresponding signal line low, but cannot drive it high. To make the I2C work, external pull-up resistors are required for I2C lines.
I teste don my board, the loopback works as expected. Please check if the I2C lines on your board are pulled up.