Other Parts Discussed in Thread: MSP430FR2355,
Hi,
I want to use the TMP126 with the MSP430FR2355.
I use the following code :
#include <msp430.h>
unsigned int G_uint8compt = 1;
unsigned int recu[3] = {0}; // ADC
int main(void)
{
WDTCTL = WDTPW|WDTHOLD; // Stop watchdog timer
P1SEL0 |= BIT1 | BIT2 | BIT3; // set 4-SPI pin as second function
UCB0CTLW0 |= UCSWRST; // **Put state machine in reset**
UCB0CTLW0 |= UCMST|UCSYNC|UCCKPL|UCMSB|UCMODE_0;
// Clock polarity high, MSB
UCB0CTLW0 |= UCSSEL__SMCLK; // Select ACLK
UCB0BR0 = 0x01; // BRCLK = ACLK/2
UCB0BR1 = 0; //
//UCB0MCTLW = 0; // No modulation
UCB0CTLW0 &= ~UCSWRST; // **Initialize USCI state machine**
P3DIR |= BIT4; // Set P1.0 to output direction
P3OUT |= BIT4; // Clear P1.0 output latch for a defined power-on state
PM5CTL0 &= ~LOCKLPM5; // Disable the GPIO power-on default high-impedance mode
// to activate previously configured port settings
__bis_SR_register(GIE); // Enter LPM0, enable interrupts
UCB0IE |= UCRXIE;
UCB0IFG &= ~UCRXIFG;
while(1)
{
P3OUT &= ~BIT4;
UCB0TXBUF = 0x01; // Transmit characters
while(!(UCB0IFG & UCTXIFG));
UCB0TXBUF = 0x00;
while(!(UCB0IFG & UCTXIFG));
UCB0TXBUF = 0x00;
UCB0TXBUF = 0x00;
P3OUT |= BIT4;
__no_operation();
if(G_uint8compt==2)
{
G_uint8compt = 1;
}
}
}
#if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
#pragma vector=USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
#elif defined(__GNUC__)
void __attribute__ ((interrupt(USCI_B0_VECTOR))) USCI_B0_ISR (void)
#else
#error Compiler not supported!
#endif
{
switch(__even_in_range(UCB0IV,USCI_SPI_UCTXIFG))
{
case USCI_NONE: break; // Vector 0 - no interrupt
case USCI_SPI_UCRXIFG:
recu[G_uint8compt] = UCB0RXBUF;
UCB0IFG &= ~UCRXIFG;
G_uint8compt ++;
break;
case USCI_SPI_UCTXIFG:
__no_operation();
break;
default: break;
}
}
On the scope, everything is fine : the two first bytes are sent to the TMP126 and the sensor answers with good data in the next two bytes. But at the code composer side, the byte received is only the second byte. It seems that the MSP miss the first byte.
Any idea?
Thanks