aboutsummaryrefslogtreecommitdiff
path: root/accel.c
diff options
context:
space:
mode:
Diffstat (limited to 'accel.c')
-rw-r--r--accel.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/accel.c b/accel.c
index b58f7f7..ede53ff 100644
--- a/accel.c
+++ b/accel.c
@@ -5,6 +5,7 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/sleep.h>
+#include <util/atomic.h>
#include "i2c.h"
#include "accel.h"
@@ -16,8 +17,6 @@
#define LIS302DL_CTRLREG1 0x20
#define LIS302DL_UNUSED1 0x28
-/* the first interrupt is lost */
-static volatile bool drdy = true;
/* 0, 2 and 4 are zero, as they contain the dummy register’s content */
static volatile int8_t val[6] = {0, 0, 0, 0, 0, 0};
/* currently reading from i2c */
@@ -26,13 +25,13 @@ static bool reading = false;
/* data ready interrupt
*/
ISR(PCINT1_vect) {
- drdy = true;
+ /* empty */
}
void accelInit () {
/* set interrupt lines to input with pull-up */
- DDRC = DDRC & ~((1 << PC0) | (1 << PC1));
- PORTC = PORTC | (1 << PC0) | (1 << PC1);
+ DDRC = DDRC & ~((1 << DDC0) | (1 << DDC1));
+ PORTC = PORTC | (1 << PORTC0) | (1 << PORTC1);
/* enable interrupt PCI1 for PCINT8/9 */
PCICR = PCICR | (1 << PCIE1);
/* enable interrupts from port PC0/PC1 aka PCINT8/PCINT9 */
@@ -67,13 +66,13 @@ bool accelProcess () {
reading = false;
}
} else {
- if (drdy && twr.status != TWST_WAIT) {
+ if (!((PINC >> PINC1) & 0x1) && 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)) {
+ if (!twRequest (TWM_READ, LIS302DL, LIS302DL_UNUSED1,
+ (uint8_t *) val, 6)) {
printf ("cannot start read\n");
} else {
- drdy = false;
reading = true;
}
}