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/TMS320F28335: Need to transmit double values to DAC via SPI

Part Number: TMS320F28335

Tool/software: Code Composer Studio

Hello,

I am using the Pmod DA4: Eight 12-bit D/A Outputs and it may receive up to 32 bits of information as so:

I plan to send two 16 bits of info to the DAC. The data bits I want to send come from:

CurrDrawn = meas_volt2curr((float)AdcMirror.ADCRESULT0 * 3/4096); //CurrDrawn is a double and meas_volt2curr performs simple math operations to change the value

I was wondering how I can convert the double back into binary form so that I can send it to the DAC.

Thank you in advance!

Jose

  • Hi Jose,

    Are you trying to just convert it to an integer type (essentially truncating the fractional part)? If so, type casting it to an appropriate integer type should do the job.

    Or is your DAC actually expecting a value that it can interpret as a float? In that case, the union option in the "original question" post above is a good option.

    Whitney

  • Whitney Dewey said:

     the union option in the "original question" post above is a good option.

    I am new to C programming so how do I convert the double into binary (or is it done automatically)? And I'm not sure how to use union to "pick apart the bytes".

    I don't expect you to give me the answer but pointing me in the right direction would be very helpful.

    Thank you!

  • Assuming you mean "binary" as the raw IEEE format value stored in memory, then you can use a union to tell the compiler to interpret the data as a float if you refer to it one way (like when doing your calculations) or an unsigned integer array if you refer to it a different way (like when sending it over SPI). I recommend just doing a web search for something like "c programming union" and you should be able to find some good explanations and examples.

    Whitney