Logo
UNICENS V2.1.0-3491
User Manual and API Reference
Ucs_Return_t Ucs_I2c_CreatePort ( Ucs_Inst_t self,
uint16_t  destination_address,
uint8_t  index,
Ucs_I2c_Speed_t  speed,
uint8_t  i2c_int_mask,
Ucs_I2c_CreatePortResCb_t  result_fptr 
)

Creates an I2C Port with its associated parameter.

 This function corresponds with the INIC function INIC.I2CPortCreate.
Parameters
selfThe UNICENS instance pointer
destination_addressAddress of the target device. Use the UCS_ADDR_LOCAL_DEV macro to target the local device.
The following address ranges are supported:
  • [0x10 ... 0x2FF]
  • [0x500 ... 0xFEF]
  • UCS_ADDR_LOCAL_DEV
indexI2C Port instance.
 Index
speedThe speed grade of the I2C Port.
 Speed
i2c_int_maskThe bit mask corresponding to the I2C-interrupt on the GPIO Port.
result_fptrRequired result callback function pointer.
Returns
Possible return values are shown in the table below.
Value Description
UCS_RET_SUCCESS No error
UCS_RET_ERR_PARAM At least one parameter is NULL
UCS_RET_ERR_BUFFER_OVERFLOW No message buffer available
UCS_RET_ERR_API_LOCKED API is currently locked
UCS_RET_ERR_NOT_INITIALIZED UNICENS is not initialized
Attention
The below points should be considered in order to receive the notification of the I2C interrupt:
  • The Ucs_I2c_IntEventReportCb_t callback function should be registered in the Ucs_InitData_t init structure.
  • The GPIO port has to be be opened and the I2C interrupt pin associated with that port configured correctly.


Example

#define I2C_INT_PIN_MASK ((uint8_t)0x01)
// Main function
void main()
{
Ucs_Return_t result = Ucs_I2c_CreatePort(0x556U, 0x00U, UCS_I2C_FAST_MODE, I2C_INT_PIN_MASK, &App_I2cCreatePortResCb);
if (result != UCS_RET_SUCCESS)
{
// Error handling here
}
}
// Handle I2cCreatePort event
static void App_I2cCreatePortResCb(uint16_t device_id, uint16_t port_handle, Ucs_I2c_Result_t result, void * user_ptr)
{
if (result.code == UCS_I2C_RES_SUCCESS)
{
// Store received port handle
}
else
{
// Error handling here
}
}