aboutsummaryrefslogtreecommitdiffstats
path: root/testhal/STM32F1xx
diff options
context:
space:
mode:
Diffstat (limited to 'testhal/STM32F1xx')
-rw-r--r--testhal/STM32F1xx/I2C/Makefile11
-rw-r--r--testhal/STM32F1xx/I2C/fake.c58
-rw-r--r--testhal/STM32F1xx/I2C/fake.h26
-rw-r--r--testhal/STM32F1xx/I2C/halconf.h15
-rw-r--r--testhal/STM32F1xx/I2C/i2c_pns.c53
-rw-r--r--testhal/STM32F1xx/I2C/i2c_pns.h20
-rw-r--r--testhal/STM32F1xx/I2C/lis3.c60
-rw-r--r--testhal/STM32F1xx/I2C/lis3.h20
-rw-r--r--testhal/STM32F1xx/I2C/main.c121
-rw-r--r--testhal/STM32F1xx/I2C/main.h19
-rw-r--r--testhal/STM32F1xx/I2C/max1236.c75
-rw-r--r--testhal/STM32F1xx/I2C/max1236.h14
-rw-r--r--testhal/STM32F1xx/I2C/mcuconf.h25
-rw-r--r--testhal/STM32F1xx/I2C/tmp75.c55
-rw-r--r--testhal/STM32F1xx/I2C/tmp75.h20
15 files changed, 304 insertions, 288 deletions
diff --git a/testhal/STM32F1xx/I2C/Makefile b/testhal/STM32F1xx/I2C/Makefile
index dc2441200..08494928a 100644
--- a/testhal/STM32F1xx/I2C/Makefile
+++ b/testhal/STM32F1xx/I2C/Makefile
@@ -31,7 +31,7 @@ endif
# Enable this if you want to see the full log while compiling.
ifeq ($(USE_VERBOSE_COMPILE),)
- USE_VERBOSE_COMPILE = no
+ USE_VERBOSE_COMPILE = yes
endif
#
@@ -63,7 +63,7 @@ LDSCRIPT= $(PORTLD)/STM32F103xB.ld
# Imported source files
CHIBIOS = ../../..
-include $(CHIBIOS)/boards/OLIMEX_STM32_P103/board.mk
+include $(CHIBIOS)/boards/OLIMEX_STM32_103STK/board.mk
include $(CHIBIOS)/os/hal/platforms/STM32F1xx/platform.mk
include $(CHIBIOS)/os/hal/hal.mk
include $(CHIBIOS)/os/ports/GCC/ARMCMx/STM32F1xx/port.mk
@@ -82,9 +82,9 @@ CSRC = $(PORTSRC) \
$(CHIBIOS)/os/various/syscalls.c \
main.c \
i2c_pns.c \
- tmp75.c\
- max1236.c\
- lis3.c\
+ lis3.c \
+ tmp75.c \
+ fake.c
@@ -127,7 +127,6 @@ INCDIR = $(PORTINC) $(KERNINC) $(TESTINC) \
# Compiler settings
#
-# -lm �������� ������ �����, ������ ��� ������ ������
MCU = cortex-m3
#TRGT = arm-elf-
diff --git a/testhal/STM32F1xx/I2C/fake.c b/testhal/STM32F1xx/I2C/fake.c
new file mode 100644
index 000000000..53779893e
--- /dev/null
+++ b/testhal/STM32F1xx/I2C/fake.c
@@ -0,0 +1,58 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+/**
+ * Not responding slave test
+ */
+
+#include <stdlib.h>
+
+#include "ch.h"
+#include "hal.h"
+
+#include "fake.h"
+
+
+/* input buffer */
+static uint8_t rx_data[2];
+
+/* temperature value */
+static int16_t temperature = 0;
+
+
+#define addr 0b1001100
+
+/* This is main function. */
+void request_fake(void){
+ i2cflags_t errors = 0;
+
+ i2cAcquireBus(&I2CD1);
+ errors = i2cMasterReceive(&I2CD1, addr, rx_data, 2);
+ i2cReleaseBus(&I2CD1);
+
+ if (errors == I2CD_ACK_FAILURE){
+ __NOP();
+ }
+ else{
+ temperature = (rx_data[0] << 8) + rx_data[1];
+ }
+}
+
+
diff --git a/testhal/STM32F1xx/I2C/fake.h b/testhal/STM32F1xx/I2C/fake.h
new file mode 100644
index 000000000..04f4206bf
--- /dev/null
+++ b/testhal/STM32F1xx/I2C/fake.h
@@ -0,0 +1,26 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#ifndef FAKE_H_
+#define FAKE_H_
+
+void request_fake(void);
+
+#endif /* FAKE_H_ */
diff --git a/testhal/STM32F1xx/I2C/halconf.h b/testhal/STM32F1xx/I2C/halconf.h
index 31d581932..54a69c2f7 100644
--- a/testhal/STM32F1xx/I2C/halconf.h
+++ b/testhal/STM32F1xx/I2C/halconf.h
@@ -44,7 +44,7 @@
* @brief Enables the ADC subsystem.
*/
#if !defined(HAL_USE_ADC) || defined(__DOXYGEN__)
-#define HAL_USE_ADC TRUE
+#define HAL_USE_ADC FALSE
#endif
/**
@@ -100,7 +100,7 @@
* @brief Enables the PWM subsystem.
*/
#if !defined(HAL_USE_PWM) || defined(__DOXYGEN__)
-#define HAL_USE_PWM TRUE
+#define HAL_USE_PWM FALSE
#endif
/**
@@ -121,7 +121,7 @@
* @brief Enables the SERIAL subsystem.
*/
#if !defined(HAL_USE_SERIAL) || defined(__DOXYGEN__)
-#define HAL_USE_SERIAL TRUE
+#define HAL_USE_SERIAL FALSE
#endif
/**
@@ -192,7 +192,7 @@
* @note Disabling this option saves both code and data space.
*/
#if !defined(I2C_USE_WAIT) || defined(__DOXYGEN__)
-#define I2C_USE_WAIT FALSE
+#define I2C_USE_WAIT TRUE
#endif
/**
@@ -202,13 +202,6 @@
#define I2C_USE_MUTUAL_EXCLUSION TRUE
#endif
-/**
- * @brief Switch to asynchronouse driver with callbacks.
- */
-#if !defined(I2C_SUPPORTS_CALLBACKS) || defined(__DOXYGEN__)
-#define I2C_SUPPORTS_CALLBACKS TRUE
-#endif
-
/*===========================================================================*/
/* MAC driver related settings. */
/*===========================================================================*/
diff --git a/testhal/STM32F1xx/I2C/i2c_pns.c b/testhal/STM32F1xx/I2C/i2c_pns.c
index 44f4a8a33..1c73482e3 100644
--- a/testhal/STM32F1xx/I2C/i2c_pns.c
+++ b/testhal/STM32F1xx/I2C/i2c_pns.c
@@ -1,32 +1,35 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include "ch.h"
#include "hal.h"
#include "i2c_pns.h"
-
#include "lis3.h"
-#include "tmp75.h"
-#include "max1236.h"
+
/* I2C1 */
static const I2CConfig i2cfg1 = {
OPMODE_I2C,
- 100000,
- STD_DUTY_CYCLE,
- 0,
- 0,
- 0,
- 0,
-};
-
-/* I2C2 */
-static const I2CConfig i2cfg2 = {
- OPMODE_I2C,
- 100000,
- STD_DUTY_CYCLE,
- 0,
- 0,
- 0,
- 0,
+ 400000,
+ FAST_DUTY_CYCLE_16_9,
};
@@ -35,22 +38,14 @@ void I2CInit_pns(void){
i2cInit();
i2cStart(&I2CD1, &i2cfg1);
- i2cStart(&I2CD2, &i2cfg2);
/* tune ports for I2C1*/
palSetPadMode(IOPORT2, 6, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
palSetPadMode(IOPORT2, 7, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
- /* tune ports for I2C2*/
- palSetPadMode(IOPORT2, 10, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
- palSetPadMode(IOPORT2, 11, PAL_MODE_STM32_ALTERNATE_OPENDRAIN);
-
/* startups. Pauses added just to be safe */
- chThdSleepMilliseconds(1000);
- init_max1236();
- chThdSleepMilliseconds(1000);
+ chThdSleepMilliseconds(100);
init_lis3();
- chThdSleepMilliseconds(1000);
}
diff --git a/testhal/STM32F1xx/I2C/i2c_pns.h b/testhal/STM32F1xx/I2C/i2c_pns.h
index 4dfdf320e..dae359ecf 100644
--- a/testhal/STM32F1xx/I2C/i2c_pns.h
+++ b/testhal/STM32F1xx/I2C/i2c_pns.h
@@ -1,3 +1,23 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#ifndef I2C_PNS_H_
#define I2C_PNS_H_
diff --git a/testhal/STM32F1xx/I2C/lis3.c b/testhal/STM32F1xx/I2C/lis3.c
index 401f56199..d3369ac82 100644
--- a/testhal/STM32F1xx/I2C/lis3.c
+++ b/testhal/STM32F1xx/I2C/lis3.c
@@ -1,7 +1,26 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
/**
- * This is most complex and difficult device.
- * It realize "read through write" paradigm. This is not standard, but
- * most of I2C devices use this paradigm.
+ * This is device realize "read through write" paradigm. This is not
+ * standard, but most of I2C devices use this paradigm.
* You must write to device reading address, send restart to bus,
* and then begin reading process.
*/
@@ -18,34 +37,13 @@
/* buffers */
-static i2cblock_t accel_rx_data[ACCEL_RX_DEPTH];
-static i2cblock_t accel_tx_data[ACCEL_TX_DEPTH];
+static uint8_t accel_rx_data[ACCEL_RX_DEPTH];
+static uint8_t accel_tx_data[ACCEL_TX_DEPTH];
static int16_t acceleration_x = 0;
static int16_t acceleration_y = 0;
static int16_t acceleration_z = 0;
-/* Error trap */
-static void i2c_lis3_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
- (void)i2cscfg;
- int status = 0;
- status = i2cp->id_i2c->SR1;
- while(TRUE);
-}
-
-/* This callback raise up when transfer finished */
-static void i2c_lis3_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
- (void)i2cp;
- (void)i2cscfg;
-}
-
-
-/* Accelerometer lis3lv02dq config */
-static const I2CSlaveConfig lis3 = {
- i2c_lis3_cb,
- i2c_lis3_error_cb,
-};
-
/**
* Init function. Here we will also start personal serving thread.
@@ -58,7 +56,9 @@ int init_lis3(void){
accel_tx_data[3] = 0b00000000;
/* sending */
- i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 4, accel_rx_data, 0);
+ i2cAcquireBus(&I2CD1);
+ i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 4, accel_rx_data, 0);
+ i2cReleaseBus(&I2CD1);
return 0;
}
@@ -67,9 +67,9 @@ int init_lis3(void){
*/
void request_acceleration_data(void){
accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address
- //i2cAcquireBus(&I2CD1);
- i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, 1, accel_rx_data, 6);
- //i2cReleaseBus(&I2CD1);
+ i2cAcquireBus(&I2CD1);
+ i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 1, accel_rx_data, 6);
+ i2cReleaseBus(&I2CD1);
acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8);
acceleration_y = accel_rx_data[2] + (accel_rx_data[3] << 8);
diff --git a/testhal/STM32F1xx/I2C/lis3.h b/testhal/STM32F1xx/I2C/lis3.h
index e50359bde..0c2eefa5d 100644
--- a/testhal/STM32F1xx/I2C/lis3.h
+++ b/testhal/STM32F1xx/I2C/lis3.h
@@ -1,3 +1,23 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#include <stdlib.h>
#include "ch.h"
diff --git a/testhal/STM32F1xx/I2C/main.c b/testhal/STM32F1xx/I2C/main.c
index b828953c5..60cb1f3ae 100644
--- a/testhal/STM32F1xx/I2C/main.c
+++ b/testhal/STM32F1xx/I2C/main.c
@@ -1,21 +1,22 @@
-/**
- * Lets imagine that we have board with LIS3LV02DL accelerometer on channel #1
- * and MAX1236 ADC, TMP75 thermometer on channel #2.
- *
- * NOTE: I assume, that you have datasheets on all this stuff.
- *
- * NOTE: Also, I assume, that you know how to I2C works.
- *
- * In order from simplicity to complexity:
- * TMP75
- * MAX1236
- * LIS3LV02DL
- *
- * Project splitted to separate source files for each device.
- *
- * Data from sensors we will be read from different thread sleeping different
- * amount of time.
- */
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
#include <stdlib.h>
@@ -23,10 +24,9 @@
#include "hal.h"
#include "i2c_pns.h"
-#include "tmp75.h"
-#include "max1236.h"
#include "lis3.h"
-
+#include "tmp75.h"
+#include "fake.h"
/*
@@ -44,55 +44,51 @@ static msg_t Blink(void *arg) {
return 0;
}
-
-
-/* Temperature polling thread */
-static WORKING_AREA(PollTmp75ThreadWA, 128);
-static msg_t PollTmp75Thread(void *arg) {
+/*
+ * Accelerometer thread
+ */
+static WORKING_AREA(PollAccelThreadWA, 128);
+static msg_t PollAccelThread(void *arg) {
+ chRegSetThreadName("PollAccel");
(void)arg;
- systime_t time = chTimeNow();
-
while (TRUE) {
- time += MS2ST(1001);
- /* Call reading function */
- request_temperature();
- chThdSleepUntil(time);
+// chThdSleepMilliseconds(rand() & 31);
+ chThdSleepMilliseconds(32);
+ request_acceleration_data();
}
return 0;
}
-/* MAX1236 polling thread */
-static WORKING_AREA(PollMax1236ThreadWA, 128);
-static msg_t PollMax1236Thread(void *arg) {
- (void)arg;
- systime_t time = chTimeNow();
+/* Temperature polling thread */
+static WORKING_AREA(PollTmp75ThreadWA, 128);
+static msg_t PollTmp75Thread(void *arg) {
+ chRegSetThreadName("PollTmp75");
+ (void)arg;
while (TRUE) {
- time += MS2ST(200);
+// chThdSleepMilliseconds(rand() & 31);
+ chThdSleepMilliseconds(15);
/* Call reading function */
- read_max1236();
- chThdSleepUntil(time);
+ request_temperature();
}
return 0;
}
-static WORKING_AREA(PollAccelThreadWA, 128);
-static msg_t PollAccelThread(void *arg) {
+/* Temperature polling thread */
+static WORKING_AREA(PollFakeThreadWA, 128);
+static msg_t PollFakeThread(void *arg) {
+ chRegSetThreadName("PollFake");
(void)arg;
- systime_t time = chTimeNow();
-
while (TRUE) {
- time += MS2ST(20);
- request_acceleration_data();
- chThdSleepUntil(time);
+ chThdSleepMilliseconds(16);
+ /* Call reading function */
+ request_fake();
}
return 0;
}
-
-
/*
* Entry point, note, the main() function is already a thread in the system
* on entry.
@@ -102,8 +98,16 @@ int main(void) {
halInit();
chSysInit();
+ chThdSleepMilliseconds(200);
I2CInit_pns();
+ /* Create accelerometer thread */
+ chThdCreateStatic(PollAccelThreadWA,
+ sizeof(PollAccelThreadWA),
+ NORMALPRIO,
+ PollAccelThread,
+ NULL);
+
/* Create temperature thread */
chThdCreateStatic(PollTmp75ThreadWA,
sizeof(PollTmp75ThreadWA),
@@ -111,24 +115,15 @@ int main(void) {
PollTmp75Thread,
NULL);
-
- /* Create max1236 thread */
- chThdCreateStatic(PollMax1236ThreadWA,
- sizeof(PollMax1236ThreadWA),
+ /* Create not responding thread */
+ chThdCreateStatic(PollFakeThreadWA,
+ sizeof(PollFakeThreadWA),
NORMALPRIO,
- PollMax1236Thread,
- NULL);
-
-
- /* Create accelerometer thread */
- chThdCreateStatic(PollAccelThreadWA,
- sizeof(PollAccelThreadWA),
- HIGHPRIO,
- PollAccelThread,
+ PollFakeThread,
NULL);
/* Creates the blinker thread. */
- chThdCreateStatic(BlinkWA, sizeof(BlinkWA), LOWPRIO, Blink, NULL);
+ chThdCreateStatic(BlinkWA, sizeof(BlinkWA), HIGHPRIO, Blink, NULL);
/* main loop that do nothing */
while (TRUE) {
diff --git a/testhal/STM32F1xx/I2C/main.h b/testhal/STM32F1xx/I2C/main.h
deleted file mode 100644
index 1435a05e5..000000000
--- a/testhal/STM32F1xx/I2C/main.h
+++ /dev/null
@@ -1,19 +0,0 @@
-/*
- * main.h
- *
- * Created on: 25.03.2011
- * Author: barthess
- */
-
-#ifndef MAIN_H_
-#define MAIN_H_
-
-
-// ãëîáàëüíûå ôëàãè
-#define GET_FILTERED_RAW_GYRO TRUE
-#define GET_FILTERED_RAW_ACCEL TRUE
-
-
-
-
-#endif /* MAIN_H_ */
diff --git a/testhal/STM32F1xx/I2C/max1236.c b/testhal/STM32F1xx/I2C/max1236.c
deleted file mode 100644
index 09e2c8b35..000000000
--- a/testhal/STM32F1xx/I2C/max1236.c
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * Maxim ADC has not so suitable default settings after startup.
- * So we will create init function to tune this ADC.
- */
-
-#include <stdlib.h>
-
-#include "ch.h"
-#include "hal.h"
-
-#include "max1236.h"
-
-
-#define max1236_addr 0b0110100
-
-
-/* Data buffers */
-static i2cblock_t max1236_rx_data[MAX1236_RX_DEPTH];
-static i2cblock_t max1236_tx_data[MAX1236_TX_DEPTH];
-/* ADC results */
-static uint16_t ch1 = 0, ch2 = 0, ch3 = 0, ch4 = 0;
-
-
-/* Error trap */
-static void i2c_max1236_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
- (void)i2cscfg;
- int status = 0;
- status = i2cp->id_i2c->SR1;
- while(TRUE);
-}
-
-
-/* This callback raise up when transfer finished */
-static void i2c_max1236_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
- (void)*i2cp;
- (void)*i2cscfg;
- /* get ADC data */
-}
-
-
-/* ADC maxim MAX1236 config */
-
-static const I2CSlaveConfig max1236 = {
- i2c_max1236_cb,
- i2c_max1236_error_cb,
-};
-
-
-/**
- * Initilization routine. See datasheet on page 13 to understand
- * how to initialize ADC.
- */
-void init_max1236(void){
- /* this data we must send via IC to setup ADC */
- max1236_tx_data[0] = 0b10000011; /* config register content. Consult datasheet */
- max1236_tx_data[1] = 0b00000111; /* config register content. Consult datasheet */
-
- /* transmit out 2 bytes */
- i2cAcquireBus(&I2CD2);
- i2cMasterTransmit(&I2CD2, &max1236, max1236_addr, max1236_tx_data, 2, max1236_rx_data, 0);
- i2cReleaseBus(&I2CD2);
-}
-
-
-/* Now simply read 8 bytes to get all 4 ADC channels */
-void read_max1236(void){
- i2cAcquireBus(&I2CD2);
- i2cMasterReceive(&I2CD2, &max1236, max1236_addr, max1236_rx_data, 8);
- i2cReleaseBus(&I2CD2);
-
- ch1 = ((max1236_rx_data[0] & 0xF) << 8) + max1236_rx_data[1];
- ch2 = ((max1236_rx_data[2] & 0xF) << 8) + max1236_rx_data[3];
- ch3 = ((max1236_rx_data[4] & 0xF) << 8) + max1236_rx_data[5];
- ch4 = ((max1236_rx_data[6] & 0xF) << 8) + max1236_rx_data[7];
-}
diff --git a/testhal/STM32F1xx/I2C/max1236.h b/testhal/STM32F1xx/I2C/max1236.h
deleted file mode 100644
index aff466cf4..000000000
--- a/testhal/STM32F1xx/I2C/max1236.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#include "ch.h"
-
-#ifndef MAX1236_H_
-#define MAX1236_H_
-
-
-#define MAX1236_RX_DEPTH 8
-#define MAX1236_TX_DEPTH 2
-
-
-void init_max1236(void);
-void read_max1236(void);
-
-#endif /* MAX1236_H_ */
diff --git a/testhal/STM32F1xx/I2C/mcuconf.h b/testhal/STM32F1xx/I2C/mcuconf.h
index 6afc97f28..dc4d3960c 100644
--- a/testhal/STM32F1xx/I2C/mcuconf.h
+++ b/testhal/STM32F1xx/I2C/mcuconf.h
@@ -47,7 +47,7 @@
/*
* ADC driver system settings.
*/
-#define STM32_ADC_USE_ADC1 TRUE
+#define STM32_ADC_USE_ADC1 FALSE
#define STM32_ADC_ADC1_DMA_PRIORITY 3
#define STM32_ADC_ADC1_IRQ_PRIORITY 5
#define STM32_ADC_ADC1_DMA_ERROR_HOOK() chSysHalt()
@@ -122,8 +122,8 @@
/*
* SERIAL driver system settings.
*/
-#define STM32_SERIAL_USE_USART1 TRUE
-#define STM32_SERIAL_USE_USART2 TRUE
+#define STM32_SERIAL_USE_USART1 FALSE
+#define STM32_SERIAL_USE_USART2 FALSE
#define STM32_SERIAL_USE_USART3 FALSE
#define STM32_SERIAL_USE_UART4 FALSE
#define STM32_SERIAL_USE_UART5 FALSE
@@ -138,8 +138,8 @@
/*
* SPI driver system settings.
*/
-#define STM32_SPI_USE_SPI1 TRUE
-#define STM32_SPI_USE_SPI2 TRUE
+#define STM32_SPI_USE_SPI1 FALSE
+#define STM32_SPI_USE_SPI2 FALSE
#define STM32_SPI_USE_SPI3 FALSE
#define STM32_SPI_SPI1_DMA_PRIORITY 1
#define STM32_SPI_SPI2_DMA_PRIORITY 1
@@ -167,25 +167,18 @@
* I2C driver system settings.
*/
#define STM32_I2C_USE_I2C1 TRUE
-#define STM32_I2C_USE_I2C2 TRUE
+#define STM32_I2C_USE_I2C2 FALSE
#define STM32_I2C_I2C1_IRQ_PRIORITY 10
#define STM32_I2C_I2C2_IRQ_PRIORITY 10
-#define STM32_I2C_I2C1_DMA_PRIORITY 4
-#define STM32_I2C_I2C2_DMA_PRIORITY 4
+#define STM32_I2C_I2C1_DMA_PRIORITY 1
+#define STM32_I2C_I2C2_DMA_PRIORITY 1
#define STM32_I2C_I2C1_DMA_ERROR_HOOK() chSysHalt()
#define STM32_I2C_I2C2_DMA_ERROR_HOOK() chSysHalt()
-/* I2C1 */
-#define STM32_I2C_I2C1_USE_GPT_TIM GPTD1
-#define STM32_I2C_I2C1_USE_POLLING_WAIT TRUE
-/* I2C2 */
-#define STM32_I2C_I2C2_USE_GPT_TIM GPTD2
-#define STM32_I2C_I2C2_USE_POLLING_WAIT TRUE
-
/*
* USB driver system settings.
*/
-#define STM32_USB_USE_USB1 TRUE
+#define STM32_USB_USE_USB1 FALSE
#define STM32_USB_LOW_POWER_ON_SUSPEND FALSE
#define STM32_USB_USB1_HP_IRQ_PRIORITY 6
#define STM32_USB_USB1_LP_IRQ_PRIORITY 14
diff --git a/testhal/STM32F1xx/I2C/tmp75.c b/testhal/STM32F1xx/I2C/tmp75.c
index 72e634527..630a76dac 100644
--- a/testhal/STM32F1xx/I2C/tmp75.c
+++ b/testhal/STM32F1xx/I2C/tmp75.c
@@ -1,3 +1,23 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
/**
* TMP75 is most simple I2C device in our case. It is already useful with
* default settings after powerup.
@@ -13,40 +33,25 @@
/* input buffer */
-static i2cblock_t tmp75_rx_data[TMP75_RX_DEPTH];
+static uint8_t tmp75_rx_data[TMP75_RX_DEPTH];
/* temperature value */
static int16_t temperature = 0;
-/* Simple error trap */
-static void i2c_tmp75_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
- (void)i2cscfg;
- int status = 0;
- status = i2cp->id_i2c->SR1;
- while(TRUE);
-}
-
-/* This callback raise up when transfer finished */
-static void i2c_tmp75_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
- (void)*i2cp;
- (void)*i2cscfg;
- /* store temperature value */
-}
-
-/* Fill TMP75 config. */
-static const I2CSlaveConfig tmp75 = {
- i2c_tmp75_cb,
- i2c_tmp75_error_cb,
-};
#define tmp75_addr 0b1001000
/* This is main function. */
void request_temperature(void){
- i2cAcquireBus(&I2CD2);
- i2cMasterReceive(&I2CD2, &tmp75, tmp75_addr, tmp75_rx_data, 2);
- i2cReleaseBus(&I2CD2);
- temperature = (tmp75_rx_data[0] << 8) + tmp75_rx_data[1];
+ int16_t t_int = 0, t_frac = 0;
+
+ i2cAcquireBus(&I2CD1);
+ i2cMasterReceive(&I2CD1, tmp75_addr, tmp75_rx_data, 2);
+ i2cReleaseBus(&I2CD1);
+
+ t_int = tmp75_rx_data[0] * 100;
+ t_frac = (tmp75_rx_data[1] * 100) >> 8;
+ temperature = t_int + t_frac;
}
diff --git a/testhal/STM32F1xx/I2C/tmp75.h b/testhal/STM32F1xx/I2C/tmp75.h
index ab4b5fa9b..13648b154 100644
--- a/testhal/STM32F1xx/I2C/tmp75.h
+++ b/testhal/STM32F1xx/I2C/tmp75.h
@@ -1,3 +1,23 @@
+/*
+ ChibiOS/RT - Copyright (C) 2006,2007,2008,2009,2010,
+ 2011 Giovanni Di Sirio.
+
+ This file is part of ChibiOS/RT.
+
+ ChibiOS/RT is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ ChibiOS/RT is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
#ifndef TMP75_H_
#define TMP75_H_