summary |
shortlog |
log |
commit | commitdiff |
tree
raw |
patch |
inline | side by side (from parent 1:
e6aee36)
Move set stop bit before reading a byte, and wait transfer bit complete
when reading last byte.
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4944
38d2e660-2303-0410-9eaa-
f027e97ec537
+ * Set STOP condition bit, to send stop after next sent byte.
-INLINE void sendStop(I2c *i2c)
+INLINE void setStop(I2c *i2c)
- HWREG(i2c->hw->base + TWI_CR_OFF) |= TWI_CR_STOP;
+ HWREG(i2c->hw->base + TWI_CR_OFF) = TWI_CR_STOP;
{
LOG_ERR("i2c: write start timeout\n");
i2c->errors |= I2C_START_TIMEOUT;
{
LOG_ERR("i2c: write start timeout\n");
i2c->errors |= I2C_START_TIMEOUT;
waitXferComplete(i2c);
return;
}
waitXferComplete(i2c);
return;
}
if ((i2c->xfer_size == 1) && (I2C_TEST_STOP(i2c->flags) == I2C_STOP))
{
if ((i2c->xfer_size == 1) && (I2C_TEST_STOP(i2c->flags) == I2C_STOP))
{
waitXferComplete(i2c);
}
}
static uint8_t i2c_sam3_getc(I2c *i2c)
{
waitXferComplete(i2c);
}
}
static uint8_t i2c_sam3_getc(I2c *i2c)
{
+ uint8_t data;
+
+ if ((i2c->xfer_size == 1) && (I2C_TEST_STOP(i2c->flags) == I2C_STOP))
+ setStop(i2c);
+
if (i2c->hw->first_xtranf)
{
HWREG(i2c->hw->base + TWI_CR_OFF) = TWI_CR_START;
i2c->hw->first_xtranf = false;
}
if (i2c->hw->first_xtranf)
{
HWREG(i2c->hw->base + TWI_CR_OFF) = TWI_CR_START;
i2c->hw->first_xtranf = false;
}
- if ((i2c->xfer_size == 1) && (I2C_TEST_STOP(i2c->flags) == I2C_STOP))
- sendStop(i2c);
-
if (!waitRxRdy(i2c, CONFIG_I2C_START_TIMEOUT))
{
LOG_ERR("i2c: read start timeout\n");
if (!waitRxRdy(i2c, CONFIG_I2C_START_TIMEOUT))
{
LOG_ERR("i2c: read start timeout\n");
- return HWREG(i2c->hw->base + TWI_RHR_OFF);
+ data = HWREG(i2c->hw->base + TWI_RHR_OFF);
+
+ if ((i2c->xfer_size == 1) && (I2C_TEST_STOP(i2c->flags) == I2C_STOP))
+ waitXferComplete(i2c);
+
+ return data;
}
static void i2c_setClock(I2c *i2c, int clock)
}
static void i2c_setClock(I2c *i2c, int clock)