From e3897565c342bee4765f921240b7ca91cd9b23f1 Mon Sep 17 00:00:00 2001 From: Lars-Dominik Braun Date: Mon, 31 Mar 2014 11:18:32 +0200 Subject: Activate accel + timer --- accel.c | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'accel.c') diff --git a/accel.c b/accel.c index a178fa3..670121e 100644 --- a/accel.c +++ b/accel.c @@ -23,7 +23,6 @@ static volatile int8_t val[6] = {0, 0, 0, 0, 0, 0}; /* currently reading from i2c */ static bool reading = false; -#warning "wrong interrupt" /* data ready interrupt */ ISR(PCINT1_vect) { @@ -31,13 +30,13 @@ ISR(PCINT1_vect) { } void accelInit () { - /* set PB1 to input, with pull-up */ - //DDRB = (DDRB & ~((1 << PB1))); - //PORTB = (PORTB | (1 << PB1)); - /* enable interrupt PCI0 */ - //PCICR = (1 << PCIE0); - /* enable interrupts on PB1/PCINT1 */ - //PCMSK0 = (1 << 1); + /* set interrupt lines to input with pull-up */ + DDRC = DDRC & ~((1 << PC0) | (1 << PC1)); + PORTC = PORTC | (1 << PC0) | (1 << PC1); + /* enable interrupt PCI1 for PCINT8/9 */ + PCICR = PCICR | (1 << PCIE1); + /* enable interrupts from port PC0/PC1 aka PCINT8/PCINT9 */ + PCMSK1 = (1 << PCINT9) | (1 << PCINT8); } /* XXX: make nonblocking */ @@ -45,9 +44,9 @@ void accelStart () { /* configuration: * disable power-down-mode * defaults - * data ready interrupt on int2 + * low active, data ready interrupt on int2 */ - uint8_t data[] = {0b01000111, 0b0, 0b00100000}; + uint8_t data[] = {0b01000111, 0b0, 0b10100000}; if (!twRequest (TWM_WRITE, LIS302DL, LIS302DL_CTRLREG1, data, sizeof (data)/sizeof (*data))) { @@ -64,11 +63,11 @@ bool accelProcess () { reading = false; return true; } else if (twr.status == TWST_ERR) { - printf ("accel i2c error\n"); + printf ("accel i2c error %x at step %i\n", twr.error, twr.step); reading = false; } } else { - if (drdy && twr.status != TWST_WAIT) { + if (/*drdy &&*/ twr.status != TWST_WAIT) { /* new data available in device buffer and bus is free, we are * reading the registers inbetween out_x/y/z and ignore them */ if (!twRequest (TWM_READ, LIS302DL, LIS302DL_UNUSED1, (uint8_t *) val, 6)) { @@ -83,3 +82,7 @@ bool accelProcess () { return false; } +volatile const int8_t *accelGet () { + return val; +} + -- cgit v1.2.3