halancik 0 Posted September 16, 2013 Share Posted September 16, 2013 Hello, I try to comunicate with ADXRS450 via SPI. But receive data is always is same. All detail and code: #include "msp430.h" #include <signal.h> #define CS_DIS {P1DIR|=BIT3;P1OUT|=BIT3;} #define CS_ENA {P1DIR|=BIT3;P1OUT&=~BIT3;} void SPI_Write(unsigned char Data_for_write); void SPI_Disable(void); void SPI_Init(void); int SPI_Read(void); void ADXRS450_Init(void); unsigned char Byte; long Measure_byte_first; long Measure_byte_second; long Measure_byte_third; long Measure_byte_four; long Measurement; int main() { WDTCTL = WDTPW + WDTHOLD; CS_DIS; SPI_Init(); __delay_cycles(10000); ADXRS450_Init(); while((UCB0STAT&UCBUSY)); for(; { CS_ENA; while((UCB0STAT&UCBUSY)); SPI_Write(0x20); SPI_Write(0x00); SPI_Write(0x00); SPI_Write(0x00); while((UCB0STAT&UCBUSY)); CS_DIS; __delay_cycles(50000); CS_ENA; while((UCB0STAT&UCBUSY)); SPI_Write(0x00); Measure_byte_first = UCA0RXBUF; SPI_Write(0x00); Measure_byte_second = (UCA0RXBUF<<8); SPI_Write(0x00); Measure_byte_third = (UCA0RXBUF<<8); SPI_Write(0x00); Measure_byte_four = (UCA0RXBUF<<8); while((UCB0STAT&UCBUSY)); CS_DIS; Measurement = (Measure_byte_first | Measure_byte_second | Measure_byte_third | Measure_byte_four); Measurement = (int)((Measurement & 0x3FFFC00) >> 10); Measurement = ((Measurement) / 80); __delay_cycles(50000); } } void SPI_Init(void) { P1SEL = BIT1 + BIT2 + BIT4; P1SEL2 = BIT1 + BIT2 + BIT4; UCA0CTL1 = UCSWRST; UCA0CTL0 |= UCMSB + UCMST + UCSYNC + UCCKPL; // 3-pin, 8-bit SPI master UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 |= 0x02; // /2 UCA0BR1 = 0; UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** } void SPI_Write(unsigned char Byte) { while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF = Byte; } void SPI_Disable(void) { UCB0CTL1 |= UCSWRST; } int SPI_Read(void) { while (!(IFG2 & UCA0RXIFG)); UCA0TXBUF = 0x00; return UCA0RXBUF; } void ADXRS450_Init(void) { __delay_cycles(150000); CS_ENA; SPI_Write(0x20); SPI_Write(0x00); SPI_Write(0x00); SPI_Write(0x03); CS_DIS; __delay_cycles(150000); CS_ENA; SPI_Write(0x20); SPI_Write(0x00); SPI_Write(0x00); SPI_Write(0x00); CS_DIS; __delay_cycles(250000); CS_ENA; SPI_Write(0x20); SPI_Write(0x00); SPI_Write(0x00); SPI_Write(0x00); CS_DIS; __delay_cycles(250000); CS_ENA; SPI_Write(0x20); SPI_Write(0x00); SPI_Write(0x00); SPI_Write(0x00); CS_DIS; __delay_cycles(250000); } Quote Link to post Share on other sites
polashmisra 0 Posted January 28, 2014 Share Posted January 28, 2014 The sensitivity of the ADXRS450 output depends on the power supply applied to it. For a better power supply module along with the Breakout board for ADXRS450 is available on http://doproto.com/store/35-gyroscopeadxrs450-300-degs-digital-output.html Quote Link to post Share on other sites
roadrunner84 466 Posted January 28, 2014 Share Posted January 28, 2014 This looks incorrect: SPI_Write(0x00); Measure_byte_first = UCA0RXBUF; SPI_Write(0x00); Measure_byte_second = (UCA0RXBUF<<8); SPI_Write(0x00); Measure_byte_third = (UCA0RXBUF<<8); SPI_Write(0x00); Measure_byte_four = (UCA0RXBUF<<8); while((UCB0STAT&UCBUSY)); CS_DIS; Measurement = (Measure_byte_first | Measure_byte_second | Measure_byte_third | Measure_byte_four); Measurement = (int)((Measurement & 0x3FFFC00) >> 10); Measurement = ((Measurement) / 80); How about this? SPI_Write(0x00); Measure_byte_first = UCA0RXBUF; SPI_Write(0x00); Measure_byte_second = UCA0RXBUF; SPI_Write(0x00); Measure_byte_third = UCA0RXBUF; SPI_Write(0x00); Measure_byte_four = UCA0RXBUF; while((UCB0STAT&UCBUSY)); CS_DIS; Measurement = (Measure_byte_first | (Measure_byte_second<<8) | (Measure_byte_third<<16) | (Measure_byte_four<<24)); Measurement = (int)((Measurement & 0x3FFFC00) >> 10); Measurement = ((Measurement) / 80); Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.