int main(void) { WDTCTL = WDTPW | WDTHOLD; //watchdog_disable(); /* Inizializzo lo stack pointer al valore 0x5FF in fondo alla RAM */ __asm (" MOV.W #0x0600,SP"); clear_RAM(); delay_watchdog (wdt_delay); watchdog_enable(); configurazione_iniziale(); display_initialization(); configurazione_SPI(); trasmissione_CONFIGURAZIONI(); FREE=0; //Is a counter linked with 100ms timer while (1) { watchdog(); if(FREE>5) { //Wait 500ms Lettura_SPI(); FREE=0; } } } void configurazione_SPI() { 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** } void trasmissione_CONFIGURAZIONI() { unsigned int Configuration_Write; Configuration_Write = 0x80; P3OUT &= (~BIT3); // Select Device UCA0TXBUF=(Configuration_Write); // Send 0x80 over SPI to MAX31865 to write on its internal Configuration_Register while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=CONREG_MAX50; //Write in the Configuration_Register to set VBias, Conversion Mode and Filter's Frequency bits while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0x00; while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0x00; while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0xFF; while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0xFF; while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0x00; while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0x00; while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0x00; while (!(IFG2 & UCA0TXIFG)); loop_delayREAD(); P3OUT |= (BIT3); // Unselect Device } //loop_delayREAD is an asm function for a little delay loop_delayREAD: mov.w #0x20, R4 loop_delay: dec R4 jnz loop_delay ret void Lettura_SPI() { unsigned char count; unsigned char var[8]; Configuration_Read= 0x00; P3OUT &= (~BIT3); loop_delayREAD(); UCA0TXBUF=0x00; while (!(IFG2 & UCA0TXIFG)); UCA0TXBUF=0x00; while (!(IFG2 & UCA0TXIFG)); for(count=0; count<8; count++) { UCA0TXBUF=(0x00+count); while (!(IFG2 & UCA0TXIFG)); var[count]=UCA0RXBUF; } loop_delayREAD(); P3OUT |= (BIT3); } /*var[1] and var[2] should be my RTD_MSB and RTD_LSB respectively but what I read isn't correct*/