# i2c_hardware

I2C hardware library

Author | Stef Mientki, Copyright © 2005..2025, all rights reserved.
Adapted-by | Joep Suijs, Albert Faber, Rob Jansen
Compiler | 2.5r9

Description

    Hardware implementation of I2C 1 (single) master.

Dependencies

No dependency found

## Summary

### Global variables/contants

- `const _i2c_slowest = 127`
- `const _i2c_100khz = target_clock / 100_000 / 4 - 1`
- `const _i2c_1mhz = target_clock / 1_000_000 / 4 - 1`
- `const _i2c_400khz = target_clock / 400_000 / 4 - 1`

### Procedures

- `i2c_restart()`
- `i2c_initialize()`
- `i2c_stop()`
- `i2c_start()`

### Functions

- `i2c_receive_byte(bit in ACK ) return byte`
- `i2c_transmit_byte(byte in data) return bit`

## API details

### Global variables/contants

- `const _i2c_slowest = 127`

      Some constants needed for the baudrate generator.
      Can be overruled by I2C_USER_BUS_SPEED.

- `const _i2c_100khz = target_clock / 100_000 / 4 - 1`

      (default)

- `const _i2c_1mhz = target_clock / 1_000_000 / 4 - 1`

  No documentation found

- `const _i2c_400khz = target_clock / 400_000 / 4 - 1`

  No documentation found

### Procedures

- `i2c_restart()`

      Sends Restart bit and waits until finished or timeout (if defined)

- `i2c_initialize()`

      if the device has changed, change the speed if necessary

- `i2c_stop()`

      Sends Stop bit and waits until finished or timeout (if defined)

- `i2c_start()`

      Sends Start bit and waits until finished or timeout (if defined)

### Functions

- `i2c_receive_byte(bit in ACK ) return byte`

      start receiving of a byte and waits till finished or timeout (if defined)
      if param ACK is true, the byte is acknowledged and next bytes can be received.
      if param ACK is false, the byte is nacked and a stop *should be* sent.
      note: this behavior is inverted from the line level and orignal library, but
      consistent with the i2c_software library.

- `i2c_transmit_byte(byte in data) return bit`

      Returns TRUE when OK and FALSE in case of an error or  when a timeout occurs
      (if defined)

## Related samples

Here are the list of samples which use this library:

16f13115 | 16f13115_vl53l0x_continuous.jal
16f1823 | 16f1823_i2c_hw_eeprom_serial.jal
16f1825 | 16f1825_vl53l0x_continuous.jal
16f1825 | 16f1825_philips_rc_decoder_ssd1306.jal
16f1825 | 16f1825_vl53l0x_single.jal
16f1825 | 16f1825_nec_rc_decoder_ssd1306.jal
16f1825 | 16f1825_as5600l.jal
16f1825 | 16f1825_glcd_ssd1306_font.jal
16f1825 | 16f1825_mcp23008.jal
16f1825 | 16f1825_gps_neo_6m_ssd1306_clock.jal
16f1825 | 16f1825_ina3221.jal
16f1825 | 16f1825_rda5807m.jal
16f1825 | 16f1825_bmp180.jal
16f1825 | 16f1825_rtc_ds3231.jal
16f18325 | 16f18325_i2c_hw_l0.jal
16f18425 | 16f18425_i2c_hw_l0.jal
16f18857 | 16f18857_glcd_ssd1306_font_graphics.jal
16f877 | 16f877_i2c_hw_l0.jal
16f877 | 16f877_i2c_hw_l1.jal
16f877a | 16f877a_i2c_hw_l0.jal
16f877a | 16f877a_i2c_hw_l1.jal
16f877a | 16f877a_rtc_pcf8563.jal
16f877a | 16f877a_ds1307_hw.jal
18f14k50 | 18f14k50_i2c_hw_l1.jal
18f14k50 | 18f14k50_i2c_hw_l0.jal
18f2520 | 18f2520_i2c_hw_l0.jal
18f2520 | 18f2520_i2c_hw_l1.jal
18f2550 | 18f2550_i2c_hw_l0.jal
18f2550 | 18f2550_i2c_hw_l1.jal
18f25k22 | 18f25k22_i2c_hw_master_echo.jal
18f2620 | 18f2620_i2c_hw_l0.jal
18f2620 | 18f2620_i2c_hw_l1.jal
18f452 | 18f452_i2c_hw_l1.jal
18f452 | 18f452_i2c_hw_l0.jal
18f4550 | 18f4550_i2c_hw_l1.jal
18f4550 | 18f4550_i2c_hw_l0.jal
18f4620 | 18f4620_i2c_hw_l0.jal
18f4620 | 18f4620_i2c_hw_l1.jal
18f67j50 | 18f67j50_i2c_hw_l1.jal
18f67j50 | 18f67j50_i2c_hw_l0.jal
18f67k22 | 18f67k22_co2_i2c.jal