mirror of https://github.com/rusefi/ChibiOS.git
I2Cv2 driver tested on STM32F37x.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5526 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
0ebb7959d5
commit
356fb1a2a0
|
@ -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. */
|
||||
/** @} */
|
||||
|
||||
/*===========================================================================*/
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue