• AVR Freaks

DRV_I2C_WriteReadTransfer function seems to be not blocking

Author
thoraz
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2013/06/01 18:37:43
  • Location: 0
  • Status: offline
2020/06/24 05:11:27 (permalink)
0

DRV_I2C_WriteReadTransfer function seems to be not blocking

I configured I2C driver via MHC in Harmony 3 as synchronous (blocking), but when I use the DRV_I2C_WriteReadTransfer function it seems to be not blocking. If I use it inside my routine
 
static uint8_t i2cTxBuff[ MAX_I2C_TX_BUFFER_SIZE ];
static uint8_t i2cRxBuff[ MAX_I2C_RX_BUFFER_SIZE ];

SYSTEM_ERROR_TYPE ADAU1961_Read_Register( uint16_t registerAddr, uint8_t *registerValue )
{
    i2cTxBuff[ 0 ] = ( uint8_t )( ( registerAddr >> 8 ) & 0x00FF );
    i2cTxBuff[ 1 ] = ( uint8_t )( registerAddr & 0x00FF );
    i2cRxBuff[ 0 ] = 0;

    if( DRV_I2C_WriteReadTransfer( codecData.codecDrvI2CHandle, ADAU1961_I2C_ADDRESS, ( void * )i2cTxBuff, 2, ( void * )i2cRxBuff, 1 ) == false )
    {
        SYSTEM_DBG_PRINT( SYSTEM_DBG_LEVEL_ERROR, "\nERROR: ADAU1961 read DRV_I2C_WriteReadTransfer" );
        return SYSTEM_ERROR;
    }

    *registerValue = i2cRxBuff[ 0 ];

    return SYSTEM_NO_ERROR;
}


and then call my routine somewhere in my application
 
if ( SYSTEM_ERROR == ADAU1961_Read_Register( ADAU1961_REG_R39_SERPP, &value ) )
    SYSTEM_PRINT( "\nERROR read ADAU1961_REG_R39_SERPP register" );
else
    SYSTEM_PRINT( "\nvalue: %X", value );


the value it returns is always 0. But if I comment the line i2cRxBuff[ 0 ] = 0; my routine become
 
static uint8_t i2cTxBuff[ MAX_I2C_TX_BUFFER_SIZE ];
static uint8_t i2cRxBuff[ MAX_I2C_RX_BUFFER_SIZE ];

SYSTEM_ERROR_TYPE ADAU1961_Read_Register( uint16_t registerAddr, uint8_t *registerValue )
{
    i2cTxBuff[ 0 ] = ( uint8_t )( ( registerAddr >> 8 ) & 0x00FF );
    i2cTxBuff[ 1 ] = ( uint8_t )( registerAddr & 0x00FF );
//     i2cRxBuff[ 0 ] = 0; <------------------------------ THIS LINE IS NOW IGNORED!!!

    if( DRV_I2C_WriteReadTransfer( codecData.codecDrvI2CHandle, ADAU1961_I2C_ADDRESS, ( void * )i2cTxBuff, 2, ( void * )i2cRxBuff, 1 ) == false )
    {
        SYSTEM_DBG_PRINT( SYSTEM_DBG_LEVEL_ERROR, "\nERROR: ADAU1961 read DRV_I2C_WriteReadTransfer" );
        return SYSTEM_ERROR;
    }

    *registerValue = i2cRxBuff[ 0 ];

    return SYSTEM_NO_ERROR;
}


and the read value is the one of the previous call: first time I call it the read value is 0 (initializzation value)only succesivelly the correct one (read in the previous call).
Where is the problem? Is it a normal behaviour?
#1
vgandhi
Senior Member
  • Total Posts : 36
  • Reward points : 0
  • Joined: 2016/10/24 21:28:35
  • Location: 0
  • Status: online
Re: DRV_I2C_WriteReadTransfer function seems to be not blocking 2020/06/24 05:31:27 (permalink)
0
@AndrewLivesChaos , the synchronous APIs of the driver are currently supported in RTOS environment only. Have you added/enabled RTOS into your project? Refer to the I2C driver documentation here -> https://microchip-mplab-h...hub.io/core/00123.html
#2
thoraz
Junior Member
  • Total Posts : 100
  • Reward points : 0
  • Joined: 2013/06/01 18:37:43
  • Location: 0
  • Status: offline
Re: DRV_I2C_WriteReadTransfer function seems to be not blocking 2020/06/24 07:43:03 (permalink)
0
vgandhi
@AndrewLivesChaos , the synchronous APIs of the driver are currently supported in RTOS environment only. Have you added/enabled RTOS into your project? Refer to the I2C driver documentation here -> https://microchip-mplab-h...hub.io/core/00123.html




Oh, you are right! I'm not using an RTOS emvironment and I didn't read the constrain about the synchronous  functions. Thanks for your fast response. 
#3
Jump to:
© 2020 APG vNext Commercial Version 4.5