From 356fb1a2a03fa00622580077007622d5c5e62555 Mon Sep 17 00:00:00 2001 From: gdisirio Date: Mon, 1 Apr 2013 16:16:18 +0000 Subject: [PATCH] I2Cv2 driver tested on STM32F37x. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5526 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/include/i2c.h | 8 ++------ os/hal/platforms/STM32/I2Cv2/i2c_lld.c | 16 +++++++++++++--- testhal/STM32F37x/I2C/main.c | 3 +-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/os/hal/include/i2c.h b/os/hal/include/i2c.h index c19ea64cb..b3a9ffdff 100644 --- a/os/hal/include/i2c.h +++ b/os/hal/include/i2c.h @@ -45,14 +45,10 @@ */ #define I2CD_NO_ERROR 0x00 /**< @brief No error. */ #define I2CD_BUS_ERROR 0x01 /**< @brief Bus Error. */ -#define I2CD_ARBITRATION_LOST 0x02 /**< @brief Arbitration Lost - (master mode). */ +#define I2CD_ARBITRATION_LOST 0x02 /**< @brief Arbitration Lost. */ #define I2CD_ACK_FAILURE 0x04 /**< @brief Acknowledge Failure. */ #define I2CD_OVERRUN 0x08 /**< @brief Overrun/Underrun. */ -#define I2CD_PEC_ERROR 0x10 /**< @brief PEC Error in - reception. */ -#define I2CD_TIMEOUT 0x20 /**< @brief Hardware timeout. */ -#define I2CD_SMB_ALERT 0x40 /**< @brief SMBus Alert. */ +#define I2CD_TIMEOUT 0x10 /**< @brief Hardware timeout. */ /** @} */ /*===========================================================================*/ diff --git a/os/hal/platforms/STM32/I2Cv2/i2c_lld.c b/os/hal/platforms/STM32/I2Cv2/i2c_lld.c index 6668c212f..3b7b52e3b 100644 --- a/os/hal/platforms/STM32/I2Cv2/i2c_lld.c +++ b/os/hal/platforms/STM32/I2Cv2/i2c_lld.c @@ -177,10 +177,20 @@ static void i2c_lld_serve_interrupt(I2CDriver *i2cp, uint32_t isr) { } else { dp->CR2 |= I2C_CR2_STOP; - wakeup_isr(i2cp, RDY_OK); } } + else if (isr & I2C_ISR_STOPF) { + /* Stops the associated DMA streams.*/ + dmaStreamDisable(i2cp->dmatx); + dmaStreamDisable(i2cp->dmarx); + + wakeup_isr(i2cp, RDY_OK); + } else if (isr & I2C_ISR_NACKF) { + /* Stops the associated DMA streams.*/ + dmaStreamDisable(i2cp->dmatx); + dmaStreamDisable(i2cp->dmarx); + i2cp->errors |= I2CD_ACK_FAILURE; wakeup_isr(i2cp, RDY_RESET); } @@ -503,8 +513,8 @@ void i2c_lld_start(I2CDriver *i2cp) { dmaStreamSetPeripheral(i2cp->dmatx, &dp->TXDR); /* Reset i2c peripheral.*/ - dp->CR1 = i2cp->config->cr1 | I2C_CR1_ERRIE | I2C_CR1_NACKIE | - I2C_CR1_TCIE | I2C_CR1_TXDMAEN | I2C_CR1_RXDMAEN; + dp->CR1 = i2cp->config->cr1 | I2C_CR1_ERRIE | I2C_CR1_STOPIE | + I2C_CR1_NACKIE | I2C_CR1_TCIE | I2C_CR1_TXDMAEN | I2C_CR1_RXDMAEN; /* Set slave address field (master mode) */ dp->CR2 = (i2cp->config->cr2 & ~I2C_CR2_SADD); diff --git a/testhal/STM32F37x/I2C/main.c b/testhal/STM32F37x/I2C/main.c index 96295089b..244de9b49 100644 --- a/testhal/STM32F37x/I2C/main.c +++ b/testhal/STM32F37x/I2C/main.c @@ -92,13 +92,12 @@ int main(void) { static const uint8_t cmd[] = {0, 0}; uint8_t data[16]; - chThdSleepMilliseconds(10); msg = i2cMasterTransmitTimeout(&I2CD2, 0x52, cmd, sizeof(cmd), data, sizeof(data), TIME_INFINITE); + msg = msg; if (msg != RDY_OK) chSysHalt(); for (i = 0; i < 256; i++) { - chThdSleepMilliseconds(10); msg = i2cMasterReceiveTimeout(&I2CD2, 0x52, data, sizeof(data), TIME_INFINITE); if (msg != RDY_OK)