void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2C_Type*)pinmap_merge(i2c_sda, i2c_scl); if ((int)obj->i2c == NC) { error("I2C pin mapping failed"); } // enable power switch ((int)obj->i2c) { case I2C_0: SIM->SCGC5 |= 1 << 13; SIM->SCGC4 |= 1 << 6; break; case I2C_1: SIM->SCGC5 |= 1 << 11; SIM->SCGC4 |= 1 << 7; break; } // set default frequency at 100k i2c_frequency(obj, 100000); // enable I2C interface obj->i2c->C1 |= 0x80; pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); first_read = 1; }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // Determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT(obj->i2c != (I2CName)NC); // Enable I2C clock if (obj->i2c == I2C_1) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); RCC_I2CCLKConfig(RCC_I2C1CLK_SYSCLK); } if (obj->i2c == I2C_2) { RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); } // Configure I2C pins pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(scl, OpenDrain); pinmap_pinout(sda, PinMap_I2C_SDA); pin_mode(sda, OpenDrain); // Reset to clear pending flags if any i2c_reset(obj); // I2C configuration i2c_frequency(obj, 100000); // 100 kHz per default }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // Determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); if (obj->i2c == (I2CName)NC) { error("I2C error: pinout mapping failed."); } // Enable I2C clock if (obj->i2c == I2C_1) { __HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK); __I2C1_CLK_ENABLE(); } if (obj->i2c == I2C_2) { __I2C2_CLK_ENABLE(); } // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); // Reset to clear pending flags if any i2c_reset(obj); // I2C configuration i2c_frequency(obj, 100000); // 100 kHz per default }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // determine the SPI to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT((int)obj->i2c != NC); // enable power i2c_power_enable(obj); pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); // Force reset if the bus is stuck in the BUSY state if (obj->i2c->SR2 & I2C_SR2_BUSY) { obj->i2c->CR1 |= I2C_CR1_SWRST; obj->i2c->CR1 &= ~I2C_CR1_SWRST; } // Set the peripheral clock frequency obj->i2c->CR2 |= 42; // set default frequency at 100k i2c_frequency(obj, 100000); i2c_interface_enable(obj); }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // determine the SPI to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT((int)obj->i2c != NC); // enable power i2c_power_enable(obj); // set default frequency at 100k i2c_frequency(obj, 100000); i2c_conclr(obj, 1, 1, 1, 1); i2c_interface_enable(obj); pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); // OpenDrain must explicitly be enabled for p0.0 and p0.1 if (sda == P0_0) { pin_mode(sda, OpenDrain); } if (scl == P0_1) { pin_mode(scl, OpenDrain); } }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); mxc_i2cm_regs_t *i2c = (mxc_i2cm_regs_t*)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT((int)i2c != NC); obj->i2c = i2c; obj->txfifo = (uint16_t*)MXC_I2CM_GET_BASE_TX_FIFO(MXC_I2CM_BASE_TO_INSTANCE(i2c)); obj->rxfifo = (uint16_t*)MXC_I2CM_GET_BASE_RX_FIFO(MXC_I2CM_BASE_TO_INSTANCE(i2c)); obj->start_pending = 0; obj->stop_pending = 0; // configure the pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); // enable the clock MXC_CLKMAN->clk_ctrl_6_i2cm = MXC_E_CLKMAN_CLK_SCALE_ENABLED; // reset module i2c->ctrl = MXC_F_I2CM_CTRL_MSTR_RESET_EN; i2c->ctrl = 0; // set default frequency at 100k i2c_frequency(obj, 100000); // set timeout to 255 ms and turn on the auto-stop option i2c->timeout = (0xFF << MXC_F_I2CM_TIMEOUT_TX_TIMEOUT_POS) | MXC_F_I2CM_TIMEOUT_AUTO_STOP_EN; // enable tx_fifo and rx_fifo i2c->ctrl |= (MXC_F_I2CM_CTRL_TX_FIFO_EN | MXC_F_I2CM_CTRL_RX_FIFO_EN); }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { const SWM_Map *swm; uint32_t regVal; int i2c_ch = 0; //LPC824 //I2C0 can support FM+ but only on P0_11 and P0_10 if (sda == I2C_SDA && scl == I2C_SCL) { //Select I2C mode for P0_11 and P0_10 LPC_SWM->PINENABLE0 &= ~(0x3 << 11); #if(LPC824_I2C0_FMPLUS == 1) // Enable FM+ mode on P0_11, P0_10 LPC_IOCON->PIO0_10 &= ~(0x3 << 8); LPC_IOCON->PIO0_10 |= (0x2 << 8); //FM+ mode LPC_IOCON->PIO0_11 &= ~(0x3 << 8); LPC_IOCON->PIO0_11 |= (0x2 << 8); //FM+ mode #endif } else { //Select any other pin for I2C1, I2C2 or I2C3 i2c_ch = get_available_i2c(); if (i2c_ch == -1) return; i2c_used |= (1 << (i2c_ch - 1)); swm = &SWM_I2C_SDA[i2c_ch - 1]; regVal = LPC_SWM->PINASSIGN[swm->n] & ~(0xFF << swm->offset); LPC_SWM->PINASSIGN[swm->n] = regVal | ((sda >> PIN_SHIFT) << swm->offset); swm = &SWM_I2C_SCL[i2c_ch - 1]; regVal = LPC_SWM->PINASSIGN[swm->n] & ~(0xFF << swm->offset); LPC_SWM->PINASSIGN[swm->n] = regVal | ((scl >> PIN_SHIFT) << swm->offset); } switch(i2c_ch) { case 0: obj->i2c = (LPC_I2C0_Type *)LPC_I2C0; break; case 1: obj->i2c = (LPC_I2C0_Type *)LPC_I2C1; break; case 2: obj->i2c = (LPC_I2C0_Type *)LPC_I2C2; break; case 3: obj->i2c = (LPC_I2C0_Type *)LPC_I2C3; break; default: break; } // enable power i2c_power_enable(i2c_ch); // set default frequency at 100k i2c_frequency(obj, 100000); i2c_interface_enable(obj); }
void I2C::aquire() { lock(); if (_owner != this) { i2c_frequency(&_i2c, _hz); _owner = this; } unlock(); }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { static int i2c1_inited = 0; static int i2c2_inited = 0; #if defined(I2C3_BASE) static int i2c3_inited = 0; #endif // Determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT(obj->i2c != (I2CName)NC); // Enable I2C1 clock and pinout if not done if ((obj->i2c == I2C_1) && !i2c1_inited) { i2c1_inited = 1; __HAL_RCC_I2C1_CONFIG(RCC_I2C1CLKSOURCE_SYSCLK); __I2C1_CLK_ENABLE(); // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); } // Enable I2C2 clock and pinout if not done if ((obj->i2c == I2C_2) && !i2c2_inited) { i2c2_inited = 1; __I2C2_CLK_ENABLE(); // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); } #if defined(I2C3_BASE) // Enable I2C3 clock and pinout if not done if ((obj->i2c == I2C_3) && !i2c3_inited) { i2c3_inited = 1; __I2C3_CLK_ENABLE(); // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); } #endif // Reset to clear pending flags if any i2c_reset(obj); // I2C configuration i2c_frequency(obj, 100000); // 100 kHz per default }
void I2C::frequency(int hz) { _hz = hz; // We want to update the frequency even if we are already the bus owners i2c_frequency(&_i2c, _hz); // Updating the frequency of the bus we become the owners of it _owner = this; }
/********************************************************************** name : function : **********************************************************************/ void TwoWire::begin(uint32_t scl, uint32_t sda, uint32_t speed) { PinName nrf_sda, nrf_scl; nrf_scl = Pin_nRF51822_to_Arduino(scl); nrf_sda = Pin_nRF51822_to_Arduino(sda); /* Initialize i2c */ i2c_init(&i2c, nrf_sda, nrf_scl); i2c_frequency(&i2c, speed); twi_status = UNINITIALIZED; }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // Determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT(obj->i2c != (I2CName)NC); // Enable I2C1 clock and pinout if not done if ((obj->i2c == I2C_1) && !i2c1_inited) { i2c1_inited = 1; __I2C1_CLK_ENABLE(); // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); } // Enable I2C2 clock and pinout if not done if ((obj->i2c == I2C_2) && !i2c2_inited) { i2c2_inited = 1; __I2C2_CLK_ENABLE(); // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); } // Enable I2C3 clock and pinout if not done if ((obj->i2c == I2C_3) && !i2c3_inited) { i2c3_inited = 1; __I2C3_CLK_ENABLE(); // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); } // Reset to clear pending flags if any i2c_reset(obj); // I2C configuration i2c_frequency(obj, 100000); // 100 kHz per default // I2C master by default obj->slave = 0; }
int SHTC1_Init(uint16_t *pID) { int error = NO_ERROR; DiagPrintf("SHTC1_Init \r\n"); i2c_init((i2c_t*)&i2cmaster, MBED_I2C_MTR_SDA ,MBED_I2C_MTR_SCL); i2c_frequency((i2c_t*)&i2cmaster,MBED_I2C_BUS_CLK); if (pID == NULL ) return NULL_ERROR; error = SHTC1_GetID(pID); return error; }
/** Initialize the I2C peripheral. It sets the default parameters for I2C * peripheral, and configures its specifieds pins. * * @param obj The I2C object * @param sda The sda pin * @param scl The scl pin */ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { struct i2c_s *obj_s = I2C_S(obj); /* find the I2C by pins */ uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA); uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL); obj_s->sda = sda; obj_s->scl = scl; obj_s->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT(obj_s->i2c != (I2CName)NC); switch (obj_s->i2c) { case I2C_0: /* enable I2C0 clock and configure the pins of I2C0 */ obj_s->index = 0; rcu_periph_clock_enable(RCU_I2C0); break; case I2C_1: /* enable I2C1 clock and configure the pins of I2C1 */ obj_s->index = 1; rcu_periph_clock_enable(RCU_I2C1); break; default: break; } /* configure the pins of I2C */ pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); /* 100 KHz as the default I2C frequence */ i2c_frequency(obj, 100000); obj_s->state = (operation_state_enum)I2C_STATE_NONE; obj_s->previous_state_mode = I2C_STATE_NONE; obj_s->global_trans_option = I2C_FIRST_AND_LAST_FRAME; #if DEVICE_I2CSLAVE /* I2C master by default */ obj_s->slave = 0; #endif }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA); uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL); obj->instance = pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT((int)obj->instance != NC); clock_manager_set_gate(kClockModuleI2C, obj->instance, true); clock_manager_set_gate(kClockModulePORT, sda >> GPIO_PORT_SHIFT, true); clock_manager_set_gate(kClockModulePORT, scl >> GPIO_PORT_SHIFT, true); i2c_hal_enable(obj->instance); i2c_frequency(obj, 100000); pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); port_hal_configure_open_drain(sda >> GPIO_PORT_SHIFT, sda & 0xFF, true); port_hal_configure_open_drain(scl >> GPIO_PORT_SHIFT, scl & 0xFF, true); }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { /* determine the I2C to use */ I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT((int)obj->i2c != NC); /* enable power */ i2c_power_enable(obj); /* set default frequency at 100k */ i2c_frequency(obj, 100000); pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); obj->last_stop_flag = 1; }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // determine the SPI to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT((int)obj->i2c != NC); // enable power i2c_power_enable(obj); // set default frequency at 100k i2c_frequency(obj, 100000); i2c_conclr(obj, 1, 1, 1, 1); i2c_interface_enable(obj); pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); }
void twi_master_init(i2c_t *obj, PinName sda, PinName scl, int frequency) { NRF_GPIO->PIN_CNF[scl] = ((GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)); NRF_GPIO->PIN_CNF[sda] = ((GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos) | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos)); obj->i2c->PSELSCL = scl; obj->i2c->PSELSDA = sda; // set default frequency at 100k i2c_frequency(obj, frequency); i2c_interface_enable(obj); }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { uint32_t i2c_sda = pinmap_peripheral(sda, PinMap_I2C_SDA); uint32_t i2c_scl = pinmap_peripheral(scl, PinMap_I2C_SCL); obj->instance = pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT((int)obj->instance != NC); CLOCK_SYS_EnableI2cClock(obj->instance); uint32_t i2c_addrs[] = I2C_BASE_ADDRS; I2C_HAL_Init(i2c_addrs[obj->instance]); I2C_HAL_Enable(i2c_addrs[obj->instance]); I2C_HAL_SetIntCmd(i2c_addrs[obj->instance], true); i2c_frequency(obj, 100000); pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); uint32_t port_addrs[] = PORT_BASE_ADDRS; PORT_HAL_SetOpenDrainCmd(port_addrs[sda >> GPIO_PORT_SHIFT], sda & 0xFF, true); PORT_HAL_SetOpenDrainCmd(port_addrs[scl >> GPIO_PORT_SHIFT], scl & 0xFF, true); }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { obj->i2c = (LPC_I2C_TypeDef *)LPC_I2C; const SWM_Map *swm; uint32_t regVal; swm = &SWM_I2C_SDA[0]; regVal = LPC_SWM->PINASSIGN[swm->n] & ~(0xFF << swm->offset); LPC_SWM->PINASSIGN[swm->n] = regVal | (sda << swm->offset); swm = &SWM_I2C_SCL[0]; regVal = LPC_SWM->PINASSIGN[swm->n] & ~(0xFF << swm->offset); LPC_SWM->PINASSIGN[swm->n] = regVal | (scl << swm->offset); // enable power i2c_power_enable(obj); // set default frequency at 100k i2c_frequency(obj, 100000); i2c_interface_enable(obj); }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // determine the SPI to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_T *)pinmap_merge(i2c_sda, i2c_scl); if ((int)obj->i2c == NC) { error("I2C pin mapping failed"); } // set default frequency at 100k i2c_frequency(obj, 100000); i2c_conclr(obj, 1, 1, 1, 1); i2c_interface_enable(obj); // If pins are not dedicated, set SCU functions if (sda != P_DED) { pinmap_pinout(sda, PinMap_I2C_SDA); } if (scl != P_DED) { pinmap_pinout(scl, PinMap_I2C_SCL); } }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { int timeout; I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c); // Determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT(obj->i2c != (I2CName)NC); // Enable I2C clock and configure I2C pins if not done before if ((obj->i2c == I2C_1)&& !i2c1_inited) { i2c1_inited = 1; RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE); // Configure I2C pins pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(scl, OpenDrain); pinmap_pinout(sda, PinMap_I2C_SDA); pin_mode(sda, OpenDrain); } if ((obj->i2c == I2C_2)&& !i2c2_inited) { i2c2_inited = 1; RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE); // Configure I2C pins pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(scl, OpenDrain); pinmap_pinout(sda, PinMap_I2C_SDA); pin_mode(sda, OpenDrain); } // Reset to clear pending flags if any i2c_reset(obj); // I2C configuration i2c_frequency(obj, 100000); // 100 kHz per default }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // determine the SPI to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (LPC_I2C_T *)pinmap_merge(i2c_sda, i2c_scl); if ((int)obj->i2c == NC) { error("I2C pin mapping failed"); } // set default frequency at 100k i2c_frequency(obj, 100000); i2c_conclr(obj, 1, 1, 1, 1); i2c_interface_enable(obj); // Set SCU functions if (scl == P_DED) { // Enable dedicated I2C0 SDA and SCL pins (open drain) LPC_SCU->SFSI2C0 = (1 << 11) | (1 << 3); } else { pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); } }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // determine the SPI to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); #if defined(TARGET_LPC1768) || defined(TARGET_LPC2368) obj->i2c = (LPC_I2C_TypeDef *)pinmap_merge(i2c_sda, i2c_scl); #elif defined(TARGET_LPC11U24) obj->i2c = (LPC_I2C_Type *)pinmap_merge(i2c_sda, i2c_scl); #endif if ((int)obj->i2c == NC) { error("I2C pin mapping failed"); } // enable power i2c_power_enable(obj); // set default frequency at 100k i2c_frequency(obj, 100000); i2c_conclr(obj, 1, 1, 1, 1); i2c_interface_enable(obj); pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // Determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT(obj->i2c != (I2CName)NC); // Enable I2C1 clock and pinout if not done if ((obj->i2c == I2C_0) && !i2c0_inited) { i2c0_inited = 1; // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, PullUp); pin_mode(scl, PullUp); } // Enable I2C2 clock and pinout if not done if ((obj->i2c == I2C_1) && !i2c1_inited) { i2c1_inited = 1; // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, PullUp); pin_mode(scl, PullUp); } // Reset to clear pending flags if any i2c_reset(obj); // I2C configuration i2c_frequency(obj, 100000); // 100 kHz per default obj->is_setAddress = 0; }
void i2c_init(i2c_t *obj, PinName sda, PinName scl) { // Determine the I2C to use I2CName i2c_sda = (I2CName)pinmap_peripheral(sda, PinMap_I2C_SDA); I2CName i2c_scl = (I2CName)pinmap_peripheral(scl, PinMap_I2C_SCL); obj->i2c = (I2CName)pinmap_merge(i2c_sda, i2c_scl); MBED_ASSERT(obj->i2c != (I2CName)NC); // Enable I2C clock __I2C1_CLK_ENABLE(); // Configure I2C pins pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); pin_mode(sda, OpenDrain); pin_mode(scl, OpenDrain); // Reset to clear pending flags if any i2c_reset(obj); // I2C configuration i2c_frequency(obj, 100000); // 100 kHz per default }
void I2C::aquire() { if (_owner != this) { i2c_frequency(&_i2c, _hz); _owner = this; } }
I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c() { i2c_init(&_i2c, sda, scl); i2c_frequency(&_i2c, 100000); i2c_slave_mode(&_i2c, 1); }
void I2CSlave::frequency(int hz) { i2c_frequency(&_i2c, hz); }