Exemplo n.º 1
0
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;
}
Exemplo n.º 2
0
Arquivo: i2c.c Projeto: 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;
}
Exemplo n.º 3
0
Arquivo: i2c.c Projeto: 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();
}
Exemplo n.º 4
0
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;
}
Exemplo n.º 5
0
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();
}
Exemplo n.º 6
0
Arquivo: i2c.c Projeto: 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;
}