コード例 #1
0
ファイル: i2c.c プロジェクト: qermit/afcipm
void vI2CInit( I2C_ID_T i2c_id, I2C_Mode mode )
{
    char pcI2C_Tag[4];
    uint8_t sla_addr;

    sprintf( pcI2C_Tag, "I2C%u", i2c_id );
    /*! @todo Maybe wrap these functions, or use some board-specific defines
     * so this code is generic enough to be applied on other hardware.
     * Example: (if using LPC17xx and LPCOpen library)
     * @code
     * #define PIN_FUNC_CFG( port, pin, func ) Chip_IOCON_PinMux(...)
     * @endcode
    */
    Chip_IOCON_PinMux( LPC_IOCON, i2c_cfg[i2c_id].pins.sda_port, i2c_cfg[i2c_id].pins.sda_pin, IOCON_MODE_INACT, i2c_cfg[i2c_id].pins.pin_func );
    Chip_IOCON_PinMux( LPC_IOCON, i2c_cfg[i2c_id].pins.scl_port, i2c_cfg[i2c_id].pins.scl_pin, IOCON_MODE_INACT, i2c_cfg[i2c_id].pins.pin_func );
    Chip_IOCON_EnableOD( LPC_IOCON, i2c_cfg[i2c_id].pins.sda_port, i2c_cfg[i2c_id].pins.sda_pin );
    Chip_IOCON_EnableOD( LPC_IOCON, i2c_cfg[i2c_id].pins.scl_port, i2c_cfg[i2c_id].pins.scl_pin );
    NVIC_SetPriority(i2c_cfg[i2c_id].irq, configMAX_SYSCALL_INTERRUPT_PRIORITY);
    NVIC_EnableIRQ( i2c_cfg[i2c_id].irq );

    /* Create mutex for accessing the shared memory (i2c_cfg) */
    I2C_mutex[i2c_id] = xSemaphoreCreateMutex();

    /* Make sure that the mutex is freed */
    xSemaphoreGive( I2C_mutex[i2c_id] );

    /* Set I2C operating mode */
    if( xSemaphoreTake( I2C_mutex[i2c_id], 0 ) ) {
        i2c_cfg[i2c_id].mode = mode;
        xSemaphoreGive( I2C_mutex[i2c_id] );
    }

    /* Enable and configure I2C clock */
    Chip_I2C_Init( i2c_id );
    Chip_I2C_SetClockRate( i2c_id, 100000 );

    /* Enable I2C interface (Master Mode only) */
    I2CCONSET( i2c_id, I2C_I2EN );

    if ( mode == I2C_Mode_IPMB )
    {
        /* Configure Slave Address */
        sla_addr = get_ipmb_addr( );
        I2CADDR_WRITE( i2c_id, sla_addr );

        /* Configure Slave Address Mask */
        I2CMASK( i2c_id, 0xFE);

        /* Enable slave mode */
        I2CCONSET( i2c_id, I2C_AA );
    }

    /* Clear I2C0 interrupt (just in case) */
    I2CCONCLR( i2c_id, I2C_SI );

} /* End of vI2C_Init */
コード例 #2
0
/* Sets up board specific I2C interface */
void Board_I2C_Init(I2C_ID_T id)
{
	switch (id) {
	case I2C0:
		Chip_IOCON_PinMux(LPC_IOCON, 0, 27, IOCON_MODE_INACT, IOCON_FUNC1);
		Chip_IOCON_PinMux(LPC_IOCON, 0, 28, IOCON_MODE_INACT, IOCON_FUNC1);
		Chip_IOCON_SetI2CPad(LPC_IOCON, I2CPADCFG_STD_MODE);
		break;

	case I2C1:
		Chip_IOCON_PinMux(LPC_IOCON, 0, 19, IOCON_MODE_INACT, IOCON_FUNC2);
		Chip_IOCON_PinMux(LPC_IOCON, 0, 20, IOCON_MODE_INACT, IOCON_FUNC2);
		Chip_IOCON_EnableOD(LPC_IOCON, 0, 19);
		Chip_IOCON_EnableOD(LPC_IOCON, 0, 20);
		break;

	case I2C2:
		Chip_IOCON_PinMux(LPC_IOCON, 0, 10, IOCON_MODE_INACT, IOCON_FUNC2);
		Chip_IOCON_PinMux(LPC_IOCON, 0, 11, IOCON_MODE_INACT, IOCON_FUNC2);
		Chip_IOCON_EnableOD(LPC_IOCON, 0, 10);
		Chip_IOCON_EnableOD(LPC_IOCON, 0, 11);
		break;
	}
}
コード例 #3
0
ファイル: main.c プロジェクト: avaudagna/Accelerometer-Reader
static void initHardware(void)
{
#if defined (__USE_LPCOPEN)
#if !defined(NO_BOARD_LIB)
    // Read clock settings and update SystemCoreClock variable
    SystemCoreClockUpdate();
    // Set up and initialize all required blocks and
    // functions related to the board hardware
    Board_Init();
    // Set the LED to the state of "Off"
    Board_LED_Set(0, false);
#endif
#endif
    Board_I2C_Init(I2C1);

    /* pines del stick */
	Chip_IOCON_PinMux(LPC_IOCON, 0, 0, IOCON_MODE_INACT, IOCON_FUNC3);
	Chip_IOCON_PinMux(LPC_IOCON, 0, 1, IOCON_MODE_INACT, IOCON_FUNC3);
	Chip_IOCON_EnableOD(LPC_IOCON, 0, 0);
	Chip_IOCON_EnableOD(LPC_IOCON, 0, 1);

    Chip_I2C_SetClockRate(I2C1, 100000);
	Chip_I2C_SetMasterEventHandler(I2C1, Chip_I2C_EventHandlerPolling);
}