void configurazione_SPIprova() { unsigned int Configuration_Write; P3DIR |= BIT0|BIT1|BIT2|BIT3|BIT4; P3OUT |= BIT4; P3SEL = BIT0|BIT4|BIT5; //P3REN |= BIT6; UCA0CTL1 |= UCSWRST; UCA0CTL0 |= UCCKPH+UCMSB+UCMST+UCSYNC; // 3-pin, 8-bit SPI master UCA0CTL1 |= UCSSEL_2; // SMCLK UCA0BR0 |= 32; // /32 UCA0BR1 = 0; UCA0MCTL = 0; // No modulation UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine** Configuration_Write = 0x80; P3OUT &= (~BIT3); // Select Device while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = Configuration_Write; // Send 0x80 over SPI to MAX31865 to write on its internal Configuration_Register while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0x91; //Write in the Configuration_Register to set VBias, Conversion Mode and Filter's Frequency bits REG_MAX31865[0]=UCA0TXBUF; //Store the value in an array P3OUT |= (BIT3); // Unselect Device P3OUT &= (~BIT3); // Select Device UCA0TXBUF=0x83; //Send the address of the next register I want to write UCA0TXBUF=0xFF; REG_MAX31865[3]=UCA0TXBUF; P3OUT |= (BIT3); // Unselect Device P3OUT &= (~BIT3); // Select Device UCA0TXBUF=0x84; UCA0TXBUF=0xFF; REG_MAX31865[4]=UCA0TXBUF; P3OUT |= (BIT3); // Unselect Device P3OUT &= (~BIT3); // Select Device UCA0TXBUF=0x85; UCA0TXBUF=0x00; REG_MAX31865[5]=UCA0TXBUF; P3OUT |= (BIT3); // Unselect Device P3OUT &= (~BIT3); // Select Device UCA0TXBUF=0x86; UCA0TXBUF=0x00; REG_MAX31865[6]=UCA0TXBUF; P3OUT |= (BIT3); // Unselect Device } void LetturaSPI_Prova() { unsigned int Configuration_Read; P3OUT &= (~BIT3); // Select Device Configuration_Read=0x00; while (!(IFG2 & UCA0TXIFG)); // USCI_A0 TX buffer ready? UCA0TXBUF = Configuration_Read; while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0x01; //This is the read address I need to read RTD_MSB=UCA0RXBUF; //I store the value in RTD_MSB UCA0TXBUF=0x02; RTD_LSB=UCA0RXBUF; RTD=(RTD_LSB| (RTD_MSB<<8)); //I unify MSB and LSB to obtain a 16-bit value P3OUT |= (BIT3); // Unselect Device } void Get_Temperatura() { //Finally I do the conversion from RTD (resistance value) to the temperature, as written on MAX31865 datasheet unsigned int ADC_CODE; unsigned int temperatura; ADC_CODE=(RTD>>1); temperatura=(ADC_CODE/32)-256; }