//***************************************************************************** // //! Initialization the I2C bus module. //! //! \param bus specifies the i2c bus data structure. //! //! This function initialization the I2C hardware bus, it will open the i2c peripheral //! and config the I2C gpio //! //! \return 0 is OK. // //***************************************************************************** int ipmi_i2c_bus_init(ipmi_i2c_bus *bus) { // // Check the arguments. // ASSERT(bus->sys_peripheral); ASSERT(bus->i2c_scl_periph); ASSERT(bus->i2c_sda_periph); ASSERT(bus->i2c_scl_gpio_port); ASSERT(bus->i2c_sda_gpio_port); ASSERT(bus->i2c_scl_gpio_pin); ASSERT(bus->i2c_sda_gpio_pin); ASSERT(bus->i2c_hw_master_base); // 初始化链表结构 INIT_LIST_HEAD(&bus->list); // 初始化系统硬件外设 SysCtlPeripheralEnable(bus->sys_peripheral); // 初始化SCL管脚硬件外设 SysCtlPeripheralEnable(bus->i2c_scl_periph); if (bus->i2c_scl_gpio_mux) GPIOPinConfigure(bus->i2c_scl_gpio_mux); GPIOPinTypeI2C(bus->i2c_scl_gpio_port, bus->i2c_scl_gpio_pin); // 初始化SDA管脚硬件外设 SysCtlPeripheralEnable(bus->i2c_sda_periph); if (bus->i2c_sda_gpio_mux) GPIOPinConfigure(bus->i2c_sda_gpio_mux); GPIOPinTypeI2C(bus->i2c_sda_gpio_port, bus->i2c_sda_gpio_pin); // 设备使能,开中断 I2CMasterInit(bus->i2c_hw_master_base, false); if (bus->i2c_int) { //I2CIntRegister(bus->i2c_hw_master_base); IntEnable(bus->i2c_int); I2CMasterIntEnable(bus->i2c_hw_master_base); } I2CMasterEnable(bus->i2c_hw_master_base); list_add(&bus->list, &ipmi_i2c_bus_root.head); ipmi_i2c_bus_root.count++; return 0; }
/* Set up I2C pins and clock slow/fast rate400 true = 400KHz, false 100KHz */ void MasterI2C0Init(int rate400) { //I2CMasterEnable(I2C0_MASTER_BASE); // causes fault // // Enable the I2C and GPIO port B blocks as they are needed by this driver. // SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0); SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); //Setup Mux GPIOPinConfigure(GPIO_PB2_I2C0SCL); GPIOPinConfigure(GPIO_PB3_I2C0SDA); GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3); //Set up direction //Reconfigure for correct operation GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_2, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_STD_WPU); GPIOPadConfigSet(GPIO_PORTB_BASE, GPIO_PIN_3, GPIO_STRENGTH_2MA, GPIO_PIN_TYPE_OD); // // Configure the I2C SCL and SDA pins for I2C operation. // //GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2); //GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3); // // Initialize the I2C master. // I2CMasterInitExpClk(I2C0_MASTER_BASE, SysCtlClockGet(), true); SysCtlDelay(10000); // delay mandatory here - otherwise portion of SlaveAddrSet() lost! // Register interrupt handler // or we could just edit the startup.c file //I2CIntRegister(I2C0_MASTER_BASE,I2C0IntHandler); // // Enable the I2C interrupt. // IntEnable(INT_I2C0); // already done via I2CIntRegister I2CMasterIntEnableEx(I2C0_MASTER_BASE,I2C_MASTER_INT_DATA | I2C_MASTER_INT_TIMEOUT); // // Enable the I2C master interrupt. // I2CMasterIntEnable(I2C0_MASTER_BASE); }
static void prvSetupHardware( void ) { /* Setup the PLL. */ SysCtlClockSet( SYSCTL_SYSDIV_10 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_6MHZ ); /* Enable the I2C used to read the pot. */ SysCtlPeripheralEnable( SYSCTL_PERIPH_I2C ); SysCtlPeripheralEnable( SYSCTL_PERIPH_GPIOB ); GPIOPinTypeI2C( GPIO_PORTB_BASE, GPIO_PIN_2 | GPIO_PIN_3 ); /* Initialize the I2C master. */ I2CMasterInit( I2C_MASTER_BASE, pdFALSE ); /* Enable the I2C master interrupt. */ I2CMasterIntEnable( I2C_MASTER_BASE ); IntEnable( INT_I2C ); /* Initialise the hardware used to talk to the LED's. */ vParTestInitialise(); }
/* * ======== I2CCC26XX_hwInit ======== * This functions initializes the I2C hardware module. * * @pre Function assumes that the I2C handle is pointing to a hardware * module which has already been opened. */ static void I2CCC26XX_initHw(I2C_Handle handle) { I2CCC26XX_Object *object; I2CCC26XX_HWAttrs const *hwAttrs; Types_FreqHz freq; /* Get the pointer to the object and hwAttrs */ object = handle->object; hwAttrs = handle->hwAttrs; /* Set the I2C configuration */ BIOS_getCpuFreq(&freq); I2CMasterInitExpClk(hwAttrs->baseAddr, freq.lo, bitRate[object->bitRate]); /* Clear any pending interrupts */ I2CMasterIntClear(hwAttrs->baseAddr); /* Enable the I2C Master for operation */ I2CMasterEnable(hwAttrs->baseAddr); /* Unmask I2C interrupts */ I2CMasterIntEnable(hwAttrs->baseAddr); }