Hi,
I'm trying to interface the kit launchpad to sensor tmp121
and I'm not getting satisfactory results, can someone help me please.
// TMP121 | | MSP430F202231 |
// -----------------------------------------------------------------
// | P5 CS| <--- | P1.1 |
// | P6 DATAOUT| ---> | P1.7/SOMI P1.0|-->LED
// | P4 CLK| <--- | P1.5/SCLK |
//
//******************************************************************************
#include <msp430x20x3.h>
void main(void)
{
int i;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
DCOCTL = CALDCO_1MHZ;
BCSCTL1 = CALBC1_1MHZ;
P1OUT = 0;
P1DIR |= 0x03;
USICTL0 |= USIPE7 + USIPE5 + USIMST + USIOE; // Port, SPI master
USICTL1 |= USIIE; // Counter interrupt, flag remains set
USICKCTL = USIDIV_2 + USISSEL_2; // /4 SMCLK
USICTL0 &= ~USISWRST; // USI released for operation
USICNT = USI16B + 16; // init-load counter
P1OUT |= 0x02; //init sensor convertion
_BIS_SR(LPM0_bits + GIE); // Enter LPM0 w/ interrupt
}
// USI interrupt service routine
#pragma vector=USI_VECTOR
__interrupt void universal_serial_interface(void)
{
int aux, i;
float tmp = 0;
P1OUT &= ~0x02; // init data transfer
for(i=0x100;i>1000;i--); // delay for data transfer
aux = (USISR >> 3);
if (aux & 0x1000) //for a negative value
{
aux ^= 0x1FFF;
aux += 0x0001;
}
tmp = aux/16;
if (tmp > 15) // if temperature > 15 deg celcius set led
P1OUT |= 0x01;
else
P1OUT &= ~0x01;
P1OUT |= 0x02; //start new convertion
USICNT = USI16B + 16; // re-load counter
}
COMMUNICATING WITH THE TMP121 (datasheet) The TMP121 and TMP123 continuously convert temperatures to digital data while CS is high. CS must be high for a minimum of one conversion time (320ms max) to update the temperature data. Reading temperature data from the TMP121 and TMP123 is initiated by pulling CS low, which will cause any conversion in progress to terminate, and place the device into analog shutdown. Quiescent current is reduced to 1 u
A during analog
shutdown. Once CS is pulled low, temperature data from the last completed conversion prior to dropping CS is latched into the shift register and clocked out at SO on the falling SCK edge. The 16-bit data word is clocked out sign bit first, followed by the MSB. Any portion of the 16-bit word can be read before raising CS. The TMP121 and TMP123 typically require 0.25s to complete a conversion and consume 50 u
A of current during this period. If CS is held
high for longer than one conversion time period the TMP121 and TMP123 will go into idle mode for 0.25s, requiring only 20 u
A of current. A new conversion begins every 0.5s.