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.

CCS/MSP430G2744: HELP with ARRAY's declaration and usage in CODE COMPOSER STUDIO

Part Number: MSP430G2744


Tool/software: Code Composer Studio

Goodmorning everybody!!

I have a question about the declaration and the use of arrays in Code Composer Studio.

In my code, what I want to do is something like this:

In my header file:

const unsigned int PROGRAMMA_1F[3];
#define SETPOINT_TEMP_VASCA_1F PROGRAMMA_1F[0]
#define SETPOINT_TEMP_CUORE_1F PROGRAMMA_1F[1]
#define TEMPO_LAVORO_1F PROGRAMMA_1F[2]

SETPOINT_TEMP_VASCA_1F= 600;
SETPOINT_TEMP_CUORE_1F= 580;
TEMPO_LAVORO_1F= 300;

But, unfortunately the Code Composer shows me severals arrors like:

#145 a value of type "int" cannot be used to initialize an entity of type "int [0]"

#145 a value of type "int" cannot be used to initialize an entity of type "int [1]"

#145 a value of type "int" cannot be used to initialize an entity of type "int [2]"

#148 declaration is incompatible with "const unsigned int PROGRAMMA_1F[3]" 

#148 declaration is incompatible with "int PROGRAMMA_1F[1]" 

#150 variable "PROGRAMMA_1F" has already been initialized 


I need to have SETPOINT_TEMP_VASCA_1FSETPOINT_TEMP_CUORE_1FTEMPO_LAVORO_1F fixed respectively with the values 600,580,300 because I have to use them in a C function like in this case:

In my C function:

if (BLANCH_CHECK != BLANCH_CHECK_F) {
	switch (counter_prog) {
	case 0: {
		SETPOINT_TEMP_VASCA1=SETPOINT_TEMP_VASCA_1F;
		SETPOINT_TEMP_CUORE1=SETPOINT_TEMP_CUORE_1F;
		TEMPO_LAVORO1=TEMPO_LAVORO_1F;
		} break;
	case 2: {
		SETPOINT_TEMP_VASCA2=SETPOINT_TEMP_VASCA_2F;
		SETPOINT_TEMP_CUORE2=SETPOINT_TEMP_CUORE_2F;
		TEMPO_LAVORO2=TEMPO_LAVORO_2F;
		} break;
	case 3: {
		SETPOINT_TEMP_VASCA3=SETPOINT_TEMP_VASCA_3F;
		SETPOINT_TEMP_CUORE3=SETPOINT_TEMP_CUORE_3F;
		TEMPO_LAVORO3=TEMPO_LAVORO_3F;
		} break;
	}
	}

What's wrong in my code? Is there another-better- way to do what I have to?

Waiting for your answers and advices (which I really appreciate),

Kind Regards

Maria Angela

  • You cannot write ...

    array[0] = 10;

    ... at global scope.  An assignment statement like that can only occur within a function.

    luigi Quaglia said:
    Is there another-better- way to do what I have to?

    You could write this ...

    const unsigned int PROGRAMMA_1F[3] = { 600, 580, 300};
    #define SETPOINT_TEMP_VASCA_1F PROGRAMMA_1F[0]
    #define SETPOINT_TEMP_CUORE_1F PROGRAMMA_1F[1]
    #define TEMPO_LAVORO_1F PROGRAMMA_1F[2]
    
    /* SETPOINT_TEMP_VASCA_2F= 600; */
    /* SETPOINT_TEMP_CUORE_1F= 580; */
    /* TEMPO_LAVORO_1F= 300;        */

    Thanks and regards,

    -George

  • Hi George!

    Ok, I understand and I tried both the solutions you suggested to me.

    But I still have some errors by Code Composer and I really don't know what isn't correct :(

    In my project I have the header file Definizioni_Flash.h:

    /************************************************************************************************************
     * 					Definizioni_FLASH.h
     ***********************************************************************************************************/
     /* Created on: 08 settembre 2017
     *  Author: Maria Angela Cianci
     */
    
    #ifndef DEFINIZIONI_FLASH_H_
    #define DEFINIZIONI_FLASH_H_
    
    /************************************************************************************************************
     * 			Zona della memoria FLASH in cui carico i DEFAULT
     ***********************************************************************************************************/
    /************************************************************************************************************
       *					FLAG ATTIVAZIONI
     ***********************************************************************************************************/
    #define	FLAG_SONDACUORE		0b0000000000000001
    #define FLAG_ATTIVAZIONI_F	0x0000
    
    /************************************************************************************************************
       *					FLAG VISUALIZZAZIONI
     ***********************************************************************************************************/
    #define FLAG_VISUALTEMP 0b0000000000000010
    #define FLAG_VISUALTIME 0b0000000000000100
    #define FLAG_VISUALIZZAZIONI_F 0x0000
    
    #define BLANCH_CHECK_F	0x0000
    
    /************************************************************************************************************
       *				       PROGRAMMI con i DEFAULT
     ***********************************************************************************************************/
    
    const unsigned int PROGRAMMA_1F[3];
    #define	SETPOINT_TEMP_VASCA_1F 	PROGRAMMA_1F[0]
    #define	SETPOINT_TEMP_CUORE_1F	PROGRAMMA_1F[1]
    #define TEMPO_LAVORO_1F		        PROGRAMMA_1F[2]
    
    const unsigned int PROGRAMMA_2F[3];
    #define	SETPOINT_TEMP_VASCA_2F 	PROGRAMMA_2F[0]
    #define	SETPOINT_TEMP_CUORE_2F	PROGRAMMA_2F[1]
    #define TEMPO_LAVORO_2F		        PROGRAMMA_2F[2]
    
    const unsigned int PROGRAMMA_3F[3];
    #define	SETPOINT_TEMP_VASCA_3F 	PROGRAMMA_3F[0]
    #define	SETPOINT_TEMP_CUORE_3F	PROGRAMMA_3F[1]
    #define TEMPO_LAVORO_3F	                PROGRAMMA_3F[2]
    
    #endif /* DEFINIZIONI_FLASH_H_ */
    

    ...and I use the declarations within this header file in some other .c files, including the .h file.

    I also have Caricamento_Programmi.c in which I write the function carica_programmiDEFAULT 

     

    /************************************************************************************************************
     * 					Caricamento_Programmi.c
     ***********************************************************************************************************/
     /* Created on: 22 giugno 2017
     *  Author: Maria Angela Cianci
     */
    #include <Definizioni_FLASH.h>
    #include <Definizioni_Settaggi.h>
    
    unsigned int PROGRAMMA_1[];
    #define	SETPOINT_TEMP_VASCA1 	PROGRAMMA_1[0]
    #define	SETPOINT_TEMP_CUORE1	PROGRAMMA_1[1]
    #define TEMPO_LAVORO1			PROGRAMMA_1[2]
    
    unsigned int PROGRAMMA_2[];
    #define	SETPOINT_TEMP_VASCA2 	PROGRAMMA_2[0]
    #define	SETPOINT_TEMP_CUORE2	PROGRAMMA_2[1]
    #define TEMPO_LAVORO2			PROGRAMMA_2[2]
    
    unsigned int PROGRAMMA_3[];
    #define	SETPOINT_TEMP_VASCA3 	PROGRAMMA_3[0]
    #define	SETPOINT_TEMP_CUORE3	PROGRAMMA_3[1]
    #define TEMPO_LAVORO3			PROGRAMMA_3[2]
    
    unsigned char counter_prog=0;	//Inizializzo il valore del contatore dei programmi a ZERO. Sarà da incrementare ogni volta che viene premuto il tasto programma, per visualizzarlo sul display.
    
    
    void carica_programmiDEFAULT() {
    /* Funzione che permette il caricamento dei programmi con i valori di DEFAULT*/
    
    	SETPOINT_TEMP_VASCA_1F= 600;	//Sono 60.0 GRADI perchè in modalità "visualizzazione temperatura" il punto è già settato sul disdec
    	SETPOINT_TEMP_CUORE_1F= 580;
    	TEMPO_LAVORO_1F= 300;			//Sono 300 MINUTI, vale a dire 5 ORE
    	SETPOINT_TEMP_VASCA_2F= 585;
    	SETPOINT_TEMP_CUORE_2F= 560;
    	TEMPO_LAVORO_2F= 240;
    	SETPOINT_TEMP_VASCA_3F= 620;
    	SETPOINT_TEMP_CUORE_3F= 600;
    	TEMPO_LAVORO_3F= 150;
    	
    	if(BLANCH_CHECK != BLANCH_CHECK_F) {
    	switch(counter_prog) {
    	case 0: {
    		SETPOINT_TEMP_VASCA1=SETPOINT_TEMP_VASCA_1F;
    		SETPOINT_TEMP_CUORE1=SETPOINT_TEMP_CUORE_1F;
    		TEMPO_LAVORO1=TEMPO_LAVORO_1F;
    		} break;
    	case 2: {
    		SETPOINT_TEMP_VASCA2=SETPOINT_TEMP_VASCA_2F;
    		SETPOINT_TEMP_CUORE2=SETPOINT_TEMP_CUORE_2F;
    		TEMPO_LAVORO2=TEMPO_LAVORO_2F;
    		} break;
    	case 3: {
    		SETPOINT_TEMP_VASCA3=SETPOINT_TEMP_VASCA_3F;
    		SETPOINT_TEMP_CUORE3=SETPOINT_TEMP_CUORE_3F;
    		TEMPO_LAVORO3=TEMPO_LAVORO_3F;
    		} break;
    	}
    	}
    }

    And Code Composer gives me this error for every assignment:

    error #138-D: expression must be a modifiable lvalue like this 

    SETPOINT_TEMP_VASCA_1F=600;

    Why?

    If I also use:

    const unsigned int PROGRAMMA_1F[3]={ 600,580,300}; as you suggested, I have this error from the Code Composer: 

    error #10056: symbol "PROGRAMMA_1F" redefined: first defined in "./Caricamento_Programmi.obj"; redefined in "./Settaggi_RAM_EEPROM_Flash.obj"


    And again I really don't understand why if the thinking process behind the code is correct, I suppose.

    Your help would be very appreciated!

    Thank you again,

    Kind Regards,

    Maria Angela

  • Please read this FAQ entry (not from TI).  It is very on point to your situation.  Now I'll discuss some of your errors, including one you made because of me (sorry!).

    luigi Quaglia said:
    const unsigned int PROGRAMMA_1F[3];

    Variable definitions like that cannot occur in a header file, only in a C file.  Furthermore, it may appear exactly one time in the entire program.

    luigi Quaglia said:
    unsigned int PROGRAMMA_1[];

    This is a variable declaration.  It does not reserve any memory for that variable.

    luigi Quaglia said:

    If I also use:

    const unsigned int PROGRAMMA_1F[3]={ 600,580,300}; as you suggested, I have this error from the Code Composer: 

    error #10056: symbol "PROGRAMMA_1F" redefined: first defined in "./Caricamento_Programmi.obj"; redefined in "./Settaggi_RAM_EEPROM_Flash.obj"

    This is my fault.  I forgot that this line appears in a header file.  In a header file you write ...

    extern const unsigned int PROGRAMMA_1F[3];

    In only one C file, you write the line I suggested.  Sorry about that!

    Thanks and regards,

    -George

  • Hi George!!

    thank you for your advices, your explanation and, obviously for your answer.

    Everything you wrote really help me to clear my head!

    And finally I have 0 errors from Code Composer. :)

    Best Regards,

    Maria Angela