NHS3152 I2C Slave data reception

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

NHS3152 I2C Slave data reception

508 Views
rantanplan
Contributor I

Hello,

I'm trying to write several bytes to the NHS3152 acting as I2C slave. Unfortunately, the I2C_EVENT_DONE is called already after the second byte.

I checked the example app_example_dp_i2c in the SDK v12.4 and saw that the RXEventHandler is now different to the previous version.

static void Slave_EventHandler(I2C_ID_T id, I2C_EVENT_T event)
{
    ASSERT(id == I2C0);
    (void)id; /* suppress [-Wunused-parameter]: only one value is possible, which is unused below. */
    if (event == I2C_EVENT_SLAVE_RX) {
       // LED_On(LED_ALL);
        /* A byte has been received. The bytes sent by the master indicate in our application the offset from which
         * to start reading.
         */
        int offset = (int)((sRxBuffer[0] + ((unsigned int)sRxBuffer[1] << 8)) % sizeof(sText));
        sXfer.txBuff = &sText[offset];
        sXfer.txSz = (offset + I2C_SLAVE_TX_SIZE < (int)sizeof(sText)) ? I2C_SLAVE_TX_SIZE : ((int)sizeof(sText) - offset + 1);
    }

 

Here it is stated that one byte is received, but sRxBuffer[0] and sRxBuffer[1], which are actually 2 bytes, are processed. So how do I know how many bytes have been received?

In the older versions of the SDK, the data reception is handled in the following function:

/**
 * Helper function to handle slave data reception.
 * @param slaveMem : Pointer to Slave memory being accessed.
 * @param slaveMemOffset : Pointer to current Offset for the Slave Memory being accessed.
 * @param slaveMemSize : Size of Slave Memory being accessed.
 * @param slaveRxBuf : Pointer to Rx buffer where data is received.
 */
static void HandleSlaveRx(uint8_t* slaveMem, uint32_t* slaveMemOffset, uint32_t slaveMemSize, uint8_t* slaveRxBuf)
{
    if (sSlaveRxIndex == 0) {
        /* The first byte is the offset */
        *slaveMemOffset = slaveRxBuf[sSlaveRxIndex++];
    }
    else if (*slaveMemOffset < slaveMemSize) {
        /* Copy the received byte into the location specified by the offset */
        slaveMem[(*slaveMemOffset)++] = slaveRxBuf[sSlaveRxIndex++];
    }
    if (*slaveMemOffset == slaveMemSize) {
        *slaveMemOffset = 0;
    }
}

Nevertheless, this function is only called twice before I2C_EVENT_DONE is received, no matter how many data I'm sending in the I2C write command.

I would be very thankful for any hints.

Many thanks in advance.

 

0 Kudos
2 Replies

469 Views
rantanplan
Contributor I

Hi Mario, 

thanks for the reply. I suppose they set the threshold level for the RX_BUFFER to 2. 

Anyways, I had a hardware issue on the I2C lines, which I solved now and modified the I2C example from SDK 11.2.

485 Views
mario_castaneda
NXP TechSupport
NXP TechSupport

Hi @rantanplan,

I hope you are doing great.

I am not sure about the application that you are doing but, the code mentions that the RX Buffer Size must be greater than 2.

#if I2CIO_RX_BUFFER_SIZE && I2CIO_RX_BUFFER_SIZE < 2
#error I2CIO_RX_BUFFER_SIZE must be at least 2.
#endif

Regards,

Mario

 

0 Kudos