/// 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; uint8_t data; //uint8_t config = 0xFF & ~BIT6; //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 // 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 | UCCKPH | UCMODE1; // synchronous Mode,3 pin SPI, (4 pin SPI, old), Master Mode, MSB first UCB3CTL1|=UCSSEL_2; // SMCLK UCB3BR0|=0x02; //0x02; // 10; // Rate, UCA3BR0 and UCA3BR1, (UCAxBR0 + UCAxBR1 ? 256) UCB3BR1=0; UCB3CTL1&=~UCSWRST; // Initialising of the State machine // spi_senden_CONFG(); while (1) { // spi_senden_CONFG(); testreadwrite(); // DATAX0readwrite(); // DATAX0 //DATAX1readwrite(); // DATAX1 //DATAY0readwrite(); // DATAY0 //DATAY1readwrite(); // DATAY1 //DATAZ0readwrite(); // DATAZ0 //DATAZ1readwrite(); // DATAZ1 // //Testarea // // in Standby Mode // UCB3TXBUF=0x31; // Addresse, 0x31; DATA_FORMAT, wake up from standby // UCB3IFG &=~UCTXIFG; // while (!(UCB3STAT & UCBUSY)==0); // waiting // UCB3TXBUF=0x4E; //SELF_TEST | SPI | INT_INVERT | 0 | FULL_RES | Justify | Range data sozusagen, Manipulierung, 0b01001110, 0x4E; // UCB3IFG &=~UCTXIFG; // // // Ending Meassurement // // while (!(UCB3STAT & UCBUSY)==0); // waiting // UCB3TXBUF=0x2D; // Addresse POWER_CTRL, switch to measurement // UCB3IFG &=~UCTXIFG; // while (!(UCB3STAT & UCBUSY)==0); // waiting // UCB3TXBUF=0x04 ; // 0 | 0 | Link | AUTO_SLEEP | Measure | Sleep | Wakeup data sozusagen, Manipulierung, 0b0000100 // UCB3IFG &=~UCTXIFG; // // // // // // // // // // // __delay_cycles(10); // P10OUT|=BIT6; // // putting CS to 1 to end transmission // // // } } // end main program //------------------------------------------------------------------------------------------------------------------------ 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=0x31; // DATA Format Register adress while (!(UCB3STAT&UCBUSY)==0); UCB3TXBUF=0x00; // setting every BIT to 0, BIT=0 means 4 wire communication, sending while (!(UCB3STAT&UCBUSY)==0); // while (UCBUSY!==0)); UCB3TXBUF=0x80; // sending while (!(UCB3STAT&UCBUSY)==0); // while( (UCB3IFG&UCRXIFG) == 0); // receive_data=UCB3RXBUF; //eingebaut UCB3TXBUF=0xFF; // sending dummy byte //while (!(UCB3IFG&UCRXIFG)); while (!(UCTXIFG)); receive_data=UCB3RXBUF; //ergänzt // __delay_cycles(2); P10OUT|=BIT6; // P10OUT&=~BIT6; return(receive_data); // return (UCB3RXBUF); // putting CS to 1 in the while loop outside of the function };