cancel
Showing results for 
Search instead for 
Did you mean: 

The I2C BlueNRG-1 always got 16 bytes.

TWu.6
Associate II

Hi Friend,

I used the I2C of BlueNRG-1 as slave to receive data. It always got 16 bytes, but my data is more than 16 bytes. The code snippet as follows. Could anyone help me? What's wrong with my code? I saw the data sheet said that I2C had 16-byte depth RX FIFO, but my i2c data frame had 18 bytes.

Thank you in advance.

uint8_t I2C_buffer[20];
 
void I2C_receiving(void)
{
    uint8_t command=0,crc_add=0;
    uint8_t length=0; 
 
#ifdef BLOCK_I2C	
    if (state==BEACONING) //Stop Beacon
    {
        aci_gap_set_non_discoverable();
        ST_PRINTF("IS Beacon Return!!!!!! \r\n");
        return;		
    }
#endif
	
    HAL_VTimer_Stop(BEACON_DURACTION_TIMER);
    HAL_VTimer_Stop(BEACON_LASTPACKET_TIMER);
    memset(I2C_buffer,0,sizeof(I2C_buffer)); //Clean I2C Buffer
 
    /* Write-to-slave request received */
    while (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_WTSR) == RESET)
    {
        if(GPIO_ReadBit(GPIO_Pin_12))
            return;
     }
 
    /* Write-to-slave request received */
    if (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_WTSR) == SET)
    {
        ST_PRINTF("\r\n");
        ST_PRINTF("I2C Received Data : Data = ");
 
        /* Wait till I2C transaction is finished */
        while (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_STD) == RESET);
 
        /* Length of the received data */
        length = ((I2C_Type*)SDK_EVAL_I2C)->SR_b.LENGTH; 
  
        for (int i = 0; i < length; i++) {
            command = I2C_ReceiveData((I2C_Type*)SDK_EVAL_I2C);
            I2C_buffer[i]=command;
            ST_PRINTF("%02x ", I2C_buffer[i]);
        }
 
        /* Flush RX FIFO */
        I2C_FlushRx((I2C_Type*)SDK_EVAL_I2C);
        while (I2C_WaitFlushRx((I2C_Type*)SDK_EVAL_I2C) == I2C_OP_ONGOING)
            ;
 
        /** Clear operation completed flag */
        I2C_ClearITPendingBit((I2C_Type*)SDK_EVAL_I2C, I2C_IT_STD);
 
        memcpy (&BLE_TPMS_I2C_Data,&I2C_buffer[1],15);	    		
....
 
}

2 REPLIES 2
Winfred LU
ST Employee

As you've known, the both RX and TX FIFOs are 16-byte depth.

So in order to receive larger size of data properly, you shall implement a check of the RX FIFO flags instead.

Something like the following, for the case that RX FIFO threshold set to 1.

while (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_STD) == RESET) {
  if (I2C_GetITStatus((I2C_Type*)SDK_EVAL_I2C, I2C_IT_RXFNF) == SET) {
    buf = I2C_ReceiveData((I2C_Type*)SDK_EVAL_I2C);
      printf("%02x ", buf);
    }
}
 
len = ((I2C_Type*)SDK_EVAL_I2C)->SR_b.LENGTH;
printf("%d bytes received totally\r\n", len);

Hi Winfred,

Thank you very much.