So with the help of the code from #Portable Trollmaster 3000 I was able to set up the module in no time. It works on the atmega32 (no real surprise here). I've made some little changes to the program - I set the sending power all the way up with the help of the datasheet and also worked on the following function. This should make it easier to set the frequency.
void set_frequency(unsigned long frequency)
{
unsigned long factor = frequency / 8192;
unsigned int upper = (uint8_t) (factor >> 8);
unsigned int lower = (uint8_t) ((factor << 8) >>8);
Wire.beginTransmission(NS731_I2C_addr);
Wire.write((uint8_t) 0x0a);
Wire.write((uint8_t) lower); // lower 0XEA is 90.0 Mhz 77 / 33 for 108
Wire.write((uint8_t) upper); // upper 0X2A Change those values to change the frequency
Wire.endTransmission();
}
updated function, removed not needed type castings etc. (thanks to @al1 )
void set_frequency(unsigned long frequency)
{
unsigned long factor = frequency / 8192;
uint8_t upper = factor >> 8;
uint8_t lower = factor;
Wire.beginTransmission(NS731_I2C_addr);
Wire.write((uint8_t) 0x0a);
Wire.write(lower); // lower 0XEA is 90.0 Mhz 77 / 33 for 108
Wire.write(upper); // upper 0X2A Change those values to change the frequency
Wire.endTransmission();
}
Discussions
Become a Hackaday.io Member
Create an account to leave a comment. Already have an account? Log In.
Well, the shifting trick could work, but I can imagine that too diligent compiler can optimize the code out, not sure about it.
Are you sure? yes | no
Line 5 looks some wired for me. Why are you shifting it first right and then left again?. Why are you usinf int for upper and lower and not uint8_t or unsigned char?
Are you sure? yes | no
The idea behind that is to get rid of the upper 8bits, because I was unsure what the casting from long to int would produce, when the long is bigger than the max integer value. The "unsigned int" vs. "uint8_t" is a result of mixing codes :D I'm going to change that, thank you! I'm gonna play around with the casting stuff and check what I need (easier now with a display hooked up ;) )
Are you sure? yes | no
If you want to get rid of upper 8 bits of "bar" (and leave only lower 8 bits) and copy it into "foo" you can do something like
foo = bar & 0xFF;
Are you sure? yes | no
@jaromir.sukuba interesting! I guess type casting did the trick as well, but this seems like a clean way too.
Are you sure? yes | no