Do not send a stop condition while sending the slave address.
authorbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 3 Feb 2011 13:10:42 +0000 (13:10 +0000)
committerbatt <batt@38d2e660-2303-0410-9eaa-f027e97ec537>
Thu, 3 Feb 2011 13:10:42 +0000 (13:10 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4675 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/drv/i2c_bitbang.c

index 4d25731fd2c0e41199e87d2ff473848b7bf47ada..9456d362aabc5aa52f8c8f53e69ca1aa7689ed63 100644 (file)
@@ -293,7 +293,7 @@ static uint8_t i2c_bitbang_getc(struct I2c *i2c)
        return data;
 }
 
-static void i2c_bitbang_putc(struct I2c *i2c, uint8_t _data)
+INLINE void i2c_bitbang_putcStop(struct I2c *i2c, uint8_t _data, bool stop)
 {
        /* Add ACK bit */
        uint16_t data = (_data << 1) | 1;
@@ -342,10 +342,15 @@ static void i2c_bitbang_putc(struct I2c *i2c, uint8_t _data)
                i2c->errors |= I2C_NO_ACK;
 
        /* Generate stop condition (if requested) */
-       if (((i2c->xfer_size == 1) && (i2c->flags & I2C_STOP)) || i2c->errors)
+       if (stop || i2c->errors)
                i2c_bitbang_stop_1(i2c);
 }
 
+static void i2c_bitbang_putc(struct I2c *i2c, uint8_t data)
+{
+       i2c_bitbang_putcStop(i2c, data,
+               (i2c->xfer_size == 1) && (i2c->flags & I2C_STOP));
+}
 
 static void i2c_bitbang_start_2(struct I2c *i2c, uint16_t slave_addr)
 {
@@ -358,12 +363,12 @@ static void i2c_bitbang_start_2(struct I2c *i2c, uint16_t slave_addr)
         * Loop on the select write sequence: when the device is busy
         * writing previously sent data it will reply to the SLA_W
         * control byte with a NACK.  In this case, we must
-        * keep trying until the deveice responds with an ACK.
+        * keep trying until the device responds with an ACK.
         */
        ticks_t start = timer_clock();
        while (i2c_bitbang_start_1(i2c))
        {
-               i2c_bitbang_putc(i2c, slave_addr);
+               i2c_bitbang_putcStop(i2c, slave_addr, false);
 
                if (!(i2c->errors & I2C_NO_ACK))
                        return;