Jump to content
43oh

ilpaso

Members
  • Content Count

    25
  • Joined

  • Last visited

Reputation Activity

  1. Like
    ilpaso reacted to grahamf72 in low power mode first sketch   
    A basic sketch could look something like the following:
    void setup() { pinMode(P1_3,INPUT_PULLUP); //Enable inputs on P1_3 (onboard button) pinMode(P1_0,OUTPUT); //Enable output on P1_0 (onboard red LED) attachInterrupt(P1_3,Interrupt, FALLING); //attach our interrupt routine to P1_3 } void loop() { LPM4; //whenever the loop runs, switch back into LPM4 //we could put code here that would run after every Interrupt - see warning in text. } void Interrupt(void) //Our interrupt routine { digitalWrite(P1_0,!digitalRead(P1_0)); //toggle the red LED };   The above code will toggle the onboard red LED everytime the button is pressed.
     
    The code goes through the normal setup routine, which is pretty self explanatory. When it goes into the loop the first thing it gets is the command to switch to Low Power Mode 4. The processor now goes into a deep sleep until an interrupt occurs.  When you press the button, the processor wakes up and executes the code in the Interrupt() function - in this case just toggling the red led.  After the interrupt finishes, the processor should go back into sleep, however Energia has a timer that handles things like millis() that also wakes up with the return from the interrupt. This timer calls an interrupt, which leaves the processor running when it finishes. The processor will continue to run from the next command after LPM4 in loop(). In the above example, there is no more code, so loop() will start again, it gets to the LPM4 instruction and goes to sleep.
     
     
    If you will be using low power modes, I recommend going into the Energia "cores" folder, finding the file WInterrupts.c, and adding the command "LPM4_EXIT;" to the end of each of the interrupt handlers in that file. This will guarantee that the processor will always be left in the "awake" state after an interrupt runs, and doesn't make it dependent on Energia's timer. Without this change, if for some reason Energia's timer was stopped when you go into LPM4, there is no way to leave the processor awake after an interrupt.
     
    To minimize current consumption, you should also configure any unused pins as INPUT_PULLDOWN.  From the tests I have done, configuring all pins to INPUT_PULLDOWN will reduce current to below 0.1uA (on my meter it flickers between 0 and 0.1). Configuring unused pins to INPUT_PULLUP or OUTPUT will result in the meter showing a consistent 0.1uA, while leaving the pins at their default (equivalent to INPUT) resulted in random current consumption in the 200-500uA range.
  2. Like
    ilpaso reacted to semicolo in how read the battery voltage   
    I was just making a quick test. Something like this should do the same as your code and be easier to read than working with the MSP430 registers:
    #define ANALOG_HALFVCC_INPUT 11 void setup() { Serial.begin(9600); // msp430g2231 must use 4800 } // returns VCC in millivolts int getVCC() { // start with the 1.5V internal reference analogReference(INTERNAL1V5); int data = analogRead(ANALOG_HALFVCC_INPUT); // if overflow, VCC is > 3V, switch to the 2.5V reference if (data==0x3ff) { analogReference(INTERNAL2V5); data = (int)map(analogRead(ANALOG_HALFVCC_INPUT), 0, 1023, 0, 5000); } else { data = (int)map(data, 0, 1023, 0, 3000); } return data; } void loop() { Serial.print("VCC value:"); int data = getVCC(); Serial.println (data); delay(1000); } Would be nice to have a standard constant for reading VCC
  3. Like
    ilpaso reacted to Rei Vilo in I2C with Magnetometer HMC5883L   
    Does it works with Arduino?
     
    Do you have a logic analyser to trace the signals?
     
    I've experienced issues with some I2C devices due to weak signal when using the 3.3V MSP430G2553. Using a lower than 10k? could improve signal.
     
    HMC5883L specification sheet mentions 2.2k? pull-up resistors.
×
×
  • Create New...