예제 #1
0
void i2c_stop(void) {
	// set SDA to 0
	clear_SDA();
	I2C_delay();
	while (read_SCL() == 0); // Clock stretching
	I2C_delay();
	if (read_SDA() == 0) {
		arbitration_lost();
	}
	I2C_delay();
	started = 0;
}
예제 #2
0
void i2c_write_bit(unsigned char bit) {
	if (bit) {
		read_SDA();
	} else {
		clear_SDA();
	}
	I2C_delay();
	while (read_SCL() == 0); // Clock stretching
	if (bit && read_SDA() == 0) {
		//Houve problema de comunicação
	}
	I2C_delay();
	clear_SCL();
	I2C_delay();
}
예제 #3
0
void i2c_stop_cond(void){
  // set SDA to 0
  clear_SDA();
  I2C_delay();
  // Clock stretching
  while (read_SCL() == 0) {
    // add timeout to this loop.
  }
  // Stop bit setup time, minimum 4us
  I2C_delay();
  // SCL is high, set SDA from 0 to 1
  if (read_SDA() == 0) {
    arbitration_lost();
  }
  I2C_delay();
  started = false;
}
예제 #4
0
// Write a bit to I2C bus
void i2c_write_bit(bool bit) {
  if (bit) {
    read_SDA();
  } else {
    clear_SDA();
  }
  I2C_delay();
  while (read_SCL() == 0) { // Clock stretching
    // You should add timeout to this loop
  }
  // SCL is high, now data is valid
  // If SDA is high, check that nobody else is driving SDA
  if (bit && read_SDA() == 0) {
    arbitration_lost();
  }
  I2C_delay();
  clear_SCL();
}
예제 #5
0
void i2c_start(void) {
	//se já estiver iniciado, prepara para reenviar o bit de start
	if (started) { 
		read_SDA();
		I2C_delay();
		while (read_SCL() == 0); // Clock stretching
		// Repeated start setup time, minimum 4.7us
		I2C_delay();
	}
	if (read_SDA() == 0) {
		//Houve problema de comunicação
	}
	// SCL is high, set SDA from 1 to 0.
	clear_SDA();
	I2C_delay();
	clear_SCL();
	started = 1;
}
예제 #6
0
void i2c_start_cond(void) {
  if (started) { // if started, do a restart cond
    // set SDA to 1
    read_SDA();
    I2C_delay();
    while (read_SCL() == 0) {  // Clock stretching
      // You should add timeout to this loop
    }
    // Repeated start setup time, minimum 4.7us
    I2C_delay();
  }
  if (read_SDA() == 0) {
    arbitration_lost();
  }
  // SCL is high, set SDA from 1 to 0.
  clear_SDA();
  I2C_delay();
  clear_SCL();
  started = true;
}