aboutsummaryrefslogtreecommitdiffstats
path: root/testhal
diff options
context:
space:
mode:
authorbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-07-03 18:02:55 +0000
committerbarthess <barthess@35acf78f-673a-0410-8e92-d51de3d6d3f4>2011-07-03 18:02:55 +0000
commitccb28114da9485c5e3f950fd31dfb67be1b8a173 (patch)
treea9645e52236f59fb69d4995ee9c121acaeb50808 /testhal
parentaf0e40079ded13b8842e8d129fa6ed2f37fdf678 (diff)
downloadChibiOS-ccb28114da9485c5e3f950fd31dfb67be1b8a173.tar.gz
ChibiOS-ccb28114da9485c5e3f950fd31dfb67be1b8a173.tar.bz2
ChibiOS-ccb28114da9485c5e3f950fd31dfb67be1b8a173.zip
I2C. Driver looks working, but sometimes hangs up. I don't know, my big project cause troubles in it, or driver cause troubles in my project.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/branches/i2c_dev@3116 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal')
-rw-r--r--testhal/STM32/I2C/halconf.h8
-rw-r--r--testhal/STM32/I2C/lis3.c22
-rw-r--r--testhal/STM32/I2C/main.c19
-rw-r--r--testhal/STM32/I2C/max1236.c19
-rw-r--r--testhal/STM32/I2C/tmp75.c8
5 files changed, 49 insertions, 27 deletions
diff --git a/testhal/STM32/I2C/halconf.h b/testhal/STM32/I2C/halconf.h
index b128d89cf..65d88f586 100644
--- a/testhal/STM32/I2C/halconf.h
+++ b/testhal/STM32/I2C/halconf.h
@@ -174,6 +174,14 @@
/*===========================================================================*/
/**
+ * @brief Enables synchronous APIs.
+ * @note Disabling this option saves both code and data space.
+ */
+#if !defined(I2C_USE_WAIT) || defined(__DOXYGEN__)
+#define I2C_USE_WAIT TRUE
+#endif
+
+/**
* @brief Enables the mutual exclusion APIs on the I2C bus.
*/
#if !defined(I2C_USE_MUTUAL_EXCLUSION) || defined(__DOXYGEN__)
diff --git a/testhal/STM32/I2C/lis3.c b/testhal/STM32/I2C/lis3.c
index c50d7e9a6..26a3292f5 100644
--- a/testhal/STM32/I2C/lis3.c
+++ b/testhal/STM32/I2C/lis3.c
@@ -54,9 +54,9 @@ static msg_t I2CAccelThread(void *arg) {
i2cscfg = (I2CSlaveConfig *)msg;
/* collect measured data */
- acceleration_x = i2cscfg->rxbuf[0] + (i2cscfg->rxbuf[1] << 8);
- acceleration_y = i2cscfg->rxbuf[2] + (i2cscfg->rxbuf[3] << 8);
- acceleration_z = i2cscfg->rxbuf[4] + (i2cscfg->rxbuf[5] << 8);
+ acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8);
+ acceleration_y = accel_rx_data[2] + (accel_rx_data[3] << 8);
+ acceleration_z = accel_rx_data[4] + (accel_rx_data[5] << 8);
}
return 0;
}
@@ -77,8 +77,6 @@ static void i2c_lis3_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
static const I2CSlaveConfig lis3 = {
i2c_lis3_cb,
i2c_lis3_error_cb,
- accel_rx_data,
- accel_tx_data,
};
@@ -106,13 +104,13 @@ int init_lis3(void){
#define RXBYTES 0 /* set to 0 because we need only transmit */
/* configure accelerometer */
- lis3.txbuf[0] = ACCEL_CTRL_REG1 | AUTO_INCREMENT_BIT; /* register address */
- lis3.txbuf[1] = 0b11100111;
- lis3.txbuf[2] = 0b01000001;
- lis3.txbuf[3] = 0b00000000;
+ accel_tx_data[0] = ACCEL_CTRL_REG1 | AUTO_INCREMENT_BIT; /* register address */
+ accel_tx_data[1] = 0b11100111;
+ accel_tx_data[2] = 0b01000001;
+ accel_tx_data[3] = 0b00000000;
/* sending */
- i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, TXBYTES, RXBYTES);
+ i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, TXBYTES, accel_rx_data, RXBYTES);
chThdSleepMilliseconds(1);
#undef RXBYTES
@@ -127,9 +125,9 @@ int init_lis3(void){
void request_acceleration_data(void){
#define RXBYTES 6
#define TXBYTES 1
- lis3.txbuf[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address
+ accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address
i2cAcquireBus(&I2CD1);
- i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, TXBYTES, RXBYTES);
+ i2cMasterTransmit(&I2CD1, &lis3, lis3_addr, accel_tx_data, TXBYTES, accel_rx_data, RXBYTES);
i2cReleaseBus(&I2CD1);
#undef RXBYTES
#undef TXBYTES
diff --git a/testhal/STM32/I2C/main.c b/testhal/STM32/I2C/main.c
index 793f73f49..ce8cb5522 100644
--- a/testhal/STM32/I2C/main.c
+++ b/testhal/STM32/I2C/main.c
@@ -29,6 +29,23 @@
+/*
+ * Red LEDs blinker thread, times are in milliseconds.
+ */
+static WORKING_AREA(BlinkWA, 128);
+static msg_t Blink(void *arg) {
+ (void)arg;
+ while (TRUE) {
+ palClearPad(IOPORT3, GPIOC_LED);
+ chThdSleepMilliseconds(500);
+ palSetPad(IOPORT3, GPIOC_LED);
+ chThdSleepMilliseconds(500);
+ }
+ return 0;
+}
+
+
+
/* Temperature polling thread */
static WORKING_AREA(PollTmp75ThreadWA, 128);
static msg_t PollTmp75Thread(void *arg) {
@@ -110,6 +127,8 @@ int main(void) {
PollAccelThread,
NULL);
+ /* Creates the blinker thread. */
+ chThdCreateStatic(BlinkWA, sizeof(BlinkWA), LOWPRIO, Blink, NULL);
/* main loop that do nothing */
while (TRUE) {
diff --git a/testhal/STM32/I2C/max1236.c b/testhal/STM32/I2C/max1236.c
index 13779b99a..3e3dbd0c1 100644
--- a/testhal/STM32/I2C/max1236.c
+++ b/testhal/STM32/I2C/max1236.c
@@ -29,11 +29,12 @@ static void i2c_max1236_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg)
/* This callback raise up when transfer finished */
static void i2c_max1236_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
(void)*i2cp;
+ (void)*i2cscfg;
/* get ADC data */
- ch1 = ((i2cscfg->rxbuf[0] & 0xF) << 8) + i2cscfg->rxbuf[1];
- ch2 = ((i2cscfg->rxbuf[2] & 0xF) << 8) + i2cscfg->rxbuf[3];
- ch3 = ((i2cscfg->rxbuf[4] & 0xF) << 8) + i2cscfg->rxbuf[5];
- ch4 = ((i2cscfg->rxbuf[6] & 0xF) << 8) + i2cscfg->rxbuf[7];
+ 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];
}
@@ -42,8 +43,6 @@ static void i2c_max1236_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
static const I2CSlaveConfig max1236 = {
i2c_max1236_cb,
i2c_max1236_error_cb,
- max1236_rx_data,
- max1236_tx_data,
};
#define max1236_addr 0b0110100
@@ -56,13 +55,13 @@ void init_max1236(void){
/* this data we must send via IC to setup ADC */
#define RXBYTES 0
#define TXBYTES 2
- max1236.txbuf[0] = 0b10000011; /* config register content. Consult datasheet */
- max1236.txbuf[1] = 0b00000111; /* config register content. Consult datasheet */
+ 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, TXBYTES, RXBYTES);
+ i2cMasterTransmit(&I2CD2, &max1236, max1236_addr, max1236_tx_data, TXBYTES, max1236_rx_data, RXBYTES);
while(I2CD2.id_state != I2C_READY){
chThdSleepMilliseconds(1);
}
@@ -78,7 +77,7 @@ void read_max1236(void){
#define RXBYTES 8
i2cAcquireBus(&I2CD2);
- i2cMasterReceive(&I2CD2, &max1236, max1236_addr, RXBYTES);
+ i2cMasterReceive(&I2CD2, &max1236, max1236_addr, max1236_rx_data, RXBYTES);
i2cReleaseBus(&I2CD2);
#undef RXBYTES
#undef TXBYTES
diff --git a/testhal/STM32/I2C/tmp75.c b/testhal/STM32/I2C/tmp75.c
index 0833e47c1..6276e7c8e 100644
--- a/testhal/STM32/I2C/tmp75.c
+++ b/testhal/STM32/I2C/tmp75.c
@@ -14,7 +14,6 @@
/* input buffer */
static i2cblock_t tmp75_rx_data[TMP75_RX_DEPTH];
-static i2cblock_t tmp75_tx_data[TMP75_TX_DEPTH];
/* temperature value */
static int16_t temperature = 0;
@@ -29,16 +28,15 @@ static void i2c_tmp75_error_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
/* This callback raise up when transfer finished */
static void i2c_tmp75_cb(I2CDriver *i2cp, const I2CSlaveConfig *i2cscfg){
(void)*i2cp;
+ (void)*i2cscfg;
/* store temperature value */
- temperature = (i2cscfg->rxbuf[0] << 8) + i2cscfg->rxbuf[1];
+ temperature = (tmp75_rx_data[0] << 8) + tmp75_rx_data[1];
}
/* Fill TMP75 config. */
static const I2CSlaveConfig tmp75 = {
i2c_tmp75_cb,
i2c_tmp75_error_cb,
- tmp75_rx_data,
- tmp75_tx_data,
};
#define tmp75_addr 0b1001000
@@ -49,7 +47,7 @@ void request_temperature(void){
#define RXBYTES 2 /* we need to read 2 bytes */
i2cAcquireBus(&I2CD2);
- i2cMasterReceive(&I2CD2, &tmp75, tmp75_addr, RXBYTES);
+ i2cMasterReceive(&I2CD2, &tmp75, tmp75_addr, tmp75_rx_data, RXBYTES);
i2cReleaseBus(&I2CD2);
}