/// SPI Communication #include "msp430F5438A.h" // microprozessor #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(); 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 | UCCKPH | 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; UCB3CTL1&=~UCSWRST; // Initialising of the State machine while (1) { testreadwrite(); } uint8_t testreadwrite() // Testfunction { P10OUT&=~BIT6; // CS putting to low to start transmission __delay_cycles(1); // inserting a delay 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 (!(UCRXIFG)); receive_data=UCB3RXBUF; //ergänzt __delay_cycles(1); P10OUT|=BIT6; return(receive_data); // putting CS to 1 in the while loop outside of the function };