This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP-EXP430F5529LP: 2 programs running at once

Part Number: MSP-EXP430F5529LP
Other Parts Discussed in Thread: ENERGIA, MSPM0G3507

Tool/software:

Hi. I'm trying to have 2 different programs run at the same time. One Basic Blink and the other Basic DigitalReadSerial using the onboard Push Button on the MSP. These aren't the 2 programs I intend to use for the MSP however I just want 2 small easy test codes to quickly test on how to have 2 programs work together before sending it my main code. Can somebody help me with running these 2 codes at the same time? The codes are here:

Blink:

#define LED RED_LED

void setup() {
pinMode(LED, OUTPUT);
}
void loop() {
digitalWrite(LED, HIGH);
delay(1000); 
digitalWrite(LED, LOW); 
delay(1000); /
}

DigitalReadSerial:

int pushButton = P2_1;

void setup() {
Serial.begin(9600);
pinMode(pushButton, INPUT_PULLUP);
}

void loop() {
int buttonState = digitalRead(pushButton);
Serial.println(buttonState);
delay(1);
}

Like I said they are both very simple codes but just want them to figure out how to have 2 seperate codes function at the same time before trying it with my main codes.

If you can help me that would be amazing! Thank you.

  • They can't of course run at the same time. But you can manage them so one runs while the other waits. The classic way to do that is with an RTOS. Very different from that Arduino shaped stuff and requires learning a lot. For example, here is a simple LED blink task from one of my FreeRTOS based programs:

    Fullscreen
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    void prvLEDTask( void *pvParameters)
    {
    TickType_t xNextWakeTime;
    /* Remove compiler warning about unused parameter. */
    ( void ) pvParameters;
    /* Initialise xNextWakeTime - this only needs to be done once. */
    xNextWakeTime = xTaskGetTickCount();
    for( ;; )
    {
    /* Place this task in the blocked state until it is time to run again. */
    vTaskDelayUntil( &xNextWakeTime, (TickType_t)(configTICK_RATE_HZ*0.95));
    LED1_ON;
    vTaskDelayUntil( &xNextWakeTime, (TickType_t)(configTICK_RATE_HZ*0.05));
    LED1_OFF;
    }
    }
    XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

  • So if lets just say the first code is to have the RED_LED to turn on for around 2 seconds and the second code is just to turn on the GREEN_LED for 5 seconds (just as indicators of which code is currently active) what would that code look like? Also I'm using the energia app not CCS because I'm more farmiliar with Arduinos and C++ so the format is the same as Arduino  so how would this fit into the Arduino C++ format? I'm not that farmiliar with C or C sharp

  • Energia is for all intents and purposes Arduino.

    This *won't* work on Energia.

    FreeRTOS is a multitasking OS that allows for context switching. You only have one CPU, so you can still only run one at a time, but like on a PC, you can switch between both tasks to make it look like both are running at the same time.

    I don't know if there is an RTOS available for your MCU, you might need a more powerful one like the MSPM0G3507.

    Unless you have a strong use case for an rtos, I suggest you just juggle things in loop, the arduino way.

  • So this task that I'm trying to run, how would that look on C or C sharp because like I said I don't really know either. The 2 codes are quite literally just these 2 LEDs , they are just indicators to us which code is in use. Using the onboard Red and Green LEDs we just know which code is active so its not just 2 different actions its which function() is active. So mixing what said above, how would that work with the LEDs? Because I tried to digitalWrite LEDs and it obviously didn't work

  • Just like David showed above, which is C. You set up two tasks and have them wait until it is time to do something.

    If you are really more comfortable with Energia, I suggest you simply use that:

    Loop()

    {

      // Do stuff for program 1

      // Do stuff for program 2

    }

  • I'm more farmiliar with Arduinos and C++

    C++ is just C plus some new stuff, hence the name. Plus, the code you have shown is plain C.

    Multitasking is something that can and has been done in the Arduino way. Just search for it.

**Attention** This is a public forum