1.35.17.3 TWIx_TransferSetup Function

C

/* x = TWI instance number */

/* TWI master mode */
bool TWIx_TransferSetup(TWI_TRANSFER_SETUP* setup, uint32_t srcClkFreq)

Summary

Dynamic setup of TWI Peripheral.

Description

This API is generally used when there are multiple clients on the same TWI bus having different clock speed. In such a case, the TWIx_TransferSetup API must be called to set the appropriate bus speed before starting the TWI transfer for the TWI slave.

Precondition

TWIx_Initialize must have been called for the associated TWI instance. The transfer status should not be busy.

Parameters

Param Description
setup Pointer to the structure containing the transfer setup.
srcClkFreq TWI Peripheral Clock Source Frequency.

Returns

true - Transfer setup was updated Successfully.

false - Failure while updating transfer setup.

Example

TWI_TRANSFER_SETUP setup;

setup.clkSpeed = 400000;

// Make sure that the TWI is not busy before changing the TWI clock frequency
if (TWI1_IsBusy() == false)
{
    if (TWI1_TransferSetup( &setup, 0 ) == true)
    {
        // Transfer Setup updated successfully
    }
}

Remarks

srcClkFreq overrides any change in the peripheral clock frequency. If configured to zero PLIB takes the peripheral clock frequency from MHC.