Advertisement
Guest User

l3g4200d.c

a guest
Jan 5th, 2012
556
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.43 KB | None | 0 0
  1. #include "l3g4200d.h"
  2. #include "spidrv.h"
  3. #include "uart.h"
  4. #include <stdio.h>
  5.  
  6. #define DEBUG 1
  7. #define MOD_NAME "l3g4200d.c"
  8.  
  9. void l3g4200d_init()
  10. {
  11.   l3g4200d_initExti();
  12.   l3g4200d_initInt();
  13.   uint8_t did = spi2_read(SPI_GYRO, GYRO_REG_ID);
  14.   if (did != GYRO_ID_VAL)
  15.   {
  16. #ifdef DEBUG
  17.     //printf("%s %s - l3g4200d_init() - wrong device ID %i (expected %i) \n\r", ERR, MOD_NAME, did, GYRO_ID_VAL);
  18.     uart_print("l3g4200d.c - l3g4200d_init - ERROR: WRONG DEVICE ID!!!\n\r");
  19. #endif
  20.     return;
  21.   }
  22.   // all these readings gives normal values
  23.   uint8_t ctrl1 = spi2_read(SPI_GYRO, GYRO_REG_CTRL_1);
  24.   uint8_t ctrl2 = spi2_read(SPI_GYRO, GYRO_REG_CTRL_2);
  25.   uint8_t ctrl3 = spi2_read(SPI_GYRO, GYRO_REG_CTRL_3);
  26.   uint8_t ctrl4 = spi2_read(SPI_GYRO, GYRO_REG_CTRL_4);
  27.   uint8_t ctrl5 = spi2_read(SPI_GYRO, GYRO_REG_CTRL_5);
  28.  
  29.   spi2_write(SPI_GYRO, GYRO_REG_CTRL_2, GYRO_HPCOFF15);
  30.   spi2_write(SPI_GYRO, GYRO_REG_CTRL_3, GYRO_DRDYINT);
  31.   // if i'll try to read after writing i will getting 0xFF till gyroscope reset
  32.   ctrl3 = spi2_read(SPI_GYRO, GYRO_REG_CTRL_3);
  33.   spi2_write(SPI_GYRO, GYRO_REG_CTRL_4, GYRO_FS500 | GYRO_BDU );//| GYRO_BIGENDIAN);
  34.   spi2_write(SPI_GYRO, GYRO_REG_CTRL_5, 0x00);
  35.   spi2_write(SPI_GYRO, GYRO_REG_CTRL_1, GYRO_PWRON | GYRO_ODR400C25 | GYRO_ZYXEN);
  36. #ifdef DEBUG
  37.   //printf("%s %s - l3g4200d_init() - OK\n\r", DBG, MOD_NAME);
  38.   uart_print("l3g4200d.c - l3g4200d_init - OK\n\r");
  39. #endif
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement