/*******************************************************************************
  Function:  ACCEL_RESULT ACCELInitialize(ACCEL_INIT *initialization)
  *****************************************************************************/
ACCEL_RESULT ACCELInitialize(ACCEL_INIT *initialization, uint8_t accl_range)
{
    PLIB_I2C_BaudRateSet(ACCEL_BMA250_I2C_MODULE, initialization->sourceClock, initialization->dataRate);
    PLIB_I2C_Enable(ACCEL_BMA250_I2C_MODULE);

#ifndef ACCEL_USE_EXTERNAL_INTERUPT_HANDLER
#ifndef ACCEL_USE_POLLING
    SYS_INT_VectorPrioritySet(ACCEL_BMA250_I2C_VECTOR,INT_PRIORITY_LEVEL_2);
#endif
#endif

    if(ReadChipID() == ACCEL_INVALID)
        return ACCEL_INVALID;

    SetRangeAndBandwidth(accl_range);

    ReadChipVersion();

    SetThershold();

    SetFIFO();

    accelXYZData.acc_x_lsb.new_data_x = 0;
    accelXYZData.acc_y_lsb.new_data_y = 0;
    accelXYZData.acc_z_lsb.new_data_z = 0;

    return ACCEL_VALID;
}
예제 #2
0
파일: i2c.c 프로젝트: ctapang/v0_70_01b
/*
  Function:
    void initMaster (int baudRate, int clockFrequency)

  Summary:
    Initializes I2C1 module as the master.
*/
void initMaster(int baudRate, int clockFrequency)
{
    PLIB_I2C_TransmitterByteSend(I2C_ID_1, 0);
    PLIB_I2C_SlaveMask7BitSet(I2C_ID_1, 0);
    PLIB_I2C_SlaveAddress7BitSet(I2C_ID_1, 0);

    PLIB_I2C_BaudRateSet(I2C_ID_1, clockFrequency, baudRate);
    PLIB_I2C_Enable(I2C_ID_1);
}
예제 #3
0
// *****************************************************************************
// *****************************************************************************
// Section: Instance 0 static driver functions
// *****************************************************************************
// *****************************************************************************
void DRV_I2C0_Initialize(void)
{
    /* Initialize I2C0 */
    PLIB_I2C_BaudRateSet(I2C_ID_4, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), 50000);
    PLIB_I2C_StopInIdleDisable(I2C_ID_4);

    /* Low frequency is enabled (**NOTE** PLIB function logic reverted) */
    PLIB_I2C_HighFrequencyEnable(I2C_ID_4);

    /* Enable I2C0 */
    PLIB_I2C_Enable(I2C_ID_4);
}
예제 #4
0
// *****************************************************************************
// Section: Instance 0 I2C Master Mode Functions
// *****************************************************************************
void DRV_I2C0_BaudRateSet(I2C_BAUD_RATE baudRate)
{
    /* Disable I2C0 */
    PLIB_I2C_Disable(I2C_ID_4);
    
    /* Change baud rate */
    PLIB_I2C_BaudRateSet(I2C_ID_4, SYS_CLK_PeripheralFrequencyGet(CLK_BUS_PERIPHERAL_1), baudRate);

    /* Low frequency is enabled (**NOTE** PLIB function revereted) */
    PLIB_I2C_HighFrequencyEnable(I2C_ID_4);
 
    /* Enable I2C0 */
    PLIB_I2C_Enable(I2C_ID_4);       
}
예제 #5
0
파일: i2c.c 프로젝트: ctapang/v0_70_01b
/*
  Function:
    void initSlave (int baudRate, int clockFrequency, int address)

  Summary:
    Initializes I2C2 module as the slave.
*/
void initSlave(int baudRate, int clockFrequency, int address)
{
    PLIB_I2C_TransmitterByteSend(I2C_ID_2, 0);
    PLIB_I2C_SlaveMask7BitSet(I2C_ID_2, 0);

    PLIB_I2C_BaudRateSet(I2C_ID_2, clockFrequency, baudRate);
    PLIB_I2C_SlaveAddress7BitSet(I2C_ID_2, address);
    PLIB_I2C_SlaveClockStretchingEnable(I2C_ID_2);
    PLIB_I2C_SlaveClockRelease(I2C_ID_2);

    IEC1 = (1 << 12); // enable i2c2 slave interrupts
    IPC8 = (2 << 10); // priority level to 2

    /* Enable multi-vectored interrupts, enable the generation of interrupts to the CPU */
    PLIB_INT_MultiVectorSelect(INT_ID_0);
    PLIB_INT_Enable(INT_ID_0);

    PLIB_I2C_Enable(I2C_ID_2);
}
예제 #6
0
파일: i2c.c 프로젝트: hackmeopen/Vectr
void initI2C_MGC3130(int baudRate, int clockFrequency){
    PLIB_I2C_BaudRateSet(I2C_MGC3130, clockFrequency, baudRate);
    PLIB_I2C_Enable(I2C_MGC3130);
}