Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

unable to set the interrupt in MSP430

Status
Not open for further replies.

Raghupathikokkarakonda

Newbie level 2
Joined
Apr 26, 2012
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,305
Hi,

I have written the below piece of code for getting the data from a humidity sensor to MSP430F2774.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
//include the controller header
#include "msp430f2274.h"
#include "intrinsics.h"
#include "in430.h"
void delay(void);
 
 
void main(void)
{
      WDTCTL = WDTPW + WDTHOLD;                 // Stop WDT
      P3SEL |= 0x06;                            // Assign I2C pins to USCI_B0
      UCB0CTL1 |= UCSWRST;                      // Enable SW reset
      UCB0CTL0 = UCMODE_3 + UCSYNC + UCMST;     // I2C mode, sync mode
      UCB0I2CSA = 0x27;                         // deafult slave address is 027h
      UCB0CTL1 |= UCSSEL_1 ;
      UCB0BR0 = 2;   
      
      //start the transmission
      UCB0CTL1 &= ~UCSWRST ;          // Clear SW reset, resume operation  
      IE2 |=  UCB0RXIE + UCB0TXIE;   // Enable TX and RX interrupts
      __bis_SR_register(GIE);          // Enable global interrupts
      
      while(1)
      {
          UCB0CTL1 |= UCTR;  //sending the MR to HIH sensor
          UCB0CTL1 |= UCTXSTT;  // start bit is enable 
          while (UCB0CTL1 & UCTXSTT); //in-loop for getting the ACK 
          
          // making master to receive mode:
          UCB0CTL1 &= (~UCTR);
          UCB0CTL1 |= UCTXSTT;  // start bit is enable
                
          while (UCB0CTL1 & UCTXSTT);//waiting the ACK from sensor          
          TXData = UCB0RXBUF;
      }
}
 
 
// USCI_B0 State ISR
#pragma vector = USCIAB0RX_VECTOR  
__interrupt void USCIAB0RX_ISR(void)
{
    TXData = UCB0RXBUF;
    RxFlag=1;
}
 
#pragma vector = USCIAB0TX_VECTOR
__interrupt void USCIAB0TX_ISR(void)
{
    P1DIR = 0x1;
    P1OUT = 0x01;
    delay();
}
 
void delay(void)
{
    P1DIR = 0x01;
    
    unsigned int i = 0;
    while( i<65000 )
    {
                  P1OUT = 0x01;
         i++;
    }
    P1OUT = 0x00;   
}



the execution control is not going inside the interrupt routine.please help me in finding out the bug in the code.

one more help is how to set the clock and baudrate for I2C communication. actually I am using the ACLK,but not able to find ACLK value, hence not able to set the baudrate exactly.
 
Last edited by a moderator:

Hello!

What you are trying to do might be obvious for you, but it's not for an average reader.
At least it's not obvious to me.
So you are trying to communicate in I2C with something, but you don't say what it is
(therefore noone can verify how it works in the sensor documentation).
Your code comments don't allow to understand what you want to do.
TXData does not seem to be defined anywhere. Is it a 2274-specific parameter?
Why do you set it in your while loop and also in the interrupt routine?

If you use a loop and poll for the ACK, then you don't need interrupts.
And if you use interrupts, why not using MSP430's hardware loop? Enable
LPMx (verify which one in the docs) and enter sleep mode with interrupt
enable, that's usually the way to do it.

Beside this, your delay function looks funny. Why constantly assigning 1 to
P1 in your loop? What about assigning it once before the loop and resetting it
after the loop?

Now why setting P1DIR to 1 at various places and at each interrupt and delay?
Since you always set it to 1, it will never change after the first time, so you should
do this in the init phase and never touch it again.

You might want to try Texas Instruments' code. Everything has been tested.
And since many people get stuck with this trick: verify the components address
and try to shift it 1 bit to the left or to the right. Example: if the address is 50, try
A0 or 28.

Dora.

Addendum: if you could post formatted code, it would be more readable.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top