ΣSigmaStudio Ask AI Русский Log in

Is this a help file doc error --or is something else going on

SigmaDSP & SigmaStudio Brettcoupe Sep 28, 2010 00:00 3 replies Original on forum ↗
Subscribe
Brettcoupe Question
Sep 28, 2010 00:00

Hi

I am using the helpfile implemtation code examples for safeload writes and 5.32 conversion

As Below

Microcontroller Code functions, safeload: single parameter write

void SafeloadSingleParamWrite(short address, float param)

{

byte param_hex[4] = {0x00, 0x00, 0x00, 0x00};

//convert decimal paramater value to 5.23 format

To523(param, param_hex);

byte paramex_hex[5];

paramex_hex[0]=0x00;

paramex_hex[1]=param_hex[0];

paramex_hex[2]=param_hex[1];

paramex_hex[3]=param_hex[2];

paramex_hex[4]=param_hex[3];

SafeParam(SAFELOAD_DATA_0, paramex_hex);

SafeAddr(SAFELOAD_ADDRESS_0, address);

InitSafeloadParam();

}

// Microcontroller code - functions: convert a float number to 5.23 format

void To523(float param_dec, byte* param_hex)

{

long param223;

long param227;

//multiply decimal number by 2^23

param223 = param_dec * (1 << 23);

//convert to positive binary

param227 = param223 + (1 << 27);

param_hex[3]=(byte)param227; //get byte 3 (LSBs) of parameter value

param_hex[2]=(byte)(param227>>8); //get byte 2 of parameter value

param_hex[1]=(byte)(param227>>16); //get byte 1 of parameter value

//get byte 0 (MSBs) of parameter value

param_hex[0]=(byte)(param227>>24);

//invert sign bit to get correct sign

param_hex[0] = param_hex[0] ^ 0x08;

}

//Microcontroller Code - functions, Safeload: SafeParam

void SafeParam(short safe_param, unsigned char* param_data)

{

byte safe_param_lo;

byte safe_param_hi;

//get low byte of register/RAM address

safe_param_lo=(byte)safe_param;

//get high byte of address shift left by 8 bits

safe_param_hi=(byte)(safe_param>>8);

SPI_TX_REG = 0x00; //Write to DSP at chip address 0

SPI_TX_REG = safe_param_hi; //Write high byte of Safeload address

SPI_TX_REG = safe_param_lo; //Write low byte of Safeload address

SPI_TX_REG = param_data[4]; //Write parameter byte 4 (MSBs)

SPI_TX_REG = param_data[3]; //Write parameter byte 3

SPI_TX_REG = param_data[2]; //Write parameter byte 2

SPI_TX_REG = param_data[1]; //Write parameter byte 1

SPI_TX_REG = param_data[0]; //Write parameter byte 1 (LSBs)

}

#####################################################

NOTE: SPI_TX_REG is replaced with my SPI rutine

SendSPI(param_data[4]) ; ETC ETC //Write parameter byte 4 (MSBs)

What I have Found is the the SafeParam() funtion is sending the LSB first Not the MSB as it is said by the comments

if I swap the function to be

SPI_TX_REG = 0x00; //Write to DSP at chip address 0

SPI_TX_REG = safe_param_hi; //Write high byte of Safeload address

SPI_TX_REG = safe_param_lo; //Write low byte of Safeload address

SPI_TX_REG = param_data[0]; //Write parameter byte 0 (MSBs)

SPI_TX_REG = param_data[1]; //Write parameter byte 1

SPI_TX_REG = param_data[2]; //Write parameter byte 2

SPI_TX_REG = param_data[3]; //Write parameter byte 3

SPI_TX_REG = param_data[4]; //Write parameter byte 4 (LSBs)

it works Ok.

thoughts?

Thanks

Brett

MagicRuB Reply
Sep 30, 2010 00:00

Check out this thread: https://ez.analog.com/message/6811

ADIApproved Reply
Oct 1, 2010 00:00

Hello Brett,

Thanks for pointing this out. I'm currently in the process of updating several articles in the help file. I will add this to my "to-do list."

Best Regards,

Brett

EZAdministrator Reply
Aug 2, 2018 00:00

This question has been assumed as answered either offline via email or with a multi-part answer. This question has now been closed out. If you have an inquiry related to this topic please post a new question in the applicable product forum.

Thank you,
EZ Admin