writeI2C0(Gyro_ADDR,CTRL_REG1,0xCF);
writeI2C0(Gyro_ADDR,CTRL_REG2,0x00);
writeI2C0(Gyro_ADDR,CTRL_REG3,0x08);
writeI2C0(Gyro_ADDR,CTRL_REG4,0x30);
writeI2C0(Gyro_ADDR,CTRL_REG5,0x00);
signed int getRotation_Y(){
signed int short raw = (signed int short) getRotation_rawY();
signed int Rotation = (signed int)raw;
return Rotation;
}
uint16_t getRotation_rawY(){
uint8_t rotData1, rotData2;
rotData1=readI2C0(Gyro_ADDR,OUT_Y_L);
rotData2=readI2C0(Gyro_ADDR,OUT_Y_H);
uint16_t rawY = (rotData2<<8)|rotData1;
return (rawY);
}
UART_OutUDec((unsigned int) rotationX)
{
if(n >= 10){
UART_OutUDec(n/10);
n = n%10;
}
UART_OutChar(n+'0'); /* n is between 0 and 9 */
}
}
#include <stdint.h>
#include <stdbool.h>
#include "driverlib/sysctl.h"
#include "Nokia5110.h"
#include "L3G4200D_Gyroscope.h"
#include "inc/tm4c123gh6pm.h"
#include "UART.h"
#include "PLL.h"
int main (void)
{
signed int rotationX, rotationY, rotationZ;
// Set the clocking to run directly from the external crystal/oscillator.
SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_OSC_INT | SYSCTL_XTAL_16MHZ);
UART_Init();
PLL_Init();
UART_OutString("Testing\r\n");
init_L3G4200D_Gyroscope();
// PortF_Init();
SetPowerMode(0x01);
int i,k,j=0;
while(1){
rotationX = getRotation_X();
if (rotationX>=0) {
UART_OutString("\r\nX Rot: ");
UART_OutUDec((unsigned int) rotationX);
} else {
UART_OutString("\r\nX Rot*: -");
UART_OutUDec((unsigned int) (rotationX*-1));
}
}
return 0;
}
#include <stdint.h>
#include "Tiva_i2c.h"
#include "L3G4200D_Gyroscope.h"
void init_L3G4200D_Gyroscope(){
initI2C0();
writeI2C0(Gyro_ADDR,CTRL_REG1,0x0F);
writeI2C0(Gyro_ADDR,CTRL_REG2,0x00);
writeI2C0(Gyro_ADDR,CTRL_REG3,0x08);
writeI2C0(Gyro_ADDR,CTRL_REG4,0x80);
writeI2C0(Gyro_ADDR,CTRL_REG5,0x00);
}
void SetPowerMode(unsigned char powerMode) {
uint8_t i2c_data = readI2C0(Gyro_ADDR,0x2d);
if (powerMode==1){
i2c_data = i2c_data | (powerMode<<3);
} else if (powerMode==0){
i2c_data &= ~(1<<3);
}
i2c_data = i2c_data | (powerMode<<3);
writeI2C0(Gyro_ADDR,0x2d,i2c_data);
}
uint16_t getRotation_rawX(){
uint16_t rotData1, rotData2;
rotData1=readI2C0(Gyro_ADDR,OUT_X_L);
rotData2=readI2C0(Gyro_ADDR,OUT_X_H);
UART_OutString("\r\nX rotData1: ");
UART_OutUDec(rotData1);
UART_OutString("\r\nX rotData2: ");
UART_OutUDec(rotData2);
uint16_t rawX = (rotData2<<8)|rotData1;
UART_OutString("\r\nX rawX: ");
UART_OutUDec(rawX);
return (rawX);
}
signed int getRotation_X(){
signed int short raw = (signed int short) getRotation_rawX();
signed int Rotation = (signed int)raw;
return Rotation;
}
#include <stdint.h>
#include <stdbool.h>
#include "Tiva_i2c.h"
#include "inc/tm4c123gh6pm.h"
#include "inc/hw_i2c.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/i2c.h"
#include "driverlib/sysctl.h"
#include "driverlib/gpio.h"
#include "driverlib/pin_map.h"
#define GPIO_PB2_I2C0SCL 0x00010803
#define GPIO_PB3_I2C0SDA 0x00010C03
void initI2C0(void)
{
//This function is for eewiki and is to be updated to handle any port
//enable I2C module
SysCtlPeripheralEnable(SYSCTL_PERIPH_I2C0);
//reset I2C module
SysCtlPeripheralReset(SYSCTL_PERIPH_I2C0);
//enable GPIO peripheral that contains I2C
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB);
// Configure the pin muxing for I2C0 functions on port B2 and B3.
GPIOPinConfigure(GPIO_PB2_I2C0SCL);
GPIOPinConfigure(GPIO_PB3_I2C0SDA);
// Select the I2C function for these pins.
GPIOPinTypeI2CSCL(GPIO_PORTB_BASE, GPIO_PIN_2);
GPIOPinTypeI2C(GPIO_PORTB_BASE, GPIO_PIN_3);
// Enable and initialize the I2C0 master module. Use the system clock for
// the I2C0 module. The last parameter sets the I2C data transfer rate.
// If false the data rate is set to 100kbps and if true the data rate will
// be set to 400kbps.
I2CMasterInitExpClk(I2C0_BASE, SysCtlClockGet(), false);
//clear I2C FIFOs
HWREG(I2C0_BASE + I2C_O_FIFOCTL) = 80008000;
}
uint8_t readI2C0(uint16_t device_address, uint16_t device_register)
{
//specify that we want to communicate to device address with an intended write to bus
I2CMasterSlaveAddrSet(I2C0_BASE, device_address, false);
//the register to be read
I2CMasterDataPut(I2C0_BASE, device_register);
//send control byte and register address byte to slave device
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_SEND);
//wait for MCU to complete send transaction
while(I2CMasterBusy(I2C0_BASE));
//read from the specified slave device
I2CMasterSlaveAddrSet(I2C0_BASE, device_address, true);
//send control byte and read from the register from the MCU
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_SINGLE_RECEIVE);
//wait while checking for MCU to complete the transaction
while(I2CMasterBusy(I2C0_BASE));
//Get the data from the MCU register and return to caller
return( I2CMasterDataGet(I2C0_BASE));
}
void writeI2C0(uint16_t device_address, uint16_t device_register, uint8_t device_data)
{
//specify that we want to communicate to device address with an intended write to bus
I2CMasterSlaveAddrSet(I2C0_BASE, device_address, false);
//register to be read
I2CMasterDataPut(I2C0_BASE, device_register);
//send control byte and register address byte to slave device
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_SEND_START);
//wait for MCU to finish transaction
while(I2CMasterBusy(I2C0_BASE));
I2CMasterSlaveAddrSet(I2C0_BASE, device_address, true);
//specify data to be written to the above mentioned device_register
I2CMasterDataPut(I2C0_BASE, device_data);
//wait while checking for MCU to complete the transaction
I2CMasterControl(I2C0_BASE, I2C_MASTER_CMD_BURST_RECEIVE_FINISH);
//wait for MCU & device to complete transaction
while(I2CMasterBusy(I2C0_BASE));
}
You configure it to the least sensitve range. Are you moving the gyro? Else there will be no change.
What should I do. I'm even not moving the Magnetometer.
. Your effort is some seconds to copy and past this code snippet. For us it takes long time to go through the datasheet to check every single bit. And even then we don't know if the setup is what you wanted.I'm initializing the L3G4200D gyrometer registers with following mentioned values
Self_test(){
writeI2C0(Compass_ADDR,Config_Reg_A,0x71);
writeI2C0(Compass_ADDR,Config_Reg_B,0xA0);
writeI2C0(Compass_ADDR,Mode_Reg,0x00);
delay();
x = getMagField_rawX();
y = getMagField_rawY();
z = getMagField_rawZ();
writeI2C0(Compass_ADDR,Config_Reg_A,0x00);
}
writeI2C0(Compass_ADDR,Config_Reg_A,0x00);
writeI2C0(Compass_ADDR,Config_Reg_B,0x20);
writeI2C0(Compass_ADDR,Mode_Reg,0x00);
signed int magfieldX = getMagField_X();
if (magfieldX>=0) {
UART_OutString("\r\nX mField: ");
UART_OutUDec((unsigned short) magfieldX);
} else {
UART_OutString("\r\nX mField: -");
UART_OutUDec((unsigned short) (magfieldX*-1));
}
signed int getMagField_X(){
signed int short raw = (signed int short) getMagField_rawX();
signed int data = (signed int)(((signed int)raw) * 0.92); // 0.92 is Digital Resolution (mG/LSB)
return data;
}
uint16_t getMagField_rawX(){
uint8_t mfData1, mfData2;
mfData1=readI2C0(Compass_ADDR,HMC5883L_OUT_X_L);
mfData2=readI2C0(Compass_ADDR,HMC5883L_OUT_X_H);
uint16_t rawX = (mfData2<<8)|mfData1;
return (rawX);
}
x: 482
y: 445
z: 426
x: 482
y: 445
z: 426
x: 482
y: 445
z: 426
x: 482
y: 445
z: 426
x: 482
y: 445
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 481
y: 89
z: 426
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 483
y: 446
z: 424
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 65147
y: 348
z: 425
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 482
y: 448
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 483
y: 65307
z: 426
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 482
y: 446
z: 425
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 65530
y: 446
z: 427
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 481
y: 445
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 65344
z: 426
x: 482
y: 447
z: 424
x: 482
y: 447
z: 424
x: 460
y: 65424
z: 98
X mField: 423
Y mField: -103
Z mField: 90
trial 0
X mField: 423
Y mField: -103
Z mField: 90
trial 1
X mField: 420
Y mField: -103
Z mField: 89
trial 2
X mField: 421
Y mField: -104
Z mField: 86
trial 3
X mField: 423
Y mField: -103
Z mField: 87
trial 4
X mField: 421
Y mField: -103
Z mField: 88
trial 5
X mField: 421
Y mField: -103
Z mField: 90
trial 6
X mField: 421
Y mField: -105
Z mField: 88
trial 7
X mField: 423
Y mField: -103
Z mField: 85
trial 8
X mField: 423
Y mField: -105
Z mField: 86
trial 9
X mField: 421
Y mField: -102
Z mField: 89
trial 10
X mField: 418
Y mField: -106
Z mField: 88
trial 11
X mField: 420
Y mField: -105
Z mField: 87
trial 12
X mField: 420
Y mField: -105
Z mField: 87
trial 13
X mField: 423
Y mField: -102
Z mField: 84
trial 14
X mField: 424
Y mField: -103
Z mField: 87
trial 15
X mField: 421
Y mField: -103
Z mField: 88
trial 16
X mField: 421
Y mField: -104
Z mField: 86
trial 17
Configuration Register A = 0x71
-->no of samples averaged = 1
-->outout data rate = 1.5 Hz
When one or more of the output registers are read, new data cannot be placed in any of the output data registers until all six data output registers are read. This requirement also impacts DRDY and RDY, which cannot be cleared until new data is placed in all the output registers.
selftsest:
* first read data without additional magnetic field, synchronized. Maybe multiple times
* then switch on additional magnetic field. Do some synced readings.
* then switch on reverse magnetic field. Do some synced readings.
* calculate the difference between that values with and without additional field. Only the difference is of interest.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?