Quantcast
Viewing all articles
Browse latest Browse all 262198

Compiler/MSP430F5419A: how struct is compiled in c++ program?

Part Number:MSP430F5419A

Tool/software: TI C/C++ Compiler

I have some questions about the compilation of structs.

the main problem is that i want yo make a method to copy a value to a struct  through a pointer and it can't be done.

the function have three arguments like this.

int ReadRegister (unsigned char *Buff, int start_register, unsigned int count)

i want to put the read value to a struct wich is pointed by Buff. may i can clarify my doubts with a fragment of code:

typedef struct
{ 
  unsigned char Family_Id;
}InfoId_t;


int ReadRegister (unsigned char *Buff, int start_register, unsigned int count) 
/*----------------------------------------------------------------------------*/
/** \brief
    Reads a register from the device as many bytes as you would like.
*******************************************************************************/
{
    BuffT[0] = start_register & 0xff; //LSB
        BuffT[1] = (start_register >> 8) & 0xff; //MSB

    Write(TACTI2C_SLVADDR, BuffT, 2); // This write register you want to read

    Read(SLAVEADDRESS, RxBuff, count) 

         for(int i=0; i<count; i++)
          {
            *Buff = RxBuff[i];
             Buff++;
          }

    return OK;  
}
void main()
{
 InfoId_t info;
unsigned char *ucRxBuff;
ucRxBuff = &info.Family_Id

error = ReadRegister (ucRxBuff, 0x00, sizeof(InfoId_t));
 return 0;
}



the problem in here is that the values are read correctly but when i put the value passing through by pointer info.Family_Id has no value associated.

anyone knows how is this posible? i mean, i suspect that the compiler have some part of fault but but i am not sure. The values are read correctly because i can see making debug all the values in an array
putted inside the fucntion read(), but when i go out the method the value are not copied to info.Family_Id.

Regards




Viewing all articles
Browse latest Browse all 262198

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>