261 can be converted to hex as a separate integer
float f = 261.03;int int_part = (int)f;int dec_part = (f - int_part) * 1000;
Now, the user will input a desired frequency down to 0.5mhz steps. So for example 13,051.5 MHz.
float frequencyMHz = 13,051.5;const float baseOscillatorMHz = 50.0;float multiplier = frequencyMHz / baseOscillatorMHz; // 261.03uint16_t integerPart = multiplier; // This is 261float fractionalPart = multiplier - integerPart;uint32_t numerator = fractionalPart * 1000000.0; // 30000uint32_t denominator = 1000000.0;
So the data must be sent as HEX to the synthesizer. It doesn't like it being sent as a decimal or in binary. Therefore the decimal needs to be converted to HEX. However, for example, if I wanted to send 1000 in HEX format, which is 3E8 in HEX it must be sent like 0x03, 0xE8. Any idea as to how I would go about doing this?Many thanks
#include <SPI.h>SPI.begin();...// Write registerSPI.transfer(0x00); //R0 address, B7:0=WRITESPI.transfer(0x03); //Send data bits 15-8SPI.transfer(0xE8); //Send data bits 7-0...// Read registerSPI.transfer(0x80); //R0 address, B7:1=READuint8_t hi = SPI.transfer(0x00); //Read data bits 15-8uint8_t lo = SPI.transfer(0x00); //Read data bits 7-0
That then needs to be converted into HEX using code in arduino to be sent over to the synth.
Yes, I've actually managed to do what you've said, as in sending the data over, However, after doing the maths to work out what the N divider is and so on, this is in decimal format. That then needs to be converted into HEX using code in arduino to be sent over to the synth. However it doesn't like being sent the information 0xFFFF, it needs to be split into two, 0xFF and 0xFF
uint16_t divider = 1000;uint8_t divider_hi = (uint8_t)(divider >> 8);uint8_t divider_lo = (uint8_t)divider;
The data is transferred in binary
.... then by logical extension "in binary" should mean a sequence of ASCII characters '0' or '1'.