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: Another problem with C and ASM used together?!...

Part Number: MSP430G2744

Tool/software: Code Composer Studio

Hi everybody!!

I'm here again to ask your help and try to resolve a problem in my code.

I have a BUFFER_EEPROM defined as an ARRAY of integer in RAM, in my header file "Definizioni_Settaggi.h"

unsigned int BUFFER_EEPROM [32];

I also define the first 3 members of this array, as follows:

#define FLAG_ATTIVAZIONI		BUFFER_EEPROM[0]
#define BLANCH_CHECK			BUFFER_EEPROM[1]
#define FLAG_VISUALIZZAZIONI	BUFFER_EEPROM[2]

Now, these are flags for me, and I want to test, set and clear their bits in an asm function which shares the header file with some other .c files.

For FLAG_ATTIVAZIONI I declare:

#define FLAG_FILTRO5060 0x0001
#define FLAGsonda_CUORE 0x0002
#define FLAGsonda_MAX 0x0004
#define FLAG_CORREZIONE 0x0008
unsigned int FLAG_ATTIVAZIONI;

And I use these names refer to tese bits of my FLAG_ATTIVAZIONI in the asm function AVVIA_CONN in the file "Protocollo_SPI.asm"

AVVIA_CONN:			nop
				push.b R13
				clr.b  R13
				mov.b #0x80, &UCA0TXBUF
				bit.b #FLAG_FILTRO5060, FLAG_ATTIVAZIONI
				jeq	  FILTRO_50HzAA
				nop
				mov.b #CONREG_MAX60, R13
				br	  #TRASMETTI_AA

But the Code Composer shows me this error: "Unexpected trailing operand(s)" at the line where I wrote --> bit.b #FLAG_FILTRO5060, FLAG_ATTIVAZIONI.

I really don't understand why...

Is there something wrong in my code? Which is the best way to resolve this problem?

I hope someone might help me sort things out and give me some helpful piece of advice.

Thank You for your attention,

Kind Regards

Maria Angela 

  • In cases like these, I like to make the compiler do the work. Here's a test case which tests a bit in the variable:

    #define FLAG_FILTRO5060 0x0001
    unsigned int FLAG_ATTIVAZIONI;

    void AVVIA_CONN(void)
    {
    if (FLAG_ATTIVAZIONI & FLAG_FILTRO5060)
    call1();
    else
    call2();
    }

    The compiler generates this:

    AVVIA_CONN:
    BIT.W #1,&FLAG_ATTIVAZIONI+0
    JNE $C$L1
    BR #call2
    $C$L1:
    BR #call1

    This suggests to me that you need to write "&FLAG_ATTIVAZIONI" instead of "FLAG_ATTIVAZIONI". Does this help?
  • One thing has me confused.  You write ...

    luigi Quaglia said:
    #define FLAG_ATTIVAZIONI BUFFER_EEPROM[0]

    ... and ...

    luigi Quaglia said:
    unsigned int FLAG_ATTIVAZIONI;

    I don't see how you can have both of these in the same C file.  If you do, that second one turns into ...

    unsigned int BUFFER_EEPROM[0];

    That is another definition BUFFER_EEPROM.  That's not legal code.

    Thanks and regards,

    -George

  • Hi Archeologist!
    Yesterday I try with the "& solution" but, unfortunately, the errors are still here ;(
    I think the problem is with de definition of BUFFER_EEPROM and FLAG_ATTIVAZIONI as a part of this integer vector.
    However, thank you very much for your answer!
    If you have any other advice, they will be sure appreciate!
    Kind Regards,
    Maria Angela
  • Hi George!

    Thank You for your answer. I think this is the center of my problem...

    So I deleted the definition

    #define FLAG_ATTIVAZIONI  BUFFER_EEPROM[0]

    and in a .c file I wrote this:

    BUFFER_EEPROM[0]=FLAG_ATTIVAZIONI;

    In my code I need that FLAG_ATTIVAZIONI is a variable available (it is a flag, so I want to have access at its bitfield) and it must be placed in BUFFER_EEPROM.

    Is this the correct approach to my purpose?

    Best Regads,

    Maria Angela

  • I'm not sure of the root of the problem.  I can say, speaking more generally, that this ...

    luigi Quaglia said:
    #define FLAG_ATTIVAZIONI BUFFER_EEPROM[0]
    #define BLANCH_CHECK BUFFER_EEPROM[1]
    #define FLAG_VISUALIZZAZIONI BUFFER_EEPROM[2]

    ... is unusual coding practice.  It is typical for a symbol created by #define to be written in all capital letters.  It is not typical for it to correspond to an array location.  This is a typical usage of #define ...

    luigi Quaglia said:
    #define FLAG_FILTRO5060 0x0001
    #define FLAGsonda_CUORE 0x0002
    #define FLAGsonda_MAX 0x0004
    #define FLAG_CORREZIONE 0x0008

    Why do you have those #define names correspond to array locations?  What overall problem are you solving?  If I understand that better, I may be able to suggest a better way to do it.

    Thanks and regards,

    -George

  • George, thanks for your reply.

    The structure that I want to give to my program is something like this:

    -----------------------------RAM-----------------------------

    0x200-->  BUFFER_EEPROM[32]

    -----------------------------------------------------------------

    This array has, at every location, a FLAG; so I have:

    FLAG_ATTIVAZIONI at the first location of BUFFER_EEPROM----> in BUFFER_EEPROM[0]

    BLANCH_CHECK is placed in BUFFER_EEPROM[1]

    FLAG_VISUALIZZAZIONI at BUFFER_EEPROM[2]

    in order to have a specific part of the RAM memory organized.

    In addition to that, my idea is to have every array location of BUFFER_EEPROM[] accessible individually as a sort of bit array:

     ---------------FLAG_ATTIVAZIONI-----------------

    FLAG_FILTRO5060 is the first bit---> 0x001

    FLAGsonda_CUORE is the second bit---> 0x002

    and so on.

    And to do that I wrote the above definitions. I hope now I've made it a bit clearer.

    Thank you very much again,

    Kind regards,

    Maria Angela

  • luigi Quaglia said:

    This array has, at every location, a FLAG; so I have:

    FLAG_ATTIVAZIONI at the first location of BUFFER_EEPROM----> in BUFFER_EEPROM[0]

    BLANCH_CHECK is placed in BUFFER_EEPROM[1]

    FLAG_VISUALIZZAZIONI at BUFFER_EEPROM[2]

    in order to have a specific part of the RAM memory organized.

    Do you need them at that exact location, in that exact order?  Or, do you need them in a particular range of memory, and the exact order does not matter?  Please explain why.

    Thanks and regards,

    -George