I'm writing a simple library for my AVR, and I wanted to try to use a macro function to define my baud-rate. A lot of the functions in the AVR's library use the macro F_CPU as well as the one I want to write.
Here's what I have for the macro definition and my supposed implementation:
#define BAUD_SELECT(baud) ((F_CPU)/(2*baud)-1)
myubrr = BAUD_SELECT(38400);
I have tried using #define F_CPU 8000000UL, and also in the make file as -D"F_CPU 8000000UL" but I always get the same error at the implementation line.
expected ')' before numeric constant
I'm sure it has something to do with my abuse of #define, and that the macro definition is in a header file, the implementation in the appropriate .c file, and the F_CPU definition either in the makefile or another main.c file.
EDIT I made the parenthesis change as suggested and ran the preprocessor and found the output file (atleast I think)
unsigned int myubrr = ((8000000UL 1)/(2*(baud))-1);
It places an extra 1 where F_CPU should be, I'm not experienced with the preprocessor so I'm not sure how to make it not do that, but perhaps that is the problem?
BAUD_SELECT(some_baud+100)which would expand to((F_CPU)/(2*some_baud+100)-1)which is not what you want. So, you would have to write the expression like this:((F_CPU)/(2*(baud))-1)