Part Number: MSP430F5419A
Tool/software: TI C/C++ Compiler
i make a method that read the adress of a controller conected to msp430.
we put and object, this objects is one of those which are defined in the regiter memory of the controller.
the address i want to get it, has 16 bit so i need to return at least an unsigned int, because there are not signed address.
the method is this:
unsigned int TactilI2C::Get_Start_Position(unsigned char Element)
{
unsigned int Address = 0;
for(int i = 0; i < data.info.Num_Obj_Declarados; i++ )
{
if(data.object_table[i].Type == Element)
{
Address |= (data.object_table[i].MSB << 8);
Address |= data.object_table[i].LSB;
return Address;
}
}
return Address;
}
when this function return, the value get it is a value like 0x005A when the correct value is 0x045A.
i put the method had called the function:
int TactilI2C::Write_Object_Config(unsigned char Object_Type, mxt_config *cfg)
{
unsigned char ucObj_Buf[256];
unsigned char usObj_Addr[2];
unsigned short usDevice_Size;
unsigned short num_bytes;
bool error = false;
if (Object_Is_Volatile(Object_Type))
{
return TACTI2C_ERROR_OBJECT_IS_VOLATILE; // object is volatile
}
usObj_Addr = Get_Start_Position(Object_Type); // here is called
if (error){
return error;
}
usDevice_Size = (unsigned short)Get_Object_Size(Object_Type);
//compare if sizes are diferent read from device config and read from config file (in our case hardcode)
if (usDevice_Size > cfg->objcfg.size)
{
m_pLog->Traza (LOG_NIV_FINAL, MSGLOG_ERROR, "TactilI2C::Write_Object_Config() ---> Extending config by: ");
m_pLog->TrazaDirecto (LOG_NIV_MEDIO, (char*)(usDevice_Size - cfg->objcfg.size));
m_pLog->Traza (LOG_NIV_FINAL, MSGLOG_ERROR, "TactilI2C::Write_Object_Config() ---> bytes in T:");
m_pLog->TrazaDirecto (LOG_NIV_MEDIO, (char*)cfg->objcfg.type);
num_bytes = cfg->objcfg.size;
}
else if (cfg->objcfg.size > usDevice_Size) {
/* Either we are in fallback mode due to wrong
* config or config from a later fw version,
* or the file is corrupt or hand-edited */
m_pLog->Traza (LOG_NIV_FINAL, MSGLOG_MESSAGE, "TactilI2C::Write_Object_Config() ---> Discarding: ");
m_pLog->TrazaDirecto (LOG_NIV_MEDIO, (char*)cfg->objcfg.size - usDevice_Size);
m_pLog->Traza (LOG_NIV_FINAL, MSGLOG_MESSAGE, "TactilI2C::Write_Object_Config() ---> bytes in T:");
m_pLog->TrazaDirecto (LOG_NIV_MEDIO, (char*)cfg->objcfg.type);
num_bytes = usDevice_Size;
}else {
num_bytes = usDevice_Size;
}
/* Update bytes from config */
memcpy(ucObj_Buf, cfg->objcfg.data, num_bytes);
/* Write object */
error = WriteRegister(usObj_Addr, ucObj_Buf, num_bytes);
if (error)
{
m_pLog->Traza (LOG_NIV_FINAL, MSGLOG_ERROR, "TactilI2C::Write_Object_Config() ---> Config write error");
return error;
}
return 0;
}