Hi all ! I'm doing "energy harvester" with wireless sensor node that includes msp430g2553 MCU. Trying to measure power consumtion, but no do not go for now. Using shunt resistor (1k 5%) i have got 345uA for active and 320uA for LPM3 mode. I thout that is something wrong here. Measured using multimeter - got almost the same results - 319uA for LMP3 mode ! Do not understand...It means that MCU do not go sleep ? Testing algorythm is : waiting for button press, then send some data using UART (150 in my code), after that go to sleep (LPM3) and wake up when UART RX or P1 BIT4 interrupt occures. Now everything is acting as is should, only current consumtion is very high in LPM3. Maybe someone can find mistake in my code (sorry for my language comments and variables in the code ) . Thanks !
#include <stdio.h>
#include "serial.h"
#define LED0 BIT0
#define LED1 BIT6
#define RXD 0x02
#define TXD 0x04
#define MYGTUKAS 0x08
volatile unsigned int skaitliukas=5, leisti=0,miegoti=0;
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
uart_init(); //is header failo
P1DIR &=~MYGTUKAS; // Mygtukas kaip įėjimas BUTTON as INPUT
P1OUT |= MYGTUKAS;
P1REN |= MYGTUKAS; // Enables pullup resistor on button
P1DIR |= LED0;
P1DIR |= LED1;
P1OUT &= ~LED0; //pradine busena - off
P1OUT &= ~LED1;
P1IE |= BIT4; // igaliname P1.4 pertraukti interrupt fot P1 BIT4
UC0IE |= UCA0RXIE; // Enable USCI_A0 RX interrupt
__enable_interrupt();
while(1)
{
P1OUT|=LED1; // LED for indicating active mode
if((P1IN & MYGTUKAS)==!MYGTUKAS) { // Was button pressed?
P1OUT ^=LED0 ;
leisti^=0xFF;
__delay_cycles(500000);
}
if (leisti==0xff) //START FLAG
{
//SENT DATA FOR RF MODULE
send_int(9); //duomenu nusistovejimui
__delay_cycles(23000);
send_int(1);
send_int(2);
__delay_cycles(23000);
miegoti++; //counter for sleep mode
}
if (miegoti>=150) { //go to sleep
P1OUT &= ~LED1; //išjungiam LED indikuodami kad miegam LED1 OFF
P1OUT &= ~LED0; //išjungiam LED indikuodami kad miegam LED0 OFF
miegoti=0x00; //clear sleep mode counter
leisti=0x00; //clear start flag
_BIS_SR(LPM3_bits + GIE); // Einame i LPM3 miego rezima Go to LPM3 mode
}
} //while pabaiga
} //main pabaiga
//----------------------------------P1 BIT 4 interrupt -----------------------------------------
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1IFG &= ~BIT4; // P1.4 IFG cleared
P1IES &= ~BIT4; // toggle the interrupt edge,
_BIC_SR(LPM3_EXIT); // Pabusti is miego rezimo LPM3 //WAKE UP
}
//----------------------------------UART RECEIVED interrupt---------------------------------------
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
if (UCA0RXBUF == '1')
{
//for future
}
_BIC_SR(LPM3_EXIT); // Pabusti is miego rezimo LPM3 //WAKE UP
}
//------------------------------UART TX interrupt----------------------------------------
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
//for future
}
#include <stdio.h>
#include "serial.h"
#define LED0 BIT0
#define LED1 BIT6
#define RXD 0x02
#define TXD 0x04
#define MYGTUKAS 0x08
volatile unsigned int skaitliukas=5, leisti=0,miegoti=0;
void main( void )
{
// Stop watchdog timer to prevent time out reset
WDTCTL = WDTPW + WDTHOLD;
uart_init(); //is header failo
P1DIR &=~MYGTUKAS; // Mygtukas kaip įėjimas BUTTON as INPUT
P1OUT |= MYGTUKAS;
P1REN |= MYGTUKAS; // Enables pullup resistor on button
P1DIR |= LED0;
P1DIR |= LED1;
P1OUT &= ~LED0; //pradine busena - off
P1OUT &= ~LED1;
P1IE |= BIT4; // igaliname P1.4 pertraukti interrupt fot P1 BIT4
UC0IE |= UCA0RXIE; // Enable USCI_A0 RX interrupt
__enable_interrupt();
while(1)
{
P1OUT|=LED1; // LED for indicating active mode
if((P1IN & MYGTUKAS)==!MYGTUKAS) { // Was button pressed?
P1OUT ^=LED0 ;
leisti^=0xFF;
__delay_cycles(500000);
}
if (leisti==0xff) //START FLAG
{
//SENT DATA FOR RF MODULE
send_int(9); //duomenu nusistovejimui
__delay_cycles(23000);
send_int(1);
send_int(2);
__delay_cycles(23000);
miegoti++; //counter for sleep mode
}
if (miegoti>=150) { //go to sleep
P1OUT &= ~LED1; //išjungiam LED indikuodami kad miegam LED1 OFF
P1OUT &= ~LED0; //išjungiam LED indikuodami kad miegam LED0 OFF
miegoti=0x00; //clear sleep mode counter
leisti=0x00; //clear start flag
_BIS_SR(LPM3_bits + GIE); // Einame i LPM3 miego rezima Go to LPM3 mode
}
} //while pabaiga
} //main pabaiga
//----------------------------------P1 BIT 4 interrupt -----------------------------------------
#pragma vector=PORT1_VECTOR
__interrupt void Port_1(void)
{
P1IFG &= ~BIT4; // P1.4 IFG cleared
P1IES &= ~BIT4; // toggle the interrupt edge,
_BIC_SR(LPM3_EXIT); // Pabusti is miego rezimo LPM3 //WAKE UP
}
//----------------------------------UART RECEIVED interrupt---------------------------------------
#pragma vector=USCIAB0RX_VECTOR
__interrupt void USCI0RX_ISR(void)
{
if (UCA0RXBUF == '1')
{
//for future
}
_BIC_SR(LPM3_EXIT); // Pabusti is miego rezimo LPM3 //WAKE UP
}
//------------------------------UART TX interrupt----------------------------------------
#pragma vector=USCIAB0TX_VECTOR
__interrupt void USCI0TX_ISR(void)
{
//for future
}