aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32F37x/I2C/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'testhal/STM32F37x/I2C/main.c')
-rw-r--r--testhal/STM32F37x/I2C/main.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/testhal/STM32F37x/I2C/main.c b/testhal/STM32F37x/I2C/main.c
index 52a4e889b..96295089b 100644
--- a/testhal/STM32F37x/I2C/main.c
+++ b/testhal/STM32F37x/I2C/main.c
@@ -23,6 +23,7 @@
* The timings are critical, please always refer to the STM32 Reference
* Manual before attempting changes.
*/
+#if 0
static const I2CConfig i2cconfig = {
STM32_TIMINGR_PRESC(8U) | /* 72MHz/9 = 8MHz I2CCLK. */
STM32_TIMINGR_SCLDEL(3U) | STM32_TIMINGR_SDADEL(3U) |
@@ -30,6 +31,14 @@ static const I2CConfig i2cconfig = {
0,
0
};
+#endif
+static const I2CConfig i2cconfig = {
+ STM32_TIMINGR_PRESC(15U) |
+ STM32_TIMINGR_SCLDEL(4U) | STM32_TIMINGR_SDADEL(2U) |
+ STM32_TIMINGR_SCLH(15U) | STM32_TIMINGR_SCLL(21U),
+ 0,
+ 0
+};
/*
* This is a periodic thread that does absolutely nothing except flashing
@@ -78,6 +87,23 @@ int main(void) {
* Normal main() thread activity, in this demo it does nothing.
*/
while (TRUE) {
+ unsigned i;
+ msg_t msg;
+ 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);
+ 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)
+ chSysHalt();
+ }
chThdSleepMilliseconds(500);
}
return 0;