/****************************************************************************************************
 * @fn      I2C_HardwareSetup
 *          Configures the GPIOs and h/w interface for the I2C bus
 *
 * @param   busId - I2C bus identifier in case multiple buses are supported
 *
 * @return  true if successful, false otherwise.
 *
 ***************************************************************************************************/
osp_bool_t I2C_HardwareSetup( I2C_TypeDef *busId )
{
    if (busId == LPC_I2C0)
    {
        if (sI2C_Bus1Initialized)
        {
            return true;
        }
        /* Configure the I2C interface in Master mode with the given speed */
        Chip_IOCON_PinMuxSet(LPC_IOCON, I2C_SENSOR_BUS_SCL_PIN);
        Chip_IOCON_PinMuxSet(LPC_IOCON, I2C_SENSOR_BUS_SDA_PIN);

        Chip_I2C_Init(busId); /* Enables clock and resets the peripheral */

        /* setup speed and config. as Master */
        Chip_I2C_SetClockDiv( busId, I2C_MASTER_CLOCK_DIV );
        Chip_I2CM_SetBusSpeed( busId, I2C_MCLOCK_SPEED );
        /* Reset master state machine */
        Chip_I2CM_Disable( busId );
        Chip_I2CM_Enable( busId );

        /* Enable interrupt for pending status */
        Chip_I2C_EnableInt( busId, I2C_INTENSET_MSTPENDING );

        I2C_Master_Initialise();

        /* Configure TWI interrupts */
        NVIC_SetPriority( I2C_SENSOR_BUS_IRQn, I2C_SENSOR_BUS_INT_PRIORITY );
        NVIC_EnableIRQ( I2C_SENSOR_BUS_IRQn );           //enable I2C isr


        sI2C_Bus1Initialized = true;

        return true;
    }
    return false;
}
Exemplo n.º 2
0
TempSensDig::TempSensDig(int deviceNumber, uint32_t speed) {
	if(deviceNumber == 0) {
		device = LPC_I2C0;
		Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 22, IOCON_DIGMODE_EN | I2C_MODE);
		Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 23, IOCON_DIGMODE_EN | I2C_MODE);
		Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SCL);
		Chip_SWM_EnableFixedPin(SWM_FIXED_I2C0_SDA);
	}
	else {
		// currently we support only I2C number 0
	}
	/* Enable I2C clock and reset I2C peripheral - the boot ROM does not
	   do this */
	Chip_I2C_Init(device);

	/* Setup clock rate for I2C */
	Chip_I2C_SetClockDiv(device, I2C_CLK_DIVIDER);

	/* Setup I2CM transfer rate */
	Chip_I2CM_SetBusSpeed(device, speed);

	/* Enable Master Mode */
	Chip_I2CM_Enable(device);
}