// SPI Communication #include "msp430F5438A.h" // einf¸gen der Mikroprozessordaten #include "stdint.h" //Variables uint8_t addr; uint8_t data; 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 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(); testreadwrite(); //DATAX0readwrite(); // DATAX0 __delay_cycles(5); P10OUT|=BIT6; // putting CS to 1 to end transmission } } // end main program //// Testfunction for SPI, receiving ID of the ADXL345 uint8_t testreadwrite() // Testfunction { P10OUT &= ~BIT6; // CS putting to low to start transmission __delay_cycles(5); // inserting a delay while (!(UCA0STAT & UCBUSY)==0); // while (UCBUSY!=0)); UCB3TXBUF = 0x80; // sending UCB3IFG &=~UCTXIFG; // clearing the flag while (!(UCA0STAT & UCBUSY)==0); UCB3TXBUF=0xFF; // sending dummy byte UCB3IFG &=~UCTXIFG; return(UCB3RXBUF); // putting CS to 1 in the while loop outside of the function }; //Configuration //void spi_senden_CONFG() //{ // P10OUT &= ~BIT6; // CSquer to low setzen, starting configuration // // while (!(UCA0STAT & UCBUSY)==0); // waiting // // UCB3TXBUF=0x31; // Addresse, 0x31; // UCB3IFG &=~UCTXIFG; // while (!(UCA0STAT & UCBUSY)==0); // waiting // UCB3TXBUF=0x4E; //SELF_TEST | SPI | INT_INVERT | 0 | FULL_RES | Justify | Range data sozusagen, Manipulierung, 0b01001110, 0x4E; // UCB3IFG &=~UCTXIFG; // // while (!(UCA0STAT & UCBUSY)==0); // waiting // UCB3TXBUF=0x2C; // Addresse // UCB3IFG &=~UCTXIFG; // while (!(UCA0STAT & UCBUSY)==0); // finished? // UCB3TXBUF = 0x0A; // UCB3IFG &=~UCTXIFG; // // while (!(UCA0STAT & UCBUSY)==0); // waiting // UCB3TXBUF = 0x38; // Addresse // UCB3IFG &=~UCTXIFG; // while (!(UCA0STAT & UCBUSY)==0); // waiting // UCB3TXBUF = 0x80 ; // FIFO_MODE | FIFO_MODE | Trigger | Samples | Samples | Samples | Samples | Samples data sozusagen, Manipulierung, 0b10000000 // UCB3IFG &=~UCTXIFG; // // while (!(UCA0STAT & UCBUSY)==0); // waiting // UCB3TXBUF=0x2D; // Addresse // UCB3IFG &=~UCTXIFG; // while (!(UCA0STAT & UCBUSY)==0); // waiting // UCB3TXBUF=0x04 ; // 0 | 0 | Link | AUTO_SLEEP | Measure | Sleep | Wakeup data sozusagen, Manipulierung, 0b0000100 // UCB3IFG &=~UCTXIFG; // // // __delay_cycles(5); // // P10OUT|=BIT6; // //}; //uint8_t DATAX0readwrite() // DATAX0 //{ // P10OUT &= ~BIT6; // CS putting to low to start transmission // __delay_cycles(5); // inserting a delay // // while (!(UCA0STAT & UCBUSY)==0); // while (UCBUSY!=0)); // UCB3TXBUF = 0x32; // sending // UCB3IFG &=~UCTXIFG; // clearing the flag // while (!(UCA0STAT & UCBUSY)==0); // UCB3TXBUF=0xFF; // sending dummy byte // data= UCB3RXBUF // UCB3IFG &=~UCTXIFG; // // return(data); // // putting CS to 1 in the while loop outside of the function //};