Thread: C MSP430 programming question

  1. #1
    Registered User
    Join Date
    Oct 2012
    Posts
    3

    C MSP430 programming question

    Hi guys,

    I have been given a msp430 chip with a main.c and utility.h files to program for an assignment using C. I am new to C and we have only had one lecture on C Strings and the rest of the course has been on C++.

    Just wondering if any body is able to give any help programming the main.c file in the commented fields, seeing as my lecturer isn't much.


    The main.c and utility.h can be found in the attachment.

    Attached Files Attached Files

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    What does this
    Code:
             /*----------------------------------------------------
             Include your code here to collect bytes into a string
             check the string against a protocol string
             Extract a device number if appropriate.
             call the appropriate function with parameters
             interpret the function return value.
             assemble and send the appropriate response string 
             as specified in the protocol
             -------------------------------------------------*/
    Have to do with this
    Code:
       // Include your code to
       // validate correct P1.n numbers for LEDs, it is written on the circuit board
       // set the port direction for the ports (without overwriting values of other ports)
       // hint, uses logical operator on binary number, (in hex)
       // set the appropriate port to on without overwiting states of other ports)
       // return 1 for success, 0 for failure (invalid port No)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Welcome to the forum, tj!

    That's what we do! What we won't do is start your program for you, or code up huge parts of it. We will help, but you need to show what you're having a problem with, and tell us what you know about it. The more specific your question and descriptions are, the more specific our answers can be.

    General requests for "Help" are not usually specific enough to be helpful.

  4. #4
    Registered User
    Join Date
    Oct 2012
    Posts
    3
    @Salem.

    I first have to collect bytes into a string then compare that string to see if it is equal to the correct function call LEDon or LEDoff. For example if you where to type LEDon it would turn the led on, on the msp430.

  5. #5
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    OK, so where is your effort?

    Remember, almost no one else here has an MSP430 to play with, so all the actual development and testing has to be done by you.

    Code:
    #include <stdio.h>
    int main ( ) {
      int RXByte;
      char buffer[10];
      int bufPos;
      bufPos=0;
      while ( (RXByte=getchar() ) != '\n' ) {
             /*----------------------------------------------------
             Include your code here to collect bytes into a string
             check the string against a protocol string
             Extract a device number if appropriate.
             call the appropriate function with parameters
             interpret the function return value.
             assemble and send the appropriate response string 
             as specified in the protocol
             -------------------------------------------------*/
      }
    }
    
       int ledon(int x)
       {
            printf("ledon(%d) called\n", x);
       // Include your code to
       // validate correct P1.n numbers for LEDs, it is written on the circuit board
       // set the port direction for the ports (without overwriting values of other ports)
       // hint, uses logical operator on binary number, (in hex)
       // set the appropriate port to on without overwiting states of other ports)
       // return 1 for success, 0 for failure (invalid port No)
       
       }
    //----------------LED OFF --
       int ledoff(int x)
       {
            printf("ledoff(%d) called\n", x);
       // Include your code to
       // validate correct P1.n numbers for LEDs, it is written on the circuit board
       // set the port direction for the ports (without overwriting values of other ports)
       // hint, uses logical operator on binary number, (in hex)
       // set the appropriate port to off without overwiting states of other ports)
       // return 1 for success, 0 for failure (invalid port No)
       }
    Without having to load any code onto your target board, can you make any headway at all using your desktop compiler, and a simple command line program?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  6. #6
    Registered User
    Join Date
    Oct 2012
    Posts
    3
    @Salem

    This is what I have attempted so far.

    Code:
     // -- Declare an array of char here to store command string, and an int to record char pos in string
          char buffer[10];
          int bufPos;
          bufPos=0;
          int r=0;
          
          int strcmp(const char *a, const char *b);
          
          char s1[] = "LONx";
          char s2[] = "LOFFx";
          char s3[] = "GETTEMP";
          char s4[] = "PONx";
          char s5[] = "POFFx";
       
          while(1)
          {
             if (hasReceived)    // If the device has received a value
             {
                hasReceived = false; // Clear the flag
                if (RXByte != '\r')
                {
                  buffer[bufPos]=RXByte;
                  bufPos++;
                }
                else
                {
                  buffer[bufPos]= '\0';
                 //  bufPos=0;
                
                for (int n=0;n<bufPos;n++)
                {
                TXByte = buffer[n]; //-- echo byte for testing. 
                Transmit();  
                } 
               bufPos=0;
              
    };

  7. #7
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > This is what I have attempted so far.
    And what are your results so far (what you expected, and what you got)?

    Don't forget you have this in your header file.
    Code:
    //------------------------ Write string of length len to serial port --
    void writeString(char * data, int len){
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 14
    Last Post: 02-19-2012, 02:24 AM
  2. Total newb to programming here... Question about the many programming languages. Ty!
    By tsubotakid1 in forum A Brief History of Cprogramming.com
    Replies: 11
    Last Post: 10-05-2003, 10:32 AM
  3. a question about programming?
    By wymin in forum C Programming
    Replies: 4
    Last Post: 08-11-2002, 09:09 AM
  4. Programming question
    By face_master in forum C++ Programming
    Replies: 1
    Last Post: 08-26-2001, 07:00 AM

Tags for this Thread