本文整理汇总了C++中I2C_CheckEvent函数的典型用法代码示例。如果您正苦于以下问题:C++ I2C_CheckEvent函数的具体用法?C++ I2C_CheckEvent怎么用?C++ I2C_CheckEvent使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了I2C_CheckEvent函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LM75_GetStatus
/**
* @brief Checks the LM75 status.
* @param None
* @retval ErrorStatus: LM75 Status (ERROR or SUCCESS).
*/
ErrorStatus LM75_GetStatus(void)
{
uint32_t I2C_TimeOut = I2C_TIMEOUT;
/*!< Clear the LM75_I2C AF flag */
I2C_ClearFlag(LM75_I2C, I2C_FLAG_AF);
/*!< Enable LM75_I2C acknowledgement if it is already disabled by other function */
I2C_AcknowledgeConfig(LM75_I2C, ENABLE);
/*---------------------------- Transmission Phase ---------------------------*/
/*!< Send LM75_I2C START condition */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/*!< Test on LM75_I2C EV5 and clear it */
while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB)) && I2C_TimeOut) /*!< EV5 */
{
I2C_TimeOut--;
}
if (I2C_TimeOut == 0)
{
return ERROR;
}
I2C_TimeOut = I2C_TIMEOUT;
/*!< Send STLM75 slave address for write */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
while ((!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) && I2C_TimeOut)/* EV6 */
{
I2C_TimeOut--;
}
if ((I2C_GetFlagStatus(LM75_I2C, I2C_FLAG_AF) != 0x00) || (I2C_TimeOut == 0))
{
return ERROR;
}
else
{
return SUCCESS;
}
}
示例2: i2c_write
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
int count;
/*
// Wait until the bus is not busy anymore
timeout = LONG_TIMEOUT;
while (I2C_GetFlagStatus(i2c, I2C_FLAG_BUSY) == SET) {
timeout--;
if (timeout == 0) {
return 0;
}
}
*/
i2c_start(obj);
// Send slave address for write
I2C_Send7bitAddress(i2c, address, I2C_Direction_Transmitter);
// Wait address is acknowledged
timeout = FLAG_TIMEOUT;
while (I2C_CheckEvent(i2c, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) == ERROR) {
timeout--;
if (timeout == 0) {
return 0;
}
}
for (count = 0; count < length; count++) {
if (i2c_byte_write(obj, data[count]) != 1) {
i2c_stop(obj);
return 0;
}
}
// If not repeated start, send stop.
if (stop) {
i2c_stop(obj);
}
return count;
}
示例3: I2C_Write
Status I2C_Write(I2C_TypeDef* I2Cx, const uint8_t* buf, uint32_t nbyte, uint8_t SlaveAddress)
{
__IO uint32_t Timeout = 0;
/* Enable Error IT (used in all modes: DMA, Polling and Interrupts */
// I2Cx->CR2 |= I2C_IT_ERR;
if (nbyte)
{
Timed(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
// Intiate Start Sequence
I2C_GenerateSTART(I2Cx, ENABLE);
Timed(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
// Send Address EV5
I2C_Send7bitAddress(I2Cx, SlaveAddress, I2C_Direction_Transmitter);
//Timed(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
// EV6
// Write first byte EV8_1
I2C_SendData(I2Cx, *buf++);
while (--nbyte) {
// wait on BTF
//Timed(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_BTF));
I2C_SendData(I2Cx, *buf++);
}
//Timed(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_BTF));
I2C_GenerateSTOP(I2Cx, ENABLE);
//Timed(I2C_GetFlagStatus(I2C1, I2C_FLAG_STOPF));
}
return Success;
errReturn:
return Error;
}
示例4: AT24_Read
uint32_t AT24_Read(uint16_t Addr, uint8_t *pdata, int size)
{
uint32_t Timeout;
I2C_AcknowledgeConfig(I2C1, ENABLE);
Timeout = I2C_TIMEOUT;
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)) { if((Timeout--) == 0) return 1; }
I2C_GenerateSTART(I2C1, ENABLE);
Timeout = I2C_TIMEOUT;
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) { if((Timeout--) == 0) return 1; }
I2C_Send7bitAddress(I2C1, 0xA0, I2C_Direction_Transmitter);
Timeout = I2C_TIMEOUT;
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) { if((Timeout--) == 0) return 1; }
I2C_SendData(I2C1, (uint8_t)((Addr & 0xFF00) >> 8));
Timeout = I2C_TIMEOUT;
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) { if((Timeout--) == 0) return 1; }
I2C_SendData(I2C1, (uint8_t)(Addr & 0x00FF));
Timeout = I2C_TIMEOUT;
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)) { if((Timeout--) == 0) return 0; }
I2C_GenerateSTART(I2C1, ENABLE);
Timeout = I2C_TIMEOUT;
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) { if((Timeout--) == 0) return 1; }
I2C_Send7bitAddress(I2C1, 0xA1, I2C_Direction_Receiver);
while(size-- > 0)
{
Timeout = I2C_TIMEOUT;
while(!I2C_CheckEvent(I2C1,I2C_EVENT_MASTER_BYTE_RECEIVED))
{
if((Timeout--) == 0) return 1;
}
*(pdata++) = I2C_ReceiveData(I2C1);
}
I2C_AcknowledgeConfig(I2C1, DISABLE);
I2C_GenerateSTOP(I2C1, ENABLE);
return 0;
}
示例5: ucI2C_ReadAck
uint8_t ucI2C_ReadAck(I2C_TypeDef* I2Cx) {
uint8_t data;
/* Enable ACK */
I2Cx->CR1 |= I2C_CR1_ACK;
/* Wait till not received */
TM_I2C_Timeout = TM_I2C_TIMEOUT;
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)) {
if (--TM_I2C_Timeout == 0x00) {
return 1;
}
}
/* Read data */
data = I2Cx->DR;
/* Return data */
return data;
}
示例6: sEE_I2C_DMA_TX_IRQHandler
/**
* @brief This function handles the DMA Tx Channel interrupt Handler.
* @note This function should be called in the
* DMA1_CHANNEL2_3_IRQHandler in the stm8l15x_it.c file.
*
* // INTERRUPT_HANDLER(DMA1_CHANNEL2_3_IRQHandler, 3)
* // {
* // sEE_I2C_DMA_TX_IRQHandler();
* // }
* @param None
* @retval None
*/
void sEE_I2C_DMA_TX_IRQHandler(void)
{
/* Check if the DMA transfer is complete */
if (DMA_GetFlagStatus(sEE_I2C_DMA_FLAG_TX_TC) != RESET)
{
/* Disable the DMA Tx Channel and Clear all its Flags */
DMA_Cmd(sEE_I2C_DMA_CHANNEL_TX, DISABLE);
DMA_ClearFlag(sEE_I2C_DMA_FLAG_TX_TC);
/*!< Wait till all data have been physically transferred on the bus */
while (!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
{}
/*!< Send STOP condition */
I2C_GenerateSTOP(sEE_I2C, ENABLE);
/* Reset the variable holding the number of data to be written */
*sEEDataWritePointer = 0;
}
}
示例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: sensor_read
uint8_t sensor_read(uint8_t sensor_address, uint8_t SUB)//read a byte from sensor
{
uint8_t data;
/* Send START condition */
I2C_GenerateSTART(I2C2, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
/* In the case of a single data transfer disable ACK before reading the data */
I2C_AcknowledgeConfig(I2C2, DISABLE);
/* Send EEPROM address for write */
sensor_address=sensor_address|0x01;
I2C_Send7bitAddress(I2C2, sensor_address, I2C_Direction_Transmitter); //0xD2
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Send the EEPROM's internal address to write to */
I2C_SendData(I2C2, SUB);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(I2C2, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for read */
I2C_Send7bitAddress(I2C2, sensor_address, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
/* Send STOP Condition */
I2C_GenerateSTOP(I2C2, ENABLE);
/* Test on EV7 and clear it */
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED));
/* Read a byte from the EEPROM */
data = I2C_ReceiveData(I2C2);
return data;
}
示例9: I2C_Read_Buf
uint32_t I2C_Read_Buf(uint8_t* buf_ptr, uint32_t len){
uint32_t nbytes = 0;
I2C_AcknowledgeConfig(I2Cx, ENABLE);
for (nbytes = 0; nbytes < (int) len; nbytes++) {
/* Send NACK on the last byte */
if (nbytes == ((int) len - 1)) {
I2C_AcknowledgeConfig(I2Cx, DISABLE);
/* Send STOP Condition */
I2C_GenerateSTOP(I2Cx, ENABLE);
}
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED)){}
/* Read a byte from the slave */
buf_ptr[nbytes] = I2C_ReceiveData(I2Cx);
}
return nbytes;
}
示例10: ITG3200_read_burst
void ITG3200_read_burst(I2C_TypeDef * I2Cx, uint8_t devwrite ,uint8_t * data_out, uint8_t nBytes){
// I2C_read_burst(I2Cx, slave_addr,ITG3200_XOUT_H, data_out, nBytes);
I2C_start(I2Cx, devwrite, I2C_Direction_Transmitter);
I2C_SendData(I2Cx,ITG3200_XOUT_H);
while (I2C_GetFlagStatus(I2Cx, I2C_FLAG_BTF) == RESET);
I2C_stop(I2Cx);
I2C_start(I2Cx,devwrite, I2C_Direction_Receiver);
I2C_AcknowledgeConfig(I2Cx, ENABLE);
for(int i= 0; i < nBytes; i++) {
while( !I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED) );
data_out[i] = I2C_ReceiveData(I2Cx);
}
//set the stack pointer to X MSB
//I2C_SendData(I2Cx,HMC8883_DATA_OUT_X_MSB_REG_ADDR);
I2C_AcknowledgeConfig(I2Cx, DISABLE);
I2C_stop(I2Cx);
}
示例11: readEndByteI2C
/**
*************************************************************************************
* @brief read one byte without acknowledge and end conversation
* @param None
* @retval the received byte
**************************************************************************************
*/
static uint8_t readEndByteI2C(void){
/* buffer for the received byte */
uint8_t ReceivedByte;
/* disabe acknowledge of received data */
I2C_AcknowledgeConfig(I2C, DISABLE);
/* wait until one byte has been received */
while( !I2C_CheckEvent(I2C, I2C_EVENT_MASTER_BYTE_RECEIVED) );
/* read data from I2C data register and return data byte */
ReceivedByte = I2C_ReceiveData(I2C);
/* send stop condition */
I2C_GenerateSTOP(I2C, ENABLE);
/* return value */
return ReceivedByte;
}
示例12: i2c_read
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop) {
I2C_TypeDef *i2c = (I2C_TypeDef *)(obj->i2c);
int timeout;
int count;
int value;
if (length == 0) return 0;
i2c_start(obj);
// Send slave address for read
I2C_Send7bitAddress(i2c, address, I2C_Direction_Receiver);
// Wait address is acknowledged
timeout = FLAG_TIMEOUT;
while (I2C_CheckEvent(i2c, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED) == ERROR) {
timeout--;
if (timeout == 0) {
return 0;
}
}
// Read all bytes except last one
for (count = 0; count < (length - 1); count++) {
value = i2c_byte_read(obj, 0);
data[count] = (char)value;
}
// If not repeated start, send stop.
// Warning: must be done BEFORE the data is read.
if (stop) {
i2c_stop(obj);
}
// Read the last byte
value = i2c_byte_read(obj, 1);
data[count] = (char)value;
return length;
}
示例13: I2C_ReadSByte1
void I2C_ReadSByte1(u8 id,u16 addr ,u8* pBuffer,u16 no)
{
if(no==0)
return;
while(I2C_GetFlagStatus(I2C2, I2C_FLAG_BUSY));
/*允许1字节1应答模式*/
I2C_AcknowledgeConfig(I2C2, ENABLE);
/* 发送起始位 */
I2C_GenerateSTART(I2C2, ENABLE);
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));/*EV5,主模式*/
/*发送器件地址(写)*/
I2C_Send7bitAddress(I2C2, id&0xfe, I2C_Direction_Transmitter);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/*发送地址*/
I2C_SendData(I2C2, addr>>8);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));/*数据已发送*/
I2C_SendData(I2C2, addr);
while (!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED));/*数据已发送*/
/*起始位*/
I2C_GenerateSTART(I2C2, ENABLE);
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT));
/*器件读*/
I2C_Send7bitAddress(I2C2, id|I2C_READ, I2C_Direction_Receiver);
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
while (no)
{
if(no==1)
{
I2C_AcknowledgeConfig(I2C2, DISABLE); //最后一位后要关闭应答的
I2C_GenerateSTOP(I2C2, ENABLE); //发送停止位
}
while(!I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_RECEIVED)); /* EV7 */
*pBuffer = I2C_ReceiveData(I2C2);
pBuffer++;
/* Decrement the read bytes counter */
no--;
}
//再次允许应答模式
I2C_AcknowledgeConfig(I2C2, ENABLE);
}
示例14: i2cRead
void i2cRead(uint8_t device, uint8_t address, uint8_t *data, uint8_t length)
{
i2cSendAddress(device, READ, address);
int i;
for(i = 0; i<length; i++)
{
/* Test on EV7 and clear it */
while(!I2C_CheckEvent(I2C_BUS, I2C_EVENT_MASTER_BYTE_RECEIVED));
*data = I2C_ReceiveData(I2C_BUS);
data++;
/* Disable Acknowledgement */
if(!(i < (length - 1)))
I2C_AcknowledgeConfig(I2C_BUS, DISABLE);
}
/* Send STOP Condition */
I2C_GenerateSTOP(I2C_BUS, ENABLE);
}
示例15: read8
short read8(I2C_TypeDef* I2Cx){
uint8_t msb=0, lsb=0;
unsigned char dummy1;
unsigned short data;
I2C_AcknowledgeConfig(I2Cx, ENABLE);
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY));
I2C_GenerateSTART(I2Cx, ENABLE);
while(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_SB));
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT));
I2C_Send7bitAddress(I2Cx,0x6B<<1,I2C_Direction_Transmitter);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2Cx,0x28);
while(!I2C_GetFlagStatus(I2Cx,I2C_FLAG_TXE));
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_GenerateSTART(I2Cx, ENABLE);
while(!I2C_GetFlagStatus(I2Cx, I2C_FLAG_SB));
I2C_Send7bitAddress(I2Cx, 0x6B<<1, I2C_Direction_Receiver);
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
msb = I2C_ReceiveData(I2Cx);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED));
I2C_NACKPositionConfig(I2Cx, I2C_NACKPosition_Current);
I2C_AcknowledgeConfig(I2Cx, DISABLE);
lsb = I2C_ReceiveData(I2Cx);
while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED));
//dummy1 = I2C_ReceiveData(I2Cx);
//while(!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_BYTE_RECEIVED));
I2C_GenerateSTOP(I2Cx, ENABLE);
while(I2C_GetFlagStatus(I2Cx, I2C_FLAG_STOPF));
data = msb<<8;
data |= lsb;
return data;
}