| Kinetis SDK Demo Applications User Guide 1.0.0-beta Freescale Semiconductor, Inc.

- Main Page
- Related Pages
- Demos

All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
i2c_sim.c File Reference
`#include "fsl_gpio_hal.h"`
`#include "i2c_sim.h"`
`#include "fsl_os_abstraction.h"`
`#include "fsl_clock_manager.h"`

## Macros
#define | I2C_INIT
#define | I2C_ACTIVE
#define | I2C_TRISTATE
#define | I2C_READ
#define | I2C_SDA_DIR(dir)
#define | I2C_SDA(bit)
#define | I2C_SCL(bit)
#define | I2C_DELAY
#define | RETRIES
#define | I2C_ACK
#define | I2C_NOACK
#define | PRINTD(fmt, args...)

## Functions
static void | send_start (void)
| Send START. More...
static void | send_stop (void)
| Send STOP. More...
static void | send_ack (int32_t ack)
| Send ACK. More...
static int32_t | write_byte (uint8_t data)
| Send 8 bits and look for an acknowledgement. More...
static uint8_t | read_byte (int32_t ack)
| Read one byte. More...
void | i2c_gpio_init (int32_t speed, int32_t slaveaddr)
| Initialization. More...
uint8_t | i2c_gpio_probe (uint8_t addr)
| Probe to see if a chip is present. Probe to see if a chip is present. Also good for checking for the completion of EEPROM writes since the chip stops responding until the write completes (typically 10mSec). More...
uint8_t | i2c_gpio_read (uint8_t chip, uint32_t addr, int32_t alen, uint8_t *buffer, int32_t len)
| Read bytes. More...
uint8_t | i2c_gpio_write (uint8_t chip, uint32_t addr, int32_t alen, uint8_t *buffer, int32_t len)
| Write bytes. More...

## Macro Definition Documentation

#define I2C_ACK

#define I2C_ACTIVE

#define I2C_DELAY

#define I2C_INIT

#define I2C_NOACK

#define I2C_READ

#define I2C_SCL | ( |  | bit | ) |

#define I2C_SDA | ( |  | bit | ) |

#define I2C_SDA_DIR | ( |  | dir | ) |

#define I2C_TRISTATE

#define PRINTD | ( |  | fmt,
|  |  | args...
| ) |  |

#define RETRIES

## Function Documentation

void i2c_gpio_init | ( | int32_t | speed,
|  | int32_t | slaveaddr
| ) |  |

Parameters

  [in] | speed | I2C speed.
  [in] | slaveaddr | Slave device address.

uint8_t i2c_gpio_probe | ( | uint8_t | addr | ) |

Parameters

  [in] | addr | I2C slave device address.

Returns
  Probe successful or failed.

uint8_t i2c_gpio_read | ( | uint8_t | chip,
|  | uint32_t | addr,
|  | int32_t | alen,
|  | uint8_t * | buffer,
|  | int32_t | len
| ) |  |

This function will read data from i2c slave device.

Parameters

  [in] | chip | Chip number.
  [in] | addr | Address in I2C slave device.
  [in] | alen | Address len.
  [in] | buffer | Buffer address that will be read to.
  [in] | len | Len of data that will be read.

Returns
  Read successful or not.

uint8_t i2c_gpio_write | ( | uint8_t | chip,
|  | uint32_t | addr,
|  | int32_t | alen,
|  | uint8_t * | buffer,
|  | int32_t | len
| ) |  |

This function will write data to i2c slave device.

Parameters

  [in] | chip | Chip address.
  [in] | addr | Address in I2C slave device.
  [in] | alen | Address len.
  [in] | buffer | Buffer address that will be write.
  [in] | len | Len of data that will be write.

Returns
  Write failed times.

static uint8_t read_byte | ( | int32_t | ack | ) |
| static

if ack == I2C_ACK, ACK the byte so can continue reading, else send I2C_NOACK to end the read.

Parameters

  [in] | ack | Ack data that to be sent.

Returns
  Read data byte.

static void send_ack | ( | int32_t | ack | ) |
| static

Send ACK. Ack should be I2C_ACK or I2C_NOACK.

static void send_start | ( | void |  | ) |
| static

Send START. High -> Low on SDA while SCL is High.

static void send_stop | ( | void |  | ) |
| static

Send STOP. STOP: Low -> High on SDA while SCL is High.

static int32_t write_byte | ( | uint8_t | data | ) |
| static

Parameters

  [in] | data | Data that will be write.

Returns
  Ackledge value. Not a nack is an ack.