Dear Guys,
I am inerfacing sht25 with cc430f5137 .I want to read temperature value from this sensor but I am not getting it . I am using supply voltage of 2.5 V for msp and the same supply is given to sht25 from msp board and ground is same for both msp and sht25. 10 k pull up resistor for sda and scl. In order to get temperature data from sensor, first I have to select transmit mode and I am selecting sensor in Hold master mode ,for that I am sending 0xE3 as stated in the data sheet . My code hangs in the trasmit isr which is case 12 in switch case and TXIFG is not set.Kindly help me out .I need urgent help or if somebody has already made this code then kindly share it .Thanks
#include <msp430.h>
#include <stdint.h>
#include<string.h>
#include"types.h"
#define LED7 BIT7
#define LED6 BIT6
volatile int a=0,b=0;
volatile int i;
unsigned char TXData;
unsigned char TXByteCtr;
volatile uint16_t Temp;
void main(void)
{
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
P3DIR |= LED6 +LED7;
P3OUT &= ~(LED6 +LED7);
PMAPPWD = 0x02D52; // Get write-access to port mapping regs
P1MAP3 = PM_UCB0SDA; // Map UCB0SDA output to P2.6
P1MAP1 = PM_UCB0SCL; // Map UCB0SCL output to P2.7
PMAPPWD = 0; // Lock port mapping registers
P1SEL |= BIT1 + BIT3; // Select P2.6 & P2.7 to I2C function
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 |= UCSSEL_2; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x40; // Slave Address is 040h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0IE |= UCTXIE; // Enable TX interrupt
UCB0IE |= UCNACKIE;
UCB0IE |= UCRXIE;
while (1)
{
TXByteCtr = 0x01;
while (UCB0CTL1 & UCTXSTP); // Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT; // I2C TX, start condition
__bis_SR_register(LPM0_bits + GIE); // Enter LPM0 w/ interrupts
__no_operation(); // Remain in LPM0 until all data
if(a==1) // when not acknowledged by the sensor
{
UCB0CTL1 |= UCTXSTP; // I2C stop condition
a=0;
while (UCB0CTL1 & UCTXSTP);
// Ensure stop condition got sent
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 |= UCSSEL_2; // Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x40; // Slave Address is 040h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0IE |= UCTXIE; // Enable TX interrupt
UCB0IE |= UCNACKIE;
UCB0IE |= UCRXIE;
// Holds TX data
// Load TX byte counter
// Ensure stop condition got sent
UCB0CTL1 |= UCTR + UCTXSTT;
__bis_SR_register(LPM0_bits + GIE);
}
if(b==1) // for receiver setting
{
b=0;
UCB0CTL1 |= UCSWRST; // Enable SW reset
UCB0CTL0 = UCMST + UCMODE_3 + UCSYNC; // I2C Master, synchronous mode
UCB0CTL1 |= UCSSEL_2;
UCB0CTL1 &=~UCTR;// Use SMCLK, keep SW reset
UCB0BR0 = 12; // fSCL = SMCLK/12 = ~100kHz
UCB0BR1 = 0;
UCB0I2CSA = 0x40; // Slave Address is 040h
UCB0CTL1 &= ~UCSWRST; // Clear SW reset, resume operation
UCB0IE |= UCTXIE; // Enable TX interrupt
UCB0IE |= UCNACKIE;
UCB0IE |= UCRXIE;
UCB0CTL1 |= UCTXSTT;
__bis_SR_register(LPM0_bits + GIE);
}
}
}
//------------------------------------------------------------------------------
// The USCIAB0_ISR is structured such that it can be used to transmit any
// number of bytes by pre-loading TXByteCtr with the byte count.
//------------------------------------------------------------------------------
#pragma vector = USCI_B0_VECTOR
__interrupt void USCI_B0_ISR(void)
{
switch(__even_in_range(UCB0IV,12))
{
case 0: break; // Vector 0: No interrupts
case 2: break; // Vector 2: ALIFG
case 4:
P3OUT |=LED7;
a=1;
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
break; // Vector 4: NACKIFG
case 6: break; // Vector 6: STTIFG
case 8:
break; // Vector 8: STPIFG
case 10:
for (i=0; i<2; i++)
{
if(i==0)
Temp= UCB0RXBUF<<8;
UCB0CTL1 |= UCTXSTP;
if(i==1)
Temp |= UCB0RXBUF;
}
while(UCB0CTL1 & UCTXSTP);
printf("Hello world %d", Temp);
__bic_SR_register_on_exit(LPM0_bits);
break; // Vector 10: RXIFG
case 12:
// Vector 12: TXIFG
if (TXByteCtr) // Check TX byte counter
{
UCB0TXBUF = TXData;
while(!(UCB0IFG&UCTXIFG)); // code stucks here
TXByteCtr--;
P3OUT |=LED6;// Decrement TX byte counter
}
else
{
UCB0IFG &= ~UCTXIFG; // Clear USCI_B0 TX int flag
b=1;
__bic_SR_register_on_exit(LPM0_bits); // Exit LPM0
}
break;
default: break;
}
}