From 4b96f983dd6b8fbfc3876041712d7b7c6b959c20 Mon Sep 17 00:00:00 2001 From: barthess Date: Fri, 6 Jul 2012 13:13:48 +0000 Subject: I2C. Fixed testhal for F4x. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@4410 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- testhal/STM32F4xx/I2C/chconf.h | 1 - testhal/STM32F4xx/I2C/halconf.h | 2 +- testhal/STM32F4xx/I2C/main.c | 34 +++++++++++++++++++--------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/testhal/STM32F4xx/I2C/chconf.h b/testhal/STM32F4xx/I2C/chconf.h index d99c26773..1abb9626c 100644 --- a/testhal/STM32F4xx/I2C/chconf.h +++ b/testhal/STM32F4xx/I2C/chconf.h @@ -34,7 +34,6 @@ //#define CORTEX_VTOR_INIT 0x000E0000 #define CORTEX_VTOR_INIT 0x00000000 -#define CORTEX_USE_FPU TRUE /*===========================================================================*/ /* Kernel parameters. */ diff --git a/testhal/STM32F4xx/I2C/halconf.h b/testhal/STM32F4xx/I2C/halconf.h index e2ac49536..8aae4a995 100644 --- a/testhal/STM32F4xx/I2C/halconf.h +++ b/testhal/STM32F4xx/I2C/halconf.h @@ -80,7 +80,7 @@ * @brief Enables the I2C subsystem. */ #if !defined(HAL_USE_I2C) || defined(__DOXYGEN__) -#define HAL_USE_I2C FALSE +#define HAL_USE_I2C TRUE #endif /** diff --git a/testhal/STM32F4xx/I2C/main.c b/testhal/STM32F4xx/I2C/main.c index 310fe5888..e65b7e1c5 100644 --- a/testhal/STM32F4xx/I2C/main.c +++ b/testhal/STM32F4xx/I2C/main.c @@ -51,7 +51,7 @@ static int16_t acceleration_x, acceleration_y, acceleration_z; static void print(char *p) { while (*p) { - chIOPut(&SD2, *p++); + sdPut(&SD2, *p++); } } @@ -61,9 +61,9 @@ static void print(char *p) { static void println(char *p) { while (*p) { - chIOPut(&SD2, *p++); + sdPut(&SD2, *p++); } - chIOWriteTimeout(&SD2, (uint8_t *)"\r\n", 2, TIME_INFINITE); + sdWriteTimeout(&SD2, (uint8_t *)"\r\n", 2, TIME_INFINITE); } /** @@ -73,20 +73,20 @@ static void printn(int16_t n) { char buf[16], *p; if (n > 0) - chIOPut(&SD2, '+'); + sdPut(&SD2, '+'); else{ - chIOPut(&SD2, '-'); + sdPut(&SD2, '-'); n = abs(n); } if (!n) - chIOPut(&SD2, '0'); + sdPut(&SD2, '0'); else { p = buf; while (n) *p++ = (n % 10) + '0', n /= 10; while (p > buf) - chIOPut(&SD2, *--p); + sdPut(&SD2, *--p); } } @@ -102,6 +102,13 @@ int16_t complement2signed(uint8_t msb, uint8_t lsb){ return (int16_t)word; } +/* I2C interface #2 */ +static const I2CConfig i2cfg2 = { + OPMODE_I2C, + 400000, + FAST_DUTY_CYCLE_2, +}; + /* * Application entry point. */ @@ -119,6 +126,11 @@ int main(void) { halInit(); chSysInit(); + /* + * Starts I2C + */ + i2cStart(&I2CD2, &i2cfg2); + /* * Prepares the Serial driver 2 */ @@ -126,14 +138,6 @@ int main(void) { palSetPadMode(GPIOA, 2, PAL_MODE_ALTERNATE(7)); palSetPadMode(GPIOA, 3, PAL_MODE_ALTERNATE(7)); - /* I2C interface #2 */ - static const I2CConfig i2cfg2 = { - OPMODE_I2C, - 400000, - FAST_DUTY_CYCLE_16_9, - }; - i2cStart(&I2CD2, &i2cfg2); - /** * Prepares the accelerometer */ -- cgit v1.2.3