I2C. Testhal update.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3584 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
edfa9d2fae
commit
8196de6aef
|
@ -31,7 +31,7 @@ endif
|
||||||
|
|
||||||
# Enable this if you want to see the full log while compiling.
|
# Enable this if you want to see the full log while compiling.
|
||||||
ifeq ($(USE_VERBOSE_COMPILE),)
|
ifeq ($(USE_VERBOSE_COMPILE),)
|
||||||
USE_VERBOSE_COMPILE = yes
|
USE_VERBOSE_COMPILE = no
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#
|
#
|
||||||
|
|
|
@ -36,15 +36,15 @@ static uint8_t rx_data[2];
|
||||||
/* temperature value */
|
/* temperature value */
|
||||||
static int16_t temperature = 0;
|
static int16_t temperature = 0;
|
||||||
|
|
||||||
|
static i2cflags_t errors = 0;
|
||||||
|
|
||||||
#define addr 0b1001100
|
#define addr 0b1001100
|
||||||
|
|
||||||
/* This is main function. */
|
/* This is main function. */
|
||||||
void request_fake(void){
|
void request_fake(void){
|
||||||
i2cflags_t errors = 0;
|
|
||||||
|
|
||||||
i2cAcquireBus(&I2CD1);
|
i2cAcquireBus(&I2CD1);
|
||||||
errors = i2cMasterReceive(&I2CD1, addr, rx_data, 2);
|
i2cMasterReceive(&I2CD1, addr, rx_data, 2, &errors, TIME_INFINITE);
|
||||||
i2cReleaseBus(&I2CD1);
|
i2cReleaseBus(&I2CD1);
|
||||||
|
|
||||||
if (errors == I2CD_ACK_FAILURE){
|
if (errors == I2CD_ACK_FAILURE){
|
||||||
|
|
|
@ -40,6 +40,8 @@
|
||||||
static uint8_t accel_rx_data[ACCEL_RX_DEPTH];
|
static uint8_t accel_rx_data[ACCEL_RX_DEPTH];
|
||||||
static uint8_t accel_tx_data[ACCEL_TX_DEPTH];
|
static uint8_t accel_tx_data[ACCEL_TX_DEPTH];
|
||||||
|
|
||||||
|
static i2cflags_t errors = 0;
|
||||||
|
|
||||||
static int16_t acceleration_x = 0;
|
static int16_t acceleration_x = 0;
|
||||||
static int16_t acceleration_y = 0;
|
static int16_t acceleration_y = 0;
|
||||||
static int16_t acceleration_z = 0;
|
static int16_t acceleration_z = 0;
|
||||||
|
@ -57,7 +59,7 @@ int init_lis3(void){
|
||||||
|
|
||||||
/* sending */
|
/* sending */
|
||||||
i2cAcquireBus(&I2CD1);
|
i2cAcquireBus(&I2CD1);
|
||||||
i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 4, accel_rx_data, 0);
|
i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 4, accel_rx_data, 0, &errors, TIME_INFINITE);
|
||||||
i2cReleaseBus(&I2CD1);
|
i2cReleaseBus(&I2CD1);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -68,7 +70,7 @@ int init_lis3(void){
|
||||||
void request_acceleration_data(void){
|
void request_acceleration_data(void){
|
||||||
accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address
|
accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; // register address
|
||||||
i2cAcquireBus(&I2CD1);
|
i2cAcquireBus(&I2CD1);
|
||||||
i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 1, accel_rx_data, 6);
|
i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 1, accel_rx_data, 6, &errors, TIME_INFINITE);
|
||||||
i2cReleaseBus(&I2CD1);
|
i2cReleaseBus(&I2CD1);
|
||||||
|
|
||||||
acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8);
|
acceleration_x = accel_rx_data[0] + (accel_rx_data[1] << 8);
|
||||||
|
|
|
@ -38,6 +38,7 @@ static uint8_t tmp75_rx_data[TMP75_RX_DEPTH];
|
||||||
/* temperature value */
|
/* temperature value */
|
||||||
static int16_t temperature = 0;
|
static int16_t temperature = 0;
|
||||||
|
|
||||||
|
static i2cflags_t errors = 0;
|
||||||
|
|
||||||
#define tmp75_addr 0b1001000
|
#define tmp75_addr 0b1001000
|
||||||
|
|
||||||
|
@ -46,7 +47,7 @@ void request_temperature(void){
|
||||||
int16_t t_int = 0, t_frac = 0;
|
int16_t t_int = 0, t_frac = 0;
|
||||||
|
|
||||||
i2cAcquireBus(&I2CD1);
|
i2cAcquireBus(&I2CD1);
|
||||||
i2cMasterReceive(&I2CD1, tmp75_addr, tmp75_rx_data, 2);
|
i2cMasterReceive(&I2CD1, tmp75_addr, tmp75_rx_data, 2, &errors, TIME_INFINITE);
|
||||||
i2cReleaseBus(&I2CD1);
|
i2cReleaseBus(&I2CD1);
|
||||||
|
|
||||||
t_int = tmp75_rx_data[0] * 100;
|
t_int = tmp75_rx_data[0] * 100;
|
||||||
|
|
Loading…
Reference in New Issue