MSP430F5529 with GY-9250 X Y and Z values are all 0

36 Views Asked by At

Hi I have my Gyroscope linked up to my MSP430F5529 like so: VCC -> 5V GND -> GND SCL -> P3.1 SDA -> P3.0

And here is my Code for the MSP430:

#include <msp430.h>
#include <stdint.h>
#include <stdio.h>

#define GYRO_ADDRESS 0x68

void I2C_Init();
void readGyroscope(int* x, int* y, int* z);

void main() {
    WDTCTL = WDTPW + WDTHOLD;
    printf("Starting...\n");
    P3SEL |= 0x03;
    printf("Configuring I2C pins...\n");

    I2C_Init();
    printf("Initializing I2C...\n");

    while (1) {
        int x, y, z;
        readGyroscope(&x, &y, &z);
        printf("X: %d, Y: %d, Z: %d\n", x, y, z);
        __delay_cycles(1000000);
    }
}

void I2C_Init() {
    UCB0CTL1 = UCSWRST;
    UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC;
    UCB0BR0 = 12;
    UCB0BR1 = 0;
    UCB0I2CSA = GYRO_ADDRESS;
    UCB0CTL1 = UCSSEL_2;
    UCB0CTL1 &= ~UCSWRST;
}

void readGyroscope(int* x, int* y, int* z) {
    UCB0I2CSA = GYRO_ADDRESS;
    printf("Setting gyroscope address...\n");

    UCB0CTL1 |= UCTR;
    UCB0CTL1 |= UCTXSTT;
    UCB0TXBUF = 0x43;
    printf("Transmitting data...\n");

    UCB0CTL1 &= ~UCTR;
    UCB0CTL1 |= UCTXSTT;
    *x = (int)(UCB0RXBUF << 8);

    UCB0CTL1 &= ~UCTR;
    UCB0CTL1 |= UCTXSTT;
    *x |= UCB0RXBUF;
    *x = (*x << 8) >> 8;

    UCB0CTL1 &= ~UCTR;
    UCB0CTL1 |= UCTXSTT;
    *y = (int)(UCB0RXBUF << 8);

    UCB0CTL1 &= ~UCTR;
    UCB0CTL1 |= UCTXSTT;
    *y |= UCB0RXBUF;
    *y = (*y << 8) >> 8;

    UCB0CTL1 &= ~UCTR;
    UCB0CTL1 |= UCTXSTP;
    *z = (int)(UCB0RXBUF << 8);
    *z = (*z << 8) >> 8;
}

However, when I run the program, I constantly receive the following output:

X: 0, Y: 0, Z: 0

I tried waiting for the Buffer to be full but its stuck in this loop forever:

while (!(UCB0IFG & UCRXIFG));
0

There are 0 best solutions below