Hello,
i wrote a simple program to check if i can read the drdy signal through the interrupt pin
Datasheet l3gd20h
it shows on the serial screen always “value = 0”.
What am I doing wrong?
i wrote a simple program to check if i can read the drdy signal through the interrupt pin
Code:
#include "SPI.h"
#define DRDY_PIN 30 // labeled DRDY
#define CS_PIN 10 // labeled CS
#define GYRO_MOSI 11 // labeled SA0
#define GYRO_MISO 12 // labeled SDA
#define GYRO_SCK 13 // labeled SCL
const uint8_t L3GD20_REGISTER_CTRL_REG1 = 0x20;
const uint8_t L3GD20_REGISTER_CTRL_REG3 = 0x22;
///////////////////////////////////////////////////////////////////
void writeReg(uint8_t reg, uint8_t value) {
digitalWrite(CS_PIN, LOW);
SPI.transfer(reg);
value = SPI.transfer(value);
digitalWrite(CS_PIN, HIGH);
}
///////////////////////////////////////////////////////////////////
void interrupt(){
f++;
if(f == 5000){
value = 5000;
f = 0;
}
}
///////////////////////////////////////////////////////////////////
volatile long f = 0, value = 0;
void setup() {
Serial.begin(115200);
Serial.println("Type any chaaracter to start");
while (!Serial.available()) {}
pinMode(CS_PIN, OUTPUT);
digitalWrite(CS_PIN, HIGH);
pinMode(DRDY_PIN, INPUT_PULLUP);
attachInterrupt(DRDY_PIN, interrupt, RISING);
SPI.begin();
SPI.beginTransaction(SPISettings(10000000, MSBFIRST, SPI_MODE3));
/* Switch to normal mode and enable all three channels at 400 Hz */
writeReg(L3GD20_REGISTER_CTRL_REG1, 0b10001111);
/* Enable I2_DRDY */
writeReg(L3GD20_REGISTER_CTRL_REG3, 0b00001000);
do {
delay(10);
} while (Serial.read() >= 0);
}
///////////////////////////////////////////////////////////////////
void loop() {
Serial.print("value =");
Serial.println(value);
delay(250);
}
Datasheet l3gd20h
it shows on the serial screen always “value = 0”.
What am I doing wrong?
Last edited: