I2C. Fully functional testhal for STM32F1x.

git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@3696 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
barthess 2011-12-31 10:34:04 +00:00
parent c397738010
commit 409fb83520
5 changed files with 29 additions and 10 deletions

View File

@ -84,7 +84,7 @@ CSRC = $(PORTSRC) \
i2c_pns.c \
tmp75.c \
fake.c \
#lis3.c
lis3.c

View File

@ -49,8 +49,12 @@ void request_fake(void){
status = i2cMasterReceiveTimeout(&I2CD1, addr, rx_data, 2, tmo);
i2cReleaseBus(&I2CD1);
if (status != RDY_OK){
if (status == RDY_RESET){
errors = i2cGetErrors(&I2CD1);
if (errors == I2CD_ACK_FAILURE){
/* there is no slave with given address on the bus, or it was die */
return;
}
}
else{

View File

@ -45,7 +45,7 @@ void I2CInit_pns(void){
/* startups. Pauses added just to be safe */
chThdSleepMilliseconds(100);
/*init_lis3();*/
init_lis3();
}

View File

@ -51,6 +51,9 @@ static int16_t acceleration_z = 0;
* Init function. Here we will also start personal serving thread.
*/
int init_lis3(void){
msg_t status = RDY_OK;
systime_t tmo = MS2ST(4);
/* configure accelerometer */
accel_tx_data[0] = ACCEL_CTRL_REG1 | AUTO_INCREMENT_BIT; /* register address */
accel_tx_data[1] = 0b11100111;
@ -59,8 +62,13 @@ int init_lis3(void){
/* sending */
i2cAcquireBus(&I2CD1);
i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 4, accel_rx_data, 0, &errors, TIME_INFINITE);
status = i2cMasterTransmitTimeout(&I2CD1, lis3_addr, accel_tx_data, 4, accel_rx_data, 0, tmo);
i2cReleaseBus(&I2CD1);
if (status != RDY_OK){
errors = i2cGetErrors(&I2CD1);
}
return 0;
}
@ -68,11 +76,18 @@ int init_lis3(void){
*
*/
void request_acceleration_data(void){
msg_t status = RDY_OK;
systime_t tmo = MS2ST(4);
accel_tx_data[0] = ACCEL_OUT_DATA | AUTO_INCREMENT_BIT; /* register address */
i2cAcquireBus(&I2CD1);
i2cMasterTransmit(&I2CD1, lis3_addr, accel_tx_data, 1, accel_rx_data, 6, &errors, TIME_INFINITE);
status = i2cMasterTransmitTimeout(&I2CD1, lis3_addr, accel_tx_data, 1, accel_rx_data, 6, tmo);
i2cReleaseBus(&I2CD1);
if (status != RDY_OK){
errors = i2cGetErrors(&I2CD1);
}
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);

View File

@ -48,17 +48,17 @@ static msg_t Blink(void *arg) {
/*
* Accelerometer thread
*/
/*static WORKING_AREA(PollAccelThreadWA, 256);
static WORKING_AREA(PollAccelThreadWA, 256);
static msg_t PollAccelThread(void *arg) {
chRegSetThreadName("PollAccel");
(void)arg;
while (TRUE) {
chThdSleepMilliseconds(rand() & 31);
/*chThdSleepMilliseconds(rand() & 31);*/
chThdSleepMilliseconds(32);
request_acceleration_data();
}
return 0;
}*/
}
/* Temperature polling thread */
@ -103,11 +103,11 @@ int main(void) {
I2CInit_pns();
/* Create accelerometer thread */
/*chThdCreateStatic(PollAccelThreadWA,
chThdCreateStatic(PollAccelThreadWA,
sizeof(PollAccelThreadWA),
NORMALPRIO,
PollAccelThread,
NULL);*/
NULL);
/* Create temperature thread */
chThdCreateStatic(PollTmp75ThreadWA,