本文整理汇总了C++中i2c_master_wait函数的典型用法代码示例。如果您正苦于以下问题:C++ i2c_master_wait函数的具体用法?C++ i2c_master_wait怎么用?C++ i2c_master_wait使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了i2c_master_wait函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: i2c_master_readByte
/******************************************************************************
* FunctionName : i2c_master_readByte
* Description : read Byte from i2c bus
* Parameters : NONE
* Returns : uint8 - readed value
*******************************************************************************/
uint8 i2c_master_readByte(void)
{
uint8 retVal = 0;
uint8 k, i;
i2c_master_setDC(1, m_nLastSCL);
for (i = 0; i < 8; i++) {
i2c_master_wait(I2C_SLEEP_TIME);
i2c_master_setDC(1, 0);
i2c_master_wait(I2C_SLEEP_TIME);// sda 1, scl 0
i2c_master_setDC(1, 1);
while(i2c_master_getCL()==0)
; // clock stretch
i2c_master_wait(I2C_SLEEP_TIME);// sda 1, scl 1
k = i2c_master_getDC();
i2c_master_wait(I2C_SLEEP_TIME);
//if (i == 7) {
// i2c_master_wait(5); ////
//}
k <<= (7 - i);
retVal |= k;
}
i2c_master_setDC(m_nLastSDA, 0);
i2c_master_wait(I2C_SLEEP_TIME);// sda 1, scl 0
return retVal;
}
示例2: i2c_master_writeByte
/******************************************************************************
* FunctionName : i2c_master_writeByte
* Description : write wrdata value(one byte) into i2c
* Parameters : uint8 wrdata - write value
* Returns : NONE
*******************************************************************************/
void i2c_master_writeByte(uint8 wrdata)
{
uint8 dat;
sint8 i;
/*
i2c_master_wait(I2C_SLEEP_TIME);
i2c_master_setDC(m_nLastSDA, 0);
*/
i2c_master_wait(I2C_SLEEP_TIME);
for (i = 7; i >= 0; i--) {
dat = wrdata >> i;
i2c_master_setDC(dat, 0);
i2c_master_wait(I2C_SLEEP_TIME);
i2c_master_setDC(dat, 1);
i2c_master_wait(I2C_SLEEP_TIME);
/*
if (i == 0) {
i2c_master_wait(5); ////
}
*/
i2c_master_setDC(dat, 0);
i2c_master_wait(I2C_SLEEP_TIME);
}
}
示例3: i2c_master_readByte
/******************************************************************************
* FunctionName : i2c_master_readByte
* Description : read Byte from i2c bus
* Parameters : NONE
* Returns : uint8 - readed value
*******************************************************************************/
uint8 ICACHE_FLASH_ATTR
i2c_master_readByte(void)
{
uint8 retVal = 0;
uint8 k, i;
i2c_master_wait(I2C_DELAY);
i2c_master_setDC(m_nLastSDA, 0); // sda 1, scl 0
for (i = 0; i < 8; i++) {
i2c_master_wait(I2C_DELAY);
i2c_master_setDC(1, 0); // sda 1, scl 0
i2c_master_setDC(1, 1); // sda 1, scl 1
k = i2c_master_getDC();
if (i == 7) {
i2c_master_wait(I2C_DELAY); // extra delay
}
k <<= (7 - i);
retVal |= k;
}
i2c_master_setDC(1, 0); // sda 1, scl 0
return retVal;
}
示例4: i2c_master_init
/******************************************************************************
* FunctionName : i2c_master_init
* Description : initilize I2C bus to enable i2c operations
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_init(void)
{
uint8 i;
i2c_master_setDC(1, 0);
i2c_master_wait(5);
// when SCL = 0, toggle SDA to clear up
i2c_master_setDC(0, 0) ;
i2c_master_wait(5);
i2c_master_setDC(1, 0) ;
i2c_master_wait(5);
// set data_cnt to max value
for (i = 0; i < 28; i++) {
i2c_master_setDC(1, 0);
i2c_master_wait(5); // sda 1, scl 0
i2c_master_setDC(1, 1);
i2c_master_wait(5); // sda 1, scl 1
}
// reset all
i2c_master_stop();
return;
}
示例5: i2c_master_start
/******************************************************************************
* FunctionName : i2c_master_start
* Description : set i2c to send state
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void i2c_master_start(void)
{
i2c_master_setDC(1, m_nLastSCL);
i2c_master_wait(I2C_SLEEP_TIME);
i2c_master_setDC(1, 1);
i2c_master_wait(I2C_SLEEP_TIME);// sda 1, scl 1
i2c_master_setDC(0, 1);
i2c_master_wait(I2C_SLEEP_TIME);// sda 0, scl 1
}
示例6: i2c_master_start
/******************************************************************************
* FunctionName : i2c_master_start
* Description : set i2c to send state
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_start(void)
{
i2c_master_setDC(1, m_nLastSCL);
i2c_master_wait(5);
i2c_master_setDC(1, 1);
i2c_master_wait(5); // sda 1, scl 1
i2c_master_setDC(0, 1);
i2c_master_wait(5); // sda 0, scl 1
}
示例7: i2c_master_stop
/******************************************************************************
* FunctionName : i2c_master_stop
* Description : set i2c to stop sending state
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_stop(void)
{
i2c_master_wait(I2C_DELAY_FULL);
i2c_master_setDC(0, m_nLastSCL);
i2c_master_wait(I2C_DELAY_FULL); // sda 0
i2c_master_setDC(0, 1);
i2c_master_wait(I2C_DELAY_FULL); // sda 0, scl 1
i2c_master_setDC(1, 1);
i2c_master_wait(I2C_DELAY_FULL); // sda 1, scl 1
}
示例8: i2c_master_stop
/******************************************************************************
* FunctionName : i2c_master_stop
* Description : set i2c to stop sending state
* Parameters : NONE
* Returns : NONE
*******************************************************************************/
void ICACHE_RAM_ATTR
i2c_master_stop(void)
{
i2c_master_wait(5);
i2c_master_setDC(0, m_nLastSCL);
i2c_master_wait(5); // sda 0
i2c_master_setDC(0, 1);
i2c_master_wait(5); // sda 0, scl 1
i2c_master_setDC(1, 1);
i2c_master_wait(5); // sda 1, scl 1
}
示例9: i2c_master_setAck
/******************************************************************************
* FunctionName : i2c_master_setAck
* Description : set ack to i2c bus as level value
* Parameters : uint8 level - 0 or 1
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_setAck(uint8 level)
{
i2c_master_setDC(level, 0);
i2c_master_wait(2); // sda level, scl 0
i2c_master_setDC(level, 1);
i2c_master_wait(4); // sda level, scl 1
i2c_master_setDC(level, 0);
i2c_master_wait(2); // sda level, scl 0
i2c_master_setDC(1, 0);
i2c_master_wait(2);
}
示例10: i2c_master_setAck
/******************************************************************************
* FunctionName : i2c_master_setAck
* Description : set ack to i2c bus as level value
* Parameters : uint8 level - 0 or 1
* Returns : NONE
*******************************************************************************/
void i2c_master_setAck(uint8 level)
{
i2c_master_setDC(m_nLastSDA, 0);
i2c_master_wait(I2C_SLEEP_TIME);
i2c_master_setDC(level, 0);
i2c_master_wait(I2C_SLEEP_TIME);// sda level, scl 0
i2c_master_setDC(level, 1);
i2c_master_wait(8);// sda level, scl 1
i2c_master_setDC(level, 0);
i2c_master_wait(I2C_SLEEP_TIME);// sda level, scl 0
i2c_master_setDC(1, 0);
i2c_master_wait(I2C_SLEEP_TIME);
}
示例11: i2c_master_getAck
/******************************************************************************
* FunctionName : i2c_master_getAck
* Description : confirm if peer send ack
* Parameters : NONE
* Returns : uint8 - ack value, 0 or 1
*******************************************************************************/
uint8 ICACHE_FLASH_ATTR
i2c_master_getAck(void)
{
uint8 retVal;
i2c_master_setDC(1, 0);
i2c_master_wait(2);
i2c_master_setDC(1, 1);
i2c_master_wait(4);
retVal = i2c_master_getDC();
i2c_master_setDC(1, 0);
i2c_master_wait(2);
return !retVal; // 0->true->ACK, 1->false->NACK
}
示例12: i2c_master_setAck
/******************************************************************************
* FunctionName : i2c_master_setAck
* Description : set ack to i2c bus as level value
* Parameters : uint8 level - 0 or 1
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_setAck(uint8 level)
{
i2c_master_setDC(m_nLastSDA, 0);
i2c_master_wait(I2C_DELAY_FULL);
i2c_master_setDC(level, 0);
i2c_master_wait(I2C_DELAY_FULL); // sda level, scl 0
i2c_master_setDC(level, 1);
i2c_master_wait(I2C_DELAY_LONG); // sda level, scl 1
i2c_master_setDC(level, 0);
i2c_master_wait(I2C_DELAY_FULL); // sda level, scl 0
i2c_master_setDC(1, 0);
i2c_master_wait(I2C_DELAY_FULL);
}
示例13: i2c_master_setAck
/******************************************************************************
* FunctionName : i2c_master_setAck
* Description : set ack to i2c bus as level value
* Parameters : uint8 level - 0 or 1
* Returns : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_setAck(uint8 level)
{
i2c_master_setDC(m_nLastSDA, 0);
i2c_master_wait(5);
i2c_master_setDC(level, 0);
i2c_master_wait(5); // sda level, scl 0
i2c_master_setDC(level, 1);
i2c_master_wait(8); // sda level, scl 1
i2c_master_setDC(level, 0);
i2c_master_wait(5); // sda level, scl 0
i2c_master_setDC(1, 0);
i2c_master_wait(5);
}
示例14: read_cb
LOCAL void ICACHE_FLASH_ATTR
read_cb(void)
{
uint8_t ack, low, high;
wdt_feed();
os_printf("Time=%ld\n", system_get_time());
i2c_master_start();
i2c_master_writeByte(BH1750_ADDR);
ack = i2c_master_getAck();
if (ack)
{
os_printf("I2C:No ack after sending address\n");
i2c_master_stop();
return;
}
i2c_master_stop();
i2c_master_wait(40000); // why?
i2c_master_start();
i2c_master_writeByte(BH1750_ADDR + 1);
ack = i2c_master_getAck();
if (ack)
{
os_printf("I2C:No ack after write command\n");
i2c_master_stop();
return;
}
low = i2c_master_readByte();
high = i2c_master_readByte();
i2c_master_setAck(1);
i2c_master_stop();
os_printf("I2C:read(L/H)=(0x%02x/0x%02x)\n", low, high);
}
示例15: i2c_master_getDC
/******************************************************************************
* FunctionName : i2c_master_getDC
* Description : Internal used function -
* get i2c SDA bit value
* Parameters : NONE
* Returns : uint8 - SDA bit value
*******************************************************************************/
LOCAL uint8 ICACHE_FLASH_ATTR
i2c_master_getDC(void)
{
uint8 sda_out;
sda_out = GPIO_INPUT_GET(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO));
i2c_master_wait(I2C_DELAY);
return sda_out;
}