Skip to content

Commit

Permalink
Fix for moved doc file and trailing whitespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
sonaux committed Feb 18, 2019
1 parent 2371f3b commit e0ad886
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
18 changes: 9 additions & 9 deletions app/driver/i2c_master.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,20 @@
// enable use GPIO16 (D0) pin as SCL line
#ifdef I2C_MASTER_GPIO16_ENABLE
#define IS_PIN16(n) ((n)==16)
// CPU_CYCLES_BETWEEN_DELAYS describes how much cpu cycles code runs
// CPU_CYCLES_BETWEEN_DELAYS describes how much cpu cycles code runs
// between i2c_master_setDC() calls if delay is zero and i2c_master_set_DC_delay()
// is not being called. This is not exact value, but proportional with length of code.
// Increasing the value results in less delay and faster i2c clock speed.
#define CPU_CYCLES_BETWEEN_DELAYS 80
// CPU_CYCLES_GPIO16 is added to CPU_CYCLES_BETWEEN_DELAYS,
// CPU_CYCLES_GPIO16 is added to CPU_CYCLES_BETWEEN_DELAYS,
// as RTC-related IO takes much more time than standard GPIOs.
// Increasing the value results in less delay and faster i2c clock speed for GPIO16.
#define CPU_CYCLES_GPIO16 90

#else
// If GPIO16 support is not enabled, remove GPIO16-related code during compile
// and change timing constants.
#define IS_PIN16(n) (0)
#define IS_PIN16(n) (0)
#define CPU_CYCLES_BETWEEN_DELAYS 74
#endif //I2C_MASTER_GPIO16_ENABLE

Expand Down Expand Up @@ -275,7 +275,7 @@ i2c_master_setup(uint16 id, uint8 sda, uint8 scl, uint32 speed)
ETS_GPIO_INTR_DISABLE(); //disable gpio interrupts

if (IS_PIN16(i2c[id]->pin_SCL)){ //if GPIO16
CLEAR_PERI_REG_MASK(PAD_XPD_DCDC_CONF, 0x43); //disable all functions for XPD_DCDC
CLEAR_PERI_REG_MASK(PAD_XPD_DCDC_CONF, 0x43); //disable all functions for XPD_DCDC
SET_PERI_REG_MASK(PAD_XPD_DCDC_CONF, 0x1); // select function RTC_GPIO0 for pin XPD_DCDC
CLEAR_PERI_REG_MASK(RTC_GPIO_CONF, 0x1); //mux configuration for out enable
SET_PERI_REG_MASK(RTC_GPIO_ENABLE, 0x1); //out enable
Expand Down Expand Up @@ -347,7 +347,7 @@ i2c_master_readByte(uint16 id, sint16 ack)
sint8 i;
//invert and clamp ACK to 0/1, because ACK == 1 for i2c means SDA in low state
uint8 ackLevel = (ack ? 0 : 1);

i2c_master_setDC(id, i2c[id]->last_SDA, 0);
i2c_master_setDC(id, 1, 0);
for (i = 7; i >= 0; i--) {
Expand Down Expand Up @@ -448,7 +448,7 @@ i2c_master_setDC(uint8 SDA, uint8 SCL)
I2C_MASTER_SDA_HIGH_SCL_LOW();
} else {
I2C_MASTER_SDA_HIGH_SCL_HIGH();
}
}

if(1 == SCL) {
do {
Expand Down Expand Up @@ -517,7 +517,7 @@ i2c_master_configured(uint16 id)
* FunctionName : i2c_master_setup
* Description : config SDA and SCL gpio to open-drain output mode,
* mux and gpio num defined in i2c_master.h
* Parameters : bus id, uint8 sda, uint8 scl, uint32 speed
* Parameters : bus id, uint8 sda, uint8 scl, uint32 speed
* Returns : configured speed
*******************************************************************************/
uint32 ICACHE_FLASH_ATTR
Expand Down Expand Up @@ -589,7 +589,7 @@ i2c_master_readByte(uint16 id, sint16 ack)
uint8 retVal = 0;
uint8 k, i;
uint8 ackLevel = (ack ? 0 : 1);

i2c_master_wait(5);
i2c_master_setDC(m_nLastSDA, 0);

Expand Down Expand Up @@ -632,7 +632,7 @@ i2c_master_writeByte(uint16 id, uint8 wrdata)
uint8 dat;
sint8 i;
uint8 retVal;

i2c_master_wait(5);

i2c_master_setDC(m_nLastSDA, 0);
Expand Down
8 changes: 4 additions & 4 deletions docs/modules/i2c.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# I²C Module
| Since | Origin / Contributor | Maintainer | Source |
| :----- | :-------------------- | :---------- | :------ |
| 2014-12-22 | [Zeroday](https://github.com/funshine) | [Zeroday](https://github.com/funshine) | [i2c.c](../../../app/modules/i2c.c)|
| 2018-08-30 | [Natalia Sorokina](https://github.com/sonaux) | | [i2c_master.c](../../../app/driver/i2c_master.c)|
| 2014-12-22 | [Zeroday](https://github.com/funshine) | [Zeroday](https://github.com/funshine) | [i2c.c](../../app/modules/i2c.c)|
| 2018-08-30 | [Natalia Sorokina](https://github.com/sonaux) | | [i2c_master.c](../../app/driver/i2c_master.c)|

I²C (I2C, IIC) is a serial 2-wire bus for communicating with various devices. Also known as SMBus or TWI, though SMBus have some additions to the I2C protocol.
ESP8266 chip does not have hardware I²C, so module uses software I²C driver.
Expand All @@ -15,14 +15,14 @@ This module supports:
- Clock stretching (slow slave device can tell the master to wait)
- Sharing SDA line over multiple I²C buses to save available pins
- GPIO16 pin can be used as SCL pin, but selected bus will be limited to not more than FAST speed.

HIGH-speed mode (3.5MHz clock) and 10-bit addressing scheme is not supported.

You have to call `i2c.setup` on a given I²C bus at least once before communicating to any device connected to that bus, otherwise you will get an error.

I²C bus designed to work in open-drain mode, so it needs pull-up resistors 1k - 10k on SDA and SCL lines. Though many peripheral modules have pull-up resistors onboard and will work without additional external resistors.

Hint for using many identical devices with same address:
Hint for using many identical devices with same address:
Many devices allow to choose between 2 I²C addresses via pin or soldered 0 Ohm resistor.
If address change is not an option or you need to use more than 2 similar devices, you can use different I²C buses.
Initialize them once by calling `i2c.setup` with different bus numbers and pins, then refer to each device by bus id and device address.
Expand Down

0 comments on commit e0ad886

Please sign in to comment.