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.

CCSTUDIO: msp430

Part Number: CCSTUDIO

Hi Team,

Greetings! Our customer have modified some code that is supposed to send the result of something to the serial port 640 times, what is read with putty. But upon loading the code, it only sends 5 times. 

Please see the attached code here 

main.c

Looking forward to your response. Thank you. 

Best regards,

Jonathan

  • Hi Jonathan,

    I will respond within 24hrs.

  • Hi Jonathan,

    Can your customer run with a debugger and see where the code is possibly getting hung up?

  • Hi Dennis,

    I regret to inform you that our customer can not find the specific error while running with the debugger. The code is our only information that you may use to find the error. Any idea why loading the code only shows a result that send 5 times instead of 640 times through the serial port?

    If any other information needed please let me know. 

    Thank you and kind regards,

    Jonathan

  • Hello, hope you are fine. here are my update. For my code, the first conversion works and it blocks when MSP430 returns to "sleep mode" the second time. Here is the new code with improvement. And i apologize, i am beginner so there some notion i don't master yet.

    #include <msp430.h> 
    #include <stdio.h>
    
    
    #define V24                      24
    #define R408                     10000
    #define R418                     1500
    #define R409                     475
    #define R412                     15000
    
    #define ADC_V24                  BIT0
    #define ADC_PIXELS               BIT3
    #define ADC_PIXELS_INCH          INCH_3
    
    
    
    #define RDX                      BIT1
    #define TDX                      BIT2
    #define PUSH_BUTTON_2            BIT3
    #define TPH_N_LATCH_3V3          BIT4
    #define TPH_DATA_IN_3V3          BIT5
    #define TPH_CLOCK_3V3            BIT6
    #define TPH_OE_3V3               BIT7
    
    void Configure_ADC(void);
    void Configure_UART(void);
    void decimal_to_hexa(int nombre, int* tableau);
    void hexa_to_ascii(int* tableau);
    unsigned long diviseur;
    unsigned long VR;
    unsigned long R;
    unsigned int echantillon[10];
    unsigned long Moyenne = 0;
    unsigned int i;
    unsigned int NumPixels;
    /**
    * main.c
    */
    int main(void)
    {
           WDTCTL = WDTPW | WDTHOLD; // stop watchdog timer
           DCOCTL = 0; // Select lowest DCOx and MODx settings<
           BCSCTL1 = CALBC1_1MHZ; // Set DCO
           DCOCTL = CALDCO_1MHZ;
    
    
    
           // CONFIGURER LES PORTS INUTILISES EN INPUT/PULL UP
           P1DIR  &=  ~(BIT4 | BIT5 );
           P1REN  |=  BIT4 | BIT5 ;
           P1OUT  |=  BIT4 | BIT5 ;
    
           P2DIR  &=  ~(BIT0 | BIT1 |BIT2);
           P2REN  |=  BIT0 | BIT1 |BIT2 ;
           P2OUT  |=  BIT0 | BIT1 |BIT2 ;
    
           //CONFIGURER ADC ET UART
    
           Configure_ADC();
           Configure_UART();
    
           // ACTIVER LES FONCTIONS ADC ET UART
    
           P1SEL  |= RDX | TDX;
           P1SEL2 |= RDX | TDX;
           UCA0CTL1 &= ~UCSWRST ;
    
           ADC10AE0 |= ADC_V24 | ADC_PIXELS;
    
           //CONFIGURER LES I/O DE LA CARTE
    
           P2DIR |=  TPH_N_LATCH_3V3 | TPH_DATA_IN_3V3  ;
           P2DIR &=  ~PUSH_BUTTON_2;
    
           P1DIR |= TPH_CLOCK_3V3 | TPH_OE_3V3;
    
           //INITIALISATION DES SIGNAUX TPH_N_LATCH_3V3 TPH_DATA_IN_3V3 TPH_CLOCK_3V3 TPH_OE_3V3
    
           P2OUT &=  ~TPH_DATA_IN_3V3 ;
           P1OUT &=  ~(TPH_CLOCK_3V3 | TPH_OE_3V3 );
           P2OUT |=  TPH_N_LATCH_3V3;
    
           //EFFACER TOUS LES REGISTRES AU DEBUT
    
           /*for (i = 5; i > 0; i--)
           {
              P1OUT |= TPH_CLOCK_3V3;
              for(i =  1; i > 0; i--)
              P1OUT &=  ~TPH_CLOCK_3V3;
           }*/
    
          P2OUT |= TPH_DATA_IN_3V3;
    
          for(NumPixels =640; NumPixels>0; NumPixels-- )
          {
          P1OUT |= TPH_CLOCK_3V3;
          for(i =  1; i > 0; i--){}
          P1OUT &=  ~TPH_CLOCK_3V3;
          P2OUT &=  ~TPH_DATA_IN_3V3;
    
    
          P2OUT &= ~TPH_N_LATCH_3V3;
          for(i =  1; i > 0; i--){}
          P2OUT |=  TPH_N_LATCH_3V3;
    
    
          P1OUT |= TPH_OE_3V3;
          for(i =  1; i > 0; i--){}
          ADC10CTL0 |= ENC + ADC10SC; //START CONVERSION
          _BIS_SR(LPM0_bits + GIE);
    
          Moyenne =0;
          for( i = 0; i<10; i++)
          {
          Moyenne += echantillon[i];
    
          }
          Moyenne = (Moyenne + (10/2)) / 10;
    
                      VR = (Moyenne * (R409 + R412));
                      VR = (VR + (1024/2)) / 1024;
                      VR = (VR *33);
                      VR = VR/10;
                      VR = (VR *10000) / R412;
                      R= R418* VR;
    
                      diviseur = VR * (R408 + R418);
                      diviseur = diviseur / (unsigned int) 10000;
                      diviseur = ((unsigned long)V24 * R418) - diviseur;
                      R = (R + diviseur/2)/ diviseur;
    
    
          int tableau[4];
          decimal_to_hexa(R, tableau);
          hexa_to_ascii(tableau);
          for(i= 0; i<4; i++)
          {
              while (!(IFG2 & UCA0TXIFG));
              UCA0TXBUF = tableau[i] ;
          }
          while (!(IFG2 & UCA0TXIFG));
          UCA0TXBUF = '\r';
          while (!(IFG2 & UCA0TXIFG));
          UCA0TXBUF = '\n';
          P1OUT &=  ~TPH_OE_3V3;
          }
    
    }
    
    void Configure_ADC(void)
    {
        ADC10CTL0 |= SREF_0  + ADC10SHT_0 + MSC + ADC10ON + ADC10IE ; // REF VCC, 4X ADCCLK , ACTIVER LE MODULE, PERMETTRE LES INTERRUPTIONS
        ADC10CTL1 |= ADC_PIXELS_INCH + SHS_0 + ADC10SSEL_0 + CONSEQ_2 ; // PIN3,
        ADC10DTC1  = 10;
        while(ADC10CTL1 & ADC10BUSY)
                {};
        ADC10SA = (int)echantillon;
    
    }
    
    
    void Configure_UART(void)
    {
        UCA0CTL1 |= UCSSEL_2 + UCSWRST ;// SMCLK ET RESET
    
        //BAUD RATE POUR 9600
        UCA0BR0 =104;
        UCA0BR1 = 0;
        UCA0MCTL = UCBRS_1;
    
        //PERMETTRE LES INTERRUPTIONS
        //IE2 |= UCA0TXIE ;
    }
    
    void decimal_to_hexa(int nombre, int* tableau)
    {
      int reste;
      for ( i = 0; i < 4; i ++)
      {
          reste = (nombre % 16);
          tableau[3 - i] = reste;
          nombre = (nombre - reste) / 16;
      }
    }
    
    //Cette fonction converti le tableau des bits de l'�criture hexa decimale
    //en tableau de bits ascii
    void hexa_to_ascii(int* tableau)
    {
        for (i = 0; i < 4; i ++)
        {
            if (tableau[i] < 10)
            {
                tableau[i] = tableau[i] + 48;
            }
            else
            {
                tableau[i] = tableau[i] + 55;
            }
        }
    }
    
    
    
    #pragma vector=ADC10_VECTOR
    __interrupt void ADC10_ISR (void)
    {
              __bic_SR_register_on_exit(CPUOFF);
    
            }
    
    
    
    
    
    

  • Hello Megane,

    I think the problem here is you need to enable continuous data transfer. ADC10DTC0  |= ADC10CT;

    Here is what I would use to configure the ADC:

        ADC10CTL0 |= SREF_0  + ADC10SHT_2 + MSC + ADC10ON + ADC10IE ; // REF VCC, 4X ADCCLK , ACTIVER LE MODULE, PERMETTRE LES INTERRUPTIONS
        ADC10CTL1 |= ADC_PIXELS_INCH + SHS_0 + ADC10SSEL_0 + CONSEQ_2 ; // PIN3,
        ADC10AE0 = 3;
        ADC10DTC0 = ADC10CT;
        ADC10DTC1  = 10;
        ADC10SA = (int)echantillon;

    Next, since you are using single channel repeat scan you need to start a conversion inside your while loop.

    I would suggest simplifying your code to look like this:

    ADC10CTL0 |= ENC + ADC10SC; //START CONVERSION  // Start ADC here once, only

          for(NumPixels =640; NumPixels>0; NumPixels-- )
          {

              _BIS_SR(LPM0_bits + GIE);
              _no_operation();
              _no_operation();  // for debugger - you can remove this

              // Process data here after 10 scans have been made
          }

    Make these changes and let me know if it is working.

  • It's been a few days since I have heard from you 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.

  • Part Number: CCSTUDIO

    Hello, I come to thank you first for your answer. I tried it but it didn't really solve my problem. But I did something that eventually worked, I added these three lines of code before each conversion to allow the storage address to be re-specified.

    ADC10CTL0 &= ~ENC; // reset pour une nouvelle convertion, celsa permet de mettre le bit ADC10BUSY à 0
    while(ADC10CTL1 & ADC10BUSY){} // Attendre que ADC10BUSY soit à 0 avant de poursuivre
    ADC10SA = (int)echantillon;
  • Hello Megane,

    I'm glad you were able to get this working.  Do you need any further assistance?