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.

Compiler/MSP-EXP432P401R: MSP-EXP432P401R

Part Number: MSP-EXP432P401R


Tool/software: TI C/C++ Compiler

Recently I have purchased the MSP-EXP432P401R (Red Board). I am attempting to code a program that enables random variables. I have one semester of experience using the MSP-432 which wasn't very helpful in the since that the labs weren't too rigorous. I simply want to have random variables to mimic the rapid change of human glucose. This is some code I have started off the top of the head, as I cannot find any examples of coding using this board. Just need a lemon, and i assure you I can make the lemonade!

* main.c
*/

int x_arr[10]={74,120,60,180,300,250,170,190,55,100,175,245,145}; //an array of random values of gluclose
int main(void)

{
for(i=1; i<14; i++) //for loop chooses value at random from initial array

{
output=x_arr[i]; //outputs values in array


WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD; // stop watchdog timer
}

 

  • You don't have matching braces {} It should look like this:

    main()
    {
    for()
    {
    } // end for
    } //end main

    You only need to stop the watchdog once right after main.

    You set aside an array to hold 10 elements, but you stuff it with 13.

    Arrays in C are zero based, this ain't no stinking MATLAB!

    The correct for idiom to step through an array of 13 elements is:

    for(i=0; i<13; i++)
    {}
  • Jahleel,

    As far as Keith's answer, his is accurate. As far as code examples, please go here: dev.ti.com/.../

    You would likely benefit from DriverLib or Register Level examples as you don't seem to be wanting to use an RTOS.
  • Thanks , so....

    int main(void)
    WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD;//stop watchdog

    int x_arr[10]={74,120,60,180,300,250,170,190,55,100,175,245,145}; //an array of random values of gluclose

    {
    for(i=0; i<13; i++) //for loop chooses value at random from initial array

    {
    output=x_arr[i]; //outputs values in array
    }//end for loop
    }//end main

    I have this code now the error is #176-D which states expression has no effect. This is line 13 the highlighted line as shown above. I'm assuming none of my values are being read before the for loop?

  • Jahleel, your array int x_arr[10], you've defined to have 10 variables stored in it. However, you try to assign 13 variables.
  • Evan this did no resolve my issue as the variables still have no affect on my code i.e the error message "../main.c", line 14: warning #176-D: expression has no effect" appearing 14 times.
  • Jahleel,

    I'm not really sure if you have anything else around your code that you're providing, but you've not intialized the variables i and output either. You were also missing an open bracket on main. 

    Please see the attached code.

    #include "msp.h"
    
    
    /**
     * main.c
     */
    int main(void){
    
        WDT_A->CTL = WDT_A_CTL_PW | WDT_A_CTL_HOLD;//stop watchdog
    
        int x_arr[13]={74,120,60,180,300,250,170,190,55,100,175,245,145}; //an array of random values of gluclose
        int output[13];
        int i;
    
        for(i=0; i<13; i++) //for loop chooses value at random from initial array
        {
            output[i]=x_arr[i]; //outputs values in array
        }//end for loop
    }//end main
    

    This code receives no errors, only one warning and the warning is because output is never used. I'm going to close this post for now as I believe this is resolved. 

**Attention** This is a public forum