예제 #1
0
파일: twi.c 프로젝트: rghunter/LoggoDAQ
int i2c_stop() {
  READSDA();
  READSCL();
  sda=-1;
  scl=-1;
  I2CSPEED=-1;
  return 0;
}
예제 #2
0
파일: twi.c 프로젝트: rghunter/LoggoDAQ
static void stop_cond(void) {
   /* Pull SDA down */
   CLRSDA();
   I2CDELAY(I2CSPEED/2);
   /* Clock stretching - wait for slave to raise it*/
   while (READSCL() == 0);
   /* SCL is high, set SDA from 0 to 1 */
   if (READSDA() == 0) {
      ARBITRATION_LOST();
   }
   I2CDELAY(I2CSPEED/2);
   start = 0;
}
예제 #3
0
파일: twi.c 프로젝트: rghunter/LoggoDAQ
static unsigned char read_bit(void) {
   unsigned char bit;
 
   // Let the slave drive data
   READSDA();
   I2CDELAY(I2CSPEED/2);
   /* Clock stretching */
   while (READSCL() == 0);
   /* SCL is high, now data is valid */
   bit = READSDA();
   I2CDELAY(I2CSPEED/2);
   CLRSCL();
   return bit;
}
예제 #4
0
bool stop_cond(void)
{
	/* set SDA to 0 */
	CLRSDA();
	I2CDELAY(I2CSPEED/2);
	/* Clock stretching */
	while (READSCL() == 0);
	/* SCL is high, set SDA from 0 to 1 */
	if (READSDA() == 0)
		return false; //arbitration lost
	I2CDELAY(I2CSPEED/2);
	start = 0;
	return true;
}
예제 #5
0
bool read_bit(void)
{
	bool bit;
 
	//Let slave drive data signal.
	READSDA();
	I2CDELAY(I2CSPEED/2);
	/* Clock stretching */
	while (READSCL() == 0);
	/* SCL is high, now data is valid */
	bit = READSDA();
	I2CDELAY(I2CSPEED/2);
	CLRSCL();
	return bit;
}
예제 #6
0
파일: i2c.c 프로젝트: celetts/elua
/* Read a bit from I2C bus */
static int i2c_read_bit(void)
{
  int bit;

  /* Let the slave drive data */
  READSDA();
  I2CDELAY();
  /* Clock stretching */
  while (READSCL() == 0)
    ;  /* You should add timeout to this loop */
  /* SCL is high, now data is valid */
  bit = READSDA();
  I2CDELAY();
  CLRSCL();
  return bit;
}
예제 #7
0
파일: i2c.c 프로젝트: celetts/elua
void i2c_stop_cond(void)
{
  /* set SDA to 0 */
  CLRSDA();
  I2CDELAY();
  /* Clock stretching */
  while (READSCL() == 0)
    ;  /* You should add timeout to this loop */
  /* SCL is high. Respect I2C spec's minimum stop setup time of 4ms. */
  I2CDELAY();
  /* set SDA from 0 to 1 */
  if (READSDA() == 0)
    ARBITRATION_LOST();
  I2CDELAY();
  started = false;
}
예제 #8
0
bool write_bit(bool bit)
{
	if(bit) 
		READSDA();
	else 
		CLRSDA();
	I2CDELAY(I2CSPEED/2);
	/* Clock stretching */
	while (READSCL() == 0);
	/* SCL is high, now data is valid */
	/* check that nobody is driving SDA */
	if (bit && READSDA() == 0)
		return false; //arbitration lost
	I2CDELAY(I2CSPEED/2);
	CLRSCL();
	return true;
}
예제 #9
0
파일: i2c.c 프로젝트: celetts/elua
/* Write a bit to I2C bus */
static void i2c_write_bit(int bit)
{
  if (bit) 
    READSDA();
  else 
    CLRSDA();
  I2CDELAY();
  /* Clock stretching */
  while (READSCL() == 0)
    ;  /* 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 && READSDA() == 0) 
    ARBITRATION_LOST();
  I2CDELAY();
  CLRSCL();
}
예제 #10
0
파일: twi.c 프로젝트: rghunter/LoggoDAQ
static void start_cond(void) {
   if (start) {
      /* Let SDA rise */
      READSDA();
      I2CDELAY(I2CSPEED/2);
      /* Clock stretching */
      while (READSCL() == 0);
   }
   if (READSDA() == 0) {
      ARBITRATION_LOST();
   }
   /* SCL is high, we waited for slave to raise it, so pull SDA down */
   CLRSDA();
   I2CDELAY(I2CSPEED/2);
  // Now pull SCL down
   CLRSCL();
   start = 1;
}
예제 #11
0
파일: twi.c 프로젝트: rghunter/LoggoDAQ
static void write_bit(unsigned char bit) {
  //Put the bit on SDA by either letting it rise or pulling it down
   if (bit) {
      READSDA();
   } else {
      CLRSDA();
   }
   I2CDELAY(I2CSPEED/2);
   /* Clock stretching - Let SCL rise and wait for slave to let it rise */
   while (READSCL() == 0);
   /* SCL is high, now data is being read */
   /* If SDA is high, check that nobody else is driving SDA */
   if (bit) {
    if (READSDA() == 0) { //Oops, someone else pulled SDA down
        ARBITRATION_LOST();
      }
   }
   I2CDELAY(I2CSPEED/2);
   CLRSCL();
}
예제 #12
0
파일: i2c.c 프로젝트: celetts/elua
void i2c_start_cond(void)
{
  if (started) {
    // if started, do a restart cond
    // set SDA to 1
    READSDA();
    I2CDELAY();
    // Clock stretching
    while (READSCL() == 0)
      ;  // You can add a timeout to this loop to
         // recover from SCL being stuck low.
    // Repeated start setup time, minimum 4.7us
    I2CDELAY();
  }
  if (READSDA() == 0)
    ARBITRATION_LOST();
  // SCL is high, set SDA from 1 to 0
  CLRSDA();
  I2CDELAY();
  CLRSCL();
  started = true;
}