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.

MSP430F5529: Port configuartion for soil moisture sensor and LCD

Part Number: MSP430F5529

Hi 

so lately I have purchased an MSP430 board for a school project which soil moisture monitoring system. I did a little search on google to find a way of configuring the ports for both LCD and soil moisture but I end up with nothing. 

however, I found this guy here on youtube, he provided the code, but I really need someone to provide me port configuration and diagram, I need to do this project asap before the deadline. 

this is the code : [For clarity, TI moved the source code to an attachment]

soil_moisture_port_configuration.c
#include <msp430.h>
#include "MSP430_LCD.h"

void readMoisture();

int main(void)
{
WDTCTL = WDTPW + WDTHOLD;              
P2DIR &= ~BIT1;
P2IFG &= ~BIT1;
P2IE |= BIT1;
P2IES |= BIT1;
P2DIR |= BIT2;
P2OUT |= BIT2;
ADC10CTL0 = ADC10SHT_2 + ADC10ON;   
ADC10CTL1 = INCH_7;                
ADC10AE0 |= 0x80;                  
P1DIR |= 0x3F;                        

initLCD();

clearLCD();

for (;;)
{
   ADC10CTL0 |= ENC + ADC10SC;      

   gotoxy(1,1);

   sendString(" MOISTURE VALUE");

   gotoxy(1,2);

   sendString("     PERCENT");

   readMoisture();

   if( ( P2IN & BIT0 ) == 0 ){

      P2OUT &= ~BIT2;

      _bis_SR_register( LPM4_bits | GIE );
   }

   _delay_cycles(500000);
}

}

void readMoisture(){
              if (ADC10MEM <= 0x01B8)
              {
                     gotoxy(2,2);
             sendString(" 100");
              }
          else if (0x01B9 <=ADC10MEM && ADC10MEM <= 0x01D7)
          {
             gotoxy(2,2);
             sendString(" 90") ;
          }
          else if (0x01D8 <=ADC10MEM && ADC10MEM <= 0x01F6)
          {
             gotoxy(2,2);
             sendString(" 85") ;

          }
          else if (0x01F7 <=ADC10MEM && ADC10MEM <= 0x0215)
          {
             gotoxy(2,2);
             sendString(" 80") ;
          }
          else if (0x0216 <=ADC10MEM && ADC10MEM <= 0x0234)
          {
             gotoxy(2,2);
             sendString(" 75") ;
          }
          else if (0x0235 <=ADC10MEM && ADC10MEM <= 0x0253)
          {
             gotoxy(2,2);
             sendString(" 70") ;
          }
          else if (0x0254 <=ADC10MEM && ADC10MEM <= 0x0272)
          {
             gotoxy(2,2);
             sendString(" 65") ;
          }
          else if (0x0273 <=ADC10MEM && ADC10MEM <= 0x0291)
          {
             gotoxy(2,2);
             sendString(" 60") ;
          }
          else if (0x0292 <=ADC10MEM && ADC10MEM <= 0x02B0)
          {
             gotoxy(2,2);
             sendString(" 55") ;
          }
          else if (0x02B1 <=ADC10MEM && ADC10MEM <= 0x02CF)
          {
             gotoxy(2,2);
             sendString(" 50") ;
          }
          else if (0x02D0 <=ADC10MEM && ADC10MEM <= 0x02EE)
          {
             gotoxy(2,2);
             sendString(" 45") ;
          }
          else if (0x02EF <=ADC10MEM && ADC10MEM <= 0x030D)
          {
             gotoxy(2,2);
             sendString(" 40") ;
          }
          else if (0x030E <=ADC10MEM && ADC10MEM <= 0x032C)
          {
             gotoxy(2,2);
             sendString(" 35") ;
          }
          else if (0x032D <=ADC10MEM && ADC10MEM <= 0x034B)
          {
             gotoxy(2,2);
             sendString(" 30") ;
          }
          else if (0x034C <=ADC10MEM && ADC10MEM <= 0x036A)
          {
             gotoxy(2,2);
             sendString(" 25") ;
          }
          else if (0x036B <=ADC10MEM && ADC10MEM <= 0x0389)
          {
             gotoxy(2,2);
             sendString(" 20") ;
          }
          else if (0x038A <=ADC10MEM && ADC10MEM <= 0x03A8)
          {
             gotoxy(2,2);
             sendString(" 15") ;
          }
          else if (0x03A9 <=ADC10MEM && ADC10MEM <= 0x03C7)
          {
             gotoxy(2,2);
             sendString(" 10") ;
          }
          else if (0x03C8 <=ADC10MEM && ADC10MEM <= 0x03E6)
          {
             gotoxy(2,2);
             sendString(" 05") ;
          }
          else if (0x03E7 <= ADC10MEM)
          {
             gotoxy(2,2);
             sendString(" 00") ;
          }
}

#pragma vector = PORT2_VECTOR

__interrupt void port2( void ){

       _bic_SR_register_on_exit( LPM4_bits | GIE );

       P2IFG &= ~BIT1;

       P2OUT |= BIT2;
}

//LCD Codes

#include "MSP430.h"

#include "MSP430_LCD.h"

void resetLCD(){

       P1OUT |= 0x0F;

       busyLCD();

       P1OUT |= 0x03;

       enbLCD();

       selectRegister(0);

       busyLCD();

       P1OUT |= 0x03;

       selectRegister(0);

       enbLCD();

       busyLCD();

       P1OUT |= 0x03;

       selectRegister(0);

       enbLCD();

       busyLCD();

       P1OUT |= 0x02;

       selectRegister(0);

       enbLCD();

       busyLCD();

}

void initLCD(){

       resetLCD();

       sendCommand(0x28);

       sendCommand(0x0C);

       sendCommand(0x06);

       sendCommand(0x80);

       sendCommand(0x01);
}

void busyLCD(){

       volatile unsigned int i;

       i=0;

                     while(i<500)

                           i++;

}

void enbLCD(){

       P1OUT |= 0x20;

       P1OUT &= ~0x20;

}

void selectRegister(int i){

       if(i==1)

              P1OUT |= 0x10;

       else

              P1OUT &= ~0x10;

}

void gotoxy(int x, int y){

       if(y==1)

       sendCommand(0x80+(x-1));

       else

       sendCommand(0xC0+(x-1));

}

void clearLCD(){
       sendCommand(0x01);
}

void sendCommand(unsigned char cmd){

       P1OUT = 0x00;

       P1OUT |= ((cmd >> 4) & 0x0F);

       selectRegister(0);

       enbLCD();

       P1OUT = 0x00;

       P1OUT |= (cmd & 0x0F);

       selectRegister(0);

       enbLCD();

       busyLCD();

       busyLCD();

}

 

void sendData(unsigned char data){

       P1OUT = 0x00;

       P1OUT |= ((data >> 4) & 0X0F);

       selectRegister(1);

       enbLCD();

       P1OUT = 0x00;

       P1OUT |= (data & 0x0F);

       selectRegister(1);

       enbLCD();
}

void sendString(char* str){

       while(*str)

              sendData(*str++);

}

// LCD Header Files

void initLCD();

void busyLCD();

void resetLCD();

void enbLCD();

void sendCommand(unsigned char);

void selectRegister(int);

void sendData(unsigned char);

void sendString(char*);

void gotoxy(int, int);

void clearLCD();


I will be thankful if you could provide me with port configuration alongside a brief explanation of the code 

 

  • Hi Mark,

    Which MSP430 board do you have?

  • Dennis Lehman said:

    Hi Mark,

    Which MSP430 board do you have?

    I have MSP430F5529 board 

  • I am wating for a reply, it an urgent project 

    I will appreciate any help 

  • Hi Mark,

    So you didn't write this code, but you want me to go through it and explain how it works and show you how to make this work on a MSP430F5529 launchpad?

  • Yes that's right

  • Hi Mark,

    First, after reviewing this author's code, I don't believe this it was written for the MSP430F5529LP.

    The first reason is the LCD code.   I thought he might be using the Sharp LCD Booster pack, but it appears he is using Port1 to load the LCD with 4-bit parallel data.  So I can't do much for you there.  Do you have an LCD?

    The second reason is he is using P2.2 turn on, I'm guessing, an LED, but on the 5529LP this pin only goes to the boosterpack header.

    The third reason he is using P6.7 (A7) for the ADC channel to measure his sensor.  That pin does not go to boosterback header.  P6.6 (A6) does so if you want to connect your sensor to that pin that makes it convenient.

    Anyway, here is a summary of the startup configuration.  Looks like after configuring the ports and ADC he puts the MSP into low power mode. He configured P2.1 (S1) to wake the MSP from LPM4 when pressed.

    And I do believe there is a bug in his code regarding the S1 button and it's assigned IO pin.

    From what I can tell, it looks like the code will continue to loop taking sensor measurements until S1 is pressed.  When pressed the MSP will enter low power mode LPM4.

    When S1 is pressed again, the MSP wakes from LPM4 and continues in the loop taking sensor measurements until S1 is pressed again.  Note the long delay coming out of LPM4 mode.  I believe this allows time for the user to remove their finger from the button else the code will re-enter LPM4 after taking a sensor measurement.

  • Hi Mark,

    I haven’t heard from you for a couple of days now, so I’m assuming you were able to resolve your issue.
    If this isn’t the case, please click the "This did NOT resolve my issue" button and reply to this thread with more information.
    If this thread locks, please click the "Ask a related question" button and in the new thread describe the current status of your issue and any additional details you may have to assist us in helping to solve your issues.

**Attention** This is a public forum