// // //// SPI Communication #include "msp430F5438A.h" // einf¸gen der Mikroprozessordaten #include "stdint.h" //Variables uint8_t addr; uint8_t dataX0; uint8_t dataX1; uint8_t dataY0; uint8_t dataY1; uint8_t dataZ0; uint8_t dataZ1; uint8_t Test; uint8_t receive_byte; uint8_t receive_data; //Settings of the ADXL345 uint8_t testreadwrite(); //void spi_senden_CONFG(); //Coordinate axes x,y,z //uint8_t DATAX0readwrite(); // DATAX0 //uint8_t DATAX1readwrite(); // DATAX1 //uint8_t DATAY0readwrite(); // DATAY0 //uint8_t DATAY1readwrite(); // DATAY1 //uint8_t DATAZ0readwrite(); // DATAZ0 //uint8_t DATAZ1readwrite(); // DATAZ1 void main (void) // Starting main program { WDTCTL=WDTPW+WDTHOLD; // turn of the Watchdogs P10SEL|= BIT0 + BIT1 + BIT2 + BIT3; //P10SEL|=0x0F; // SCLK, BIT3, P10.3 ; MOSI ist 1 auf P10.1 ; SOMI ist 0 auf P10.2, CS(low active) auf 1 am P10.0, 0b00001101 // PSEL, SPI Konfiguration ausw‰hlen, 0b00001111 P10DIR|=0x40; //P10DIR|=0x0D; //GPIO-Pin 10.6, defining the direction, output UCB3CTL1|=UCSWRST; // **Put state machine in reset** !!! UCB3CTL0|= UCSYNC | UCMST | UCMSB | UCCKPL | UCMODE1; // synchronous Mode,3 pin SPI, (4 pin SPI, old), Master Mode, MSB first UCB3CTL1|=UCSSEL_2; // SMCLK UCB3BR0|=0x02; // Rate, UCA3BR0 and UCA3BR1, (UCAxBR0 + UCAxBR1 ? 256) UCB3BR1=0; UCB3IE|=UCRXIE + UCTXIE; // Interrupts enable UCB3CTL1&=~UCSWRST; // Initialising of the State machine // spi_senden_CONFG(); while (1) { //spi_senden_CONFG(); // __delay_cycles(50000); testreadwrite(); //DATAX0readwrite(); // DATAX0 //DATAX1readwrite(); // DATAX1 //DATAY0readwrite(); // DATAY0 //DATAY1readwrite(); // DATAY1 //DATAZ0readwrite(); // DATAZ0 //DATAZ1readwrite(); // DATAZ1 // __delay_cycles(100); // P10OUT|=BIT6; // putting CS to 1 to end transmission } } // end main program //------------------------------------------------------------------------------------------------------------------------ //// Testfunction for SPI, receiving ID of the ADXL345, David Versuche //uint8_t testreadwrite() // Testfunction //{ // P10OUT &= ~BIT6; // CS putting to low to start transmission // // __delay_cycles(10); // inserting a delay // // while (!(UCB3STAT & UCBUSY)==0); // while (UCBUSY!=0)); // UCB3TXBUF = 0x80; // UCB3IFG &=~UCTXIFG; // UCB3TXBUF=0xFF; // dataX0= UCB3RXBUF; // UCB3IFG &=~UCRXIFG; // while (!(UCB3STAT & UCBUSY)==0); // UCB3IFG &=~UCTXIFG; // // __delay_cycles(10); // P10OUT|=BIT6; // // sending // // clearing the flag // // // // UCB3TXBUF=0xFF; // sending dummy byte // // // // return(dataX0); // // putting CS to 1 in the while loop outside of the function //}; //------------------------------------------------------------------------------------------------------------------------ uint8_t testreadwrite() // Testfunction { P10OUT&=~BIT6; // CS putting to low to start transmission __delay_cycles(10); // inserting a delay while (!(UCB3STAT&UCBUSY)==0); // while (UCBUSY!=0)); UCB3TXBUF=0x80; // sending UCB3IFG&=~UCTXIFG; // clearing the flag while (!(UCB3STAT&UCBUSY)==0); UCB3TXBUF=0xFF; // sending dummy byte UCB3IFG&=~UCTXIFG; receive_data=UCB3RXBUF; __delay_cycles(10); P10OUT|=BIT6; return(receive_data); // putting CS to 1 in the while loop outside of the function };