STM32f103 + l3gd20h (arduino)

Hello everyone (sorry for my english)

I want to retrieve the values of my gyroscope l3gd20h using interruption. I did the program below and I don’t see what the problem is. Help!!


int8_t readReg(int8_t address) {
int8_t buffer = 0;
digitalWrite(CS, LOW);
SPI.transfer(readData | address);
buffer = SPI.transfer(writeData);
digitalWrite(CS, HIGH);
return(buffer);
}

void writeReg(int8_t address, int8_t val) {
digitalWrite(CS, LOW);
SPI.transfer(writeData | address);
SPI.transfer(val);
digitalWrite(CS, HIGH);
}

void setup() {
Serial.begin(9600);
SPI.begin();
pinMode(CS, OUTPUT);
pinMode(PC15,INPUT);
writeReg(CTRL1, 0x0F);
//pour les intérruptions

writeReg(CTRL3, 0x80);//configuration pin1
writeReg(IG_CFG,0x02);
writeReg(IG_DURATION,0x00);
writeReg(IG_THS_XH,0x34);
writeReg(IG_THS_XL,0x3E);

for(int a=0;a<20;a++){
tabx[a]=0;
taby[a]=0;
tabz[a]=0;}
attachInterrupt(PC15,sanscalibration,RISING);
}

void sanscalibration(){
gx = (int16_t) readReg(OUT_X_H) <<8 | readReg(OUT_X_L);
gy = (int16_t) readReg(OUT_Y_H) <<8 | readReg(OUT_Y_L);
gz = (int16_t) readReg(OUT_Z_H) <<8 | readReg(OUT_Z_L);
}
void loop() {
/Serial.print(“Vitesse Angulaire en degre par seconde (dps) sans calibration: \n”);
Serial.print(“X: “);Serial.print(gx, DEC); Serial.print(”\n”);
Serial.print(“Y: “);Serial.print(gy, DEC);Serial.print(”\n”);
Serial.print(“Z: “);Serial.print(gz, DEC); Serial.print(”\n”);
Serial.print("---------------------------------------------");
Serial.println();
/
}

this is not the full code…

Is it the full code now??? ( I made some modifications )

#include <SPI.h> // Include Arduino SPI library
#define CTRL1 0x20
#define OUT_X_L 0x28
#define OUT_X_H 0x29
#define OUT_Y_L 0x2A
#define OUT_Y_H 0x2B
#define OUT_Z_L 0x2C
#define OUT_Z_H 0x2D
#define CS PA4
/* Registre pour l’interruption*/
#define CTRL3 0x22
#define IG_CFG 0x30
#define IG_SRC 0x31
#define IG_DURATION 0x38
// seuil
#define IG_THS_XH 0x32
#define IG_THS_XL 0x33
#define IG_THS_YH 0x34
#define IG_THS_YL 0x35
#define IG_THS_ZH 0x36
#define IG_THS_ZL 0x37

int8_t readData = 0x80;
int8_t writeData = 0x00;
int16_t gx, gy, gz;

int8_t readReg(int8_t address) {
int8_t buffer = 0;
digitalWrite(CS, LOW);
SPI.transfer(readData | address);
buffer = SPI.transfer(writeData);
digitalWrite(CS, HIGH);
return(buffer);
}

void writeReg(int8_t address, int8_t val) {
digitalWrite(CS, LOW);
SPI.transfer(writeData | address);
SPI.transfer(val);
digitalWrite(CS, HIGH);
}

void setup() {
Serial.begin(9600);
SPI.begin();
pinMode(CS, OUTPUT);
pinMode(PC15,INPUT);
writeReg(CTRL1, 0x0F);

writeReg(CTRL3, 0x80);// Interrupt pin configuration
writeReg(IG_CFG,0x02); // Interrupt configuration
writeReg(IG_DURATION,0x00);
writeReg(IG_THS_XH,0x34);
writeReg(IG_THS_XL,0x3E);

attachInterrupt(PC15,sanscalibration,RISING);
}

void sanscalibration(){
gx = (int16_t) readReg(OUT_X_H) <<8 | readReg(OUT_X_L);
gy = (int16_t) readReg(OUT_Y_H) <<8 | readReg(OUT_Y_L);
gz = (int16_t) readReg(OUT_Z_H) <<8 | readReg(OUT_Z_L);
}
void loop() {
Serial.print(“Vitesse Angulaire en degre par seconde (dps) sans calibration: \n”);
Serial.print(“X: “);Serial.print(gx, DEC); Serial.print(”\n”);
Serial.print(“Y: “);Serial.print(gy, DEC);Serial.print(”\n”);
Serial.print(“Z: “);Serial.print(gz, DEC); Serial.print(”\n”);
Serial.print("---------------------------------------------");
Serial.println();
}

My PC15 pin is connected to Int1 of my gyroscope.