本文整理汇总了C++中I2C_Cmd函数的典型用法代码示例。如果您正苦于以下问题:C++ I2C_Cmd函数的具体用法?C++ I2C_Cmd怎么用?C++ I2C_Cmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了I2C_Cmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: I2C_Master_Initialise
/****************************************************************************************************
* @fn I2C_Master_Initialise
* Call this function to set up the I2C master to its initial standby state.
* Remember to enable interrupts from the main application after initializing the I2C.
*
* @param none
*
* @return none
*
***************************************************************************************************/
void I2C_Master_Initialise(void)
{
I2C_InitTypeDef I2C_InitStructure;
/* Configure the I2C interface */
I2C_Cmd(I2C_SENSOR_BUS, ENABLE);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0; //Don't care in master mode
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_SENSOR_BUS_CLOCK;
I2C_Init(I2C_SENSOR_BUS, &I2C_InitStructure);
asyncXfer.i2c_txrx_status = I2C_TXRX_STATUS_PASSED; //initialize last comm status
/* Note: I2C bus event and error interrupts are enabled when tx is started */
}
示例2: LM75_Init
/**
* @brief Initializes the LM75_I2C.
* @param None
* @retval None
*/
void LM75_Init(void)
{
LM75_LowLevel_Init();
/* I2C DeInit */
I2C_DeInit(LM75_I2C);
/* I2C configuration */
I2C_Init(LM75_I2C, LM75_I2C_SPEED, 0x00, I2C_Mode_SMBusHost,
I2C_DutyCycle_2, I2C_Ack_Enable, I2C_AcknowledgedAddress_7bit);
/*!< Enable SMBus Alert interrupt */
I2C_ITConfig(LM75_I2C, I2C_IT_ERR, ENABLE);
/*!< LM75_I2C Init */
I2C_Cmd(LM75_I2C, ENABLE);
}
示例3: I2C_Mode_Config
/*
* 函数名:I2C_Mode_Config
* 描述 :I2C 工作模式配置
* 输入 :无
* 输出 :无
* 调用 :内部调用
*/
static void I2C_Mode_Config(void)
{
/* Initialize the I2C1 according to the I2C_InitStructure members */
I2C_InitTypeDef I2C_InitStructure;
/* I2C 配置 */
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C ;
//I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
//I2C_InitStructure.I2C_OwnAddress1 = SlaveAddress;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 350000;
/* I2C1 初始化 */
I2C_Init(I2C1, &I2C_InitStructure);
/* 使能 I2C1 */
I2C_Cmd(I2C1, ENABLE);
/*允许应答模式*/
I2C_AcknowledgeConfig(I2C1, ENABLE);
}
示例4: P_I2C3_InitI2C
//--------------------------------------------------------------
// interne Funktion
// Init der I2C-Schnittstelle
//--------------------------------------------------------------
void P_I2C3_InitI2C(void)
{
I2C_InitTypeDef I2C_InitStructure;
// I2C-Konfiguration
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C3_CLOCK_FRQ;
// I2C enable
I2C_Cmd(I2C3, ENABLE);
// Init Struktur
I2C_Init(I2C3, &I2C_InitStructure);
}
示例5: platform_i2c_setup
/* I2C Functions */
u32 platform_i2c_setup( unsigned id, u32 speed )
{
GPIO_InitTypeDef GPIO_InitStruct;
I2C_InitTypeDef I2C_InitStruct;
// enable APB1 peripheral clock for I2C1
RCC_APB1PeriphClockCmd(i2c_rcc[id], ENABLE);
// enable clock for SCL and SDA pins
RCC_AHB1PeriphClockCmd(i2c_port_rcc[id], ENABLE);
I2C_DeInit(i2c[id]);
/* setup SCL and SDA pins
* You can connect I2C1 to two different
* pairs of pins:
* 1. SCL on PB6 and SDA on PB7
* 2. SCL on PB8 and SDA on PB9
*/
GPIO_InitStruct.GPIO_Pin = i2c_scl_pin[id] | i2c_sda_pin[id]; // pins to use
GPIO_InitStruct.GPIO_Mode = GPIO_Mode_AF; // set pins to alternate function
GPIO_InitStruct.GPIO_Speed = GPIO_Speed_50MHz; // set GPIO speed
GPIO_InitStruct.GPIO_OType = GPIO_OType_OD; // set output to open drain --> the line has to be only pulled low, not driven high
GPIO_InitStruct.GPIO_PuPd = GPIO_PuPd_UP; // enable pull up resistors
GPIO_Init(i2c_port[id], &GPIO_InitStruct); // init GPIO
// Connect I2C1 pins to AF
GPIO_PinAFConfig(i2c_port[id], i2c_scl_pinsource[id], i2c_af[id]); // SCL
GPIO_PinAFConfig(i2c_port[id], i2c_sda_pinsource[id], i2c_af[id]); // SDA
// configure I2C1
I2C_StructInit(&I2C_InitStruct);
I2C_InitStruct.I2C_ClockSpeed = speed; //set speed (100kHz or 400kHz)
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C; // I2C mode
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2; // 50% duty cycle --> standard
I2C_InitStruct.I2C_OwnAddress1 = 0x00; // own address, not relevant in master mode
I2C_InitStruct.I2C_Ack = I2C_Ack_Disable; // disable acknowledge when reading (can be changed later on)
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit; // set address length to 7 bit addresses
I2C_Init(i2c[id], &I2C_InitStruct); // init I2C1
// enable I2C1
I2C_Cmd(i2c[id], ENABLE);
return speed;
}
示例6: i2cInit
void i2cInit(I2C_TypeDef *I2C)
{
NVIC_InitTypeDef NVIC_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
I2C_InitTypeDef I2C_InitStructure;
// Init pins
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10 | GPIO_Pin_11;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_Init(GPIOB, &GPIO_InitStructure);
I2Cx = I2C;
// clock out stuff to make sure slaves arent stuck
i2cUnstick();
// Init I2C
I2C_DeInit(I2Cx);
I2C_StructInit(&I2C_InitStructure);
I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, DISABLE); //Enable EVT and ERR interrupts - they are enabled by the first request
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 400000;
I2C_Cmd(I2Cx, ENABLE);
I2C_Init(I2Cx, &I2C_InitStructure);
NVIC_PriorityGroupConfig(0x500);
// I2C ER Interrupt
NVIC_InitStructure.NVIC_IRQChannel = I2C2_ER_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// I2C EV Interrupt
NVIC_InitStructure.NVIC_IRQChannel = I2C2_EV_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_Init(&NVIC_InitStructure);
}
示例7: Temp_Read
u8 Temp_Read(void)
{
u8 MSB,LSB;
//等待I2C閒置
while(I2C_GetFlagStatus(I2C1,I2C_FLAG_BUSY));
I2C_AcknowledgeConfig(I2C1,ENABLE);
//啟動訊號
I2C_GenerateSTART(I2C1,ENABLE);
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)!=SUCCESS);
//發送裝置位置
I2C_Send7bitAddress(I2C1,0xF0,I2C_Direction_Transmitter);
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)!=SUCCESS);
I2C_Cmd(I2C1,ENABLE);
//發送記憶體位置
I2C_SendData(I2C1,0xE5);
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_TRANSMITTED)!=SUCCESS);
//啟動訊號
I2C_GenerateSTART(I2C1,ENABLE);
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_MODE_SELECT)!=SUCCESS);
//發送裝置位置
I2C_Send7bitAddress(I2C1,0xF0,I2C_Direction_Receiver);
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)!=SUCCESS);
//I2C_AcknowledgeConfig(I2C1,DISABLE); //ACK 關閉
MSB=I2C_ReceiveData(I2C1);
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)!=SUCCESS);
LSB=I2C_ReceiveData(I2C1);
while(I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED)!=SUCCESS);
//停止訊號
I2C_GenerateSTOP(I2C1,ENABLE);
USART_SendData(USART1,MSB);
}
示例8: sEE_LowLevel_DeInit
/**
* @brief DeInitializes peripherals used by the I2C EEPROM driver.
* @param None
* @retval None
*/
void sEE_LowLevel_DeInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
/* sEE_I2C Peripheral Disable */
I2C_Cmd(sEE_I2C, DISABLE);
/* sEE_I2C DeInit */
I2C_DeInit(sEE_I2C);
/*!< sEE_I2C Periph clock disable */
RCC_APB1PeriphClockCmd(sEE_I2C_CLK, DISABLE);
/*!< GPIO configuration */
/*!< Configure sEE_I2C pins: SCL */
GPIO_InitStructure.GPIO_Pin = sEE_I2C_SCL_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL;
GPIO_Init(sEE_I2C_SCL_GPIO_PORT, &GPIO_InitStructure);
/*!< Configure sEE_I2C pins: SDA */
GPIO_InitStructure.GPIO_Pin = sEE_I2C_SDA_PIN;
GPIO_Init(sEE_I2C_SDA_GPIO_PORT, &GPIO_InitStructure);
/* Configure and enable I2C DMA TX Channel interrupt */
NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_TX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
NVIC_InitStructure.NVIC_IRQChannelCmd = DISABLE;
NVIC_Init(&NVIC_InitStructure);
/* Configure and enable I2C DMA RX Channel interrupt */
NVIC_InitStructure.NVIC_IRQChannel = sEE_I2C_DMA_RX_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = sEE_I2C_DMA_PREPRIO;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = sEE_I2C_DMA_SUBPRIO;
NVIC_Init(&NVIC_InitStructure);
/* Disable and Deinitialize the DMA channels */
DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE);
DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, DISABLE);
DMA_DeInit(sEE_I2C_DMA_CHANNEL_TX);
DMA_DeInit(sEE_I2C_DMA_CHANNEL_RX);
}
示例9: sEE_Init
/**
* @brief Initializes peripherals used by the I2C EEPROM driver.
* @param None
* @retval None
*/
void sEE_Init(void)
{
sEE_LowLevel_Init();
/*!< I2C configuration */
/* sEE_I2C Peripheral Enable */
I2C_Cmd(sEE_I2C, ENABLE);
/* sEE_I2C configuration after enabling it */
I2C_Init(sEE_I2C, I2C_SPEED, I2C_SLAVE_ADDRESS7, I2C_Mode_I2C, I2C_DutyCycle_2,
I2C_Ack_Enable, I2C_AcknowledgedAddress_7bit);
/* Enable the sEE_I2C peripheral DMA requests */
I2C_DMACmd(sEE_I2C, ENABLE);
#if defined (sEE_M24C64_32)
/*!< Select the EEPROM address according to the state of E0, E1, E2 pins */
sEEAddress = sEE_HW_ADDRESS;
#endif /*!< sEE_M24C64_32 */
}
示例10: ade7880_i2c_cfg
void ade7880_i2c_cfg(void)
{
I2C_InitTypeDef I2C_InitStructure;
I2C_DeInit(I2C2);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0x01;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 50000;
I2C_Init(I2C2, &I2C_InitStructure);
I2C_Cmd(I2C2, DISABLE);
return;
}
示例11: Codec_CtrlInterface_Init
/**
* @brief Initializes the Audio Codec control interface (I2C).
* @param None.
* @retval None.
*/
static void Codec_CtrlInterface_Init(void)
{
I2C_InitTypeDef I2C_InitStructure;
/* Enable the CODEC_I2C peripheral clock */
RCC_APB1PeriphClockCmd(CODEC_I2C_CLK, ENABLE);
/* CODEC_I2C peripheral configuration */
I2C_DeInit(CODEC_I2C);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0x33;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
/* Enable the I2C peripheral */
I2C_Cmd(CODEC_I2C, ENABLE);
I2C_Init(CODEC_I2C, &I2C_InitStructure);
}
示例12: I2C_Initialise
void I2C_Initialise()
{
I2C_InitTypeDef I2C_InitStruct;
RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, ENABLE);
RCC_APB1PeriphResetCmd(RCC_APB1Periph_I2C1, DISABLE);
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C1, ENABLE);
I2C_InitStruct.I2C_Ack = I2C_Ack_Enable;
I2C_InitStruct.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStruct.I2C_ClockSpeed = 100000;
I2C_InitStruct.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStruct.I2C_Mode = I2C_Mode_I2C;
I2C_InitStruct.I2C_OwnAddress1 = 0x00;
I2C_Init(I2C1, &I2C_InitStruct);
I2C_Cmd(I2C1, ENABLE);
}
示例13: i2cInit
void i2cInit(I2C_TypeDef *I2C)
{
NVIC_InitTypeDef nvic;
I2C_InitTypeDef i2c;
gpio_config_t gpio;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2 | RCC_APB2Periph_GPIOB, ENABLE);
// Init pins
gpio.pin = Pin_10 | Pin_11;
gpio.speed = Speed_2MHz;
gpio.mode = Mode_AF_OD;
gpioInit(GPIOB, &gpio);
I2Cx = I2C;
// clock out stuff to make sure slaves arent stuck
i2cUnstick();
// Init I2C
I2C_DeInit(I2Cx);
I2C_StructInit(&i2c);
I2C_ITConfig(I2Cx, I2C_IT_EVT | I2C_IT_ERR, DISABLE); // Enable EVT and ERR interrupts - they are enabled by the first request
i2c.I2C_Mode = I2C_Mode_I2C;
i2c.I2C_DutyCycle = I2C_DutyCycle_2;
i2c.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
i2c.I2C_ClockSpeed = 400000;
I2C_Cmd(I2Cx, ENABLE);
I2C_Init(I2Cx, &i2c);
// I2C ER Interrupt
nvic.NVIC_IRQChannel = I2C2_ER_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 0;
nvic.NVIC_IRQChannelSubPriority = 0;
nvic.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&nvic);
// I2C EV Interrupt
nvic.NVIC_IRQChannel = I2C2_EV_IRQn;
nvic.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_Init(&nvic);
}
示例14: i2cInit
void i2cInit(I2C_TypeDef* I2Cx)
{
chSemObjectInit(&i2c1_semI, 1);
chSemObjectInit(&i2c1_semS, 1);
I2C_InitTypeDef I2C_InitStructure;
I2C_StructInit(&I2C_InitStructure);
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_AnalogFilter = I2C_AnalogFilter_Disable;
I2C_InitStructure.I2C_DigitalFilter = 0x00;
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_Timing = 0x0070D8FF;
I2C_Init(I2Cx, &I2C_InitStructure);
I2C_Cmd(I2Cx, ENABLE);
}
示例15: i2c_frequency
void i2c_frequency(i2c_t *obj, int hz) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
I2C_InitTypeDef I2C_InitStructure;
if ((hz != 0) && (hz <= 400000)) {
I2C_DeInit(i2c);
// I2C configuration
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = hz;
I2C_Init(i2c, &I2C_InitStructure);
I2C_Cmd(i2c, ENABLE);
}
}