Created
May 15, 2013 23:45
-
-
Save johnhowe/5588359 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdlib.h> | |
#include "ch.h" | |
#include "hal.h" | |
#include "mma845x.h" | |
#define ACCEL_RX_DEPTH 8 | |
#define ACCEL_TX_DEPTH 8 | |
#define ACCEL_CTRL_REG1 0x2A | |
static uint8_t rxbuf[ACCEL_RX_DEPTH]; | |
static uint8_t txbuf[ACCEL_TX_DEPTH]; | |
#define mma8451_addr 0b0011100 | |
#define I2CBUS I2CD1 // I2CD1 works, I2CD2 and I2CD3 don't | |
int main(void) | |
{ | |
halInit(); | |
chSysInit(); | |
systime_t timeout = MS2ST(100); | |
static const I2CConfig i2cfg = {OPMODE_I2C, 100000, FAST_DUTY_CYCLE_2}; | |
i2cStart(&I2CBUS, &i2cfg); | |
txbuf[0] = ACCEL_CTRL_REG1; | |
while (TRUE) { | |
i2cAcquireBus(&I2CBUS); | |
i2cMasterTransmitTimeout(&I2CBUS, mma8451_addr, txbuf, 1, rxbuf, 0, timeout); | |
i2cReleaseBus(&I2CBUS); | |
chThdSleepMilliseconds(10); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* I2C driver system settings. | |
*/ | |
#define STM32_I2C_USE_I2C1 TRUE | |
#define STM32_I2C_USE_I2C2 TRUE | |
#define STM32_I2C_USE_I2C3 TRUE | |
#define STM32_I2C_I2C1_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 0) | |
#define STM32_I2C_I2C1_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 6) | |
#define STM32_I2C_I2C2_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) | |
#define STM32_I2C_I2C2_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 7) | |
#define STM32_I2C_I2C3_RX_DMA_STREAM STM32_DMA_STREAM_ID(1, 2) | |
#define STM32_I2C_I2C3_TX_DMA_STREAM STM32_DMA_STREAM_ID(1, 4) | |
#define STM32_I2C_I2C1_IRQ_PRIORITY 5 | |
#define STM32_I2C_I2C2_IRQ_PRIORITY 5 | |
#define STM32_I2C_I2C3_IRQ_PRIORITY 5 | |
#define STM32_I2C_I2C1_DMA_PRIORITY 3 | |
#define STM32_I2C_I2C2_DMA_PRIORITY 3 | |
#define STM32_I2C_I2C3_DMA_PRIORITY 3 | |
#define STM32_I2C_I2C1_DMA_ERROR_HOOK() chSysHalt() | |
#define STM32_I2C_I2C2_DMA_ERROR_HOOK() chSysHalt() | |
#define STM32_I2C_I2C3_DMA_ERROR_HOOK() chSysHalt() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment