I suspect the problem is not with your C code but with your Makefile.
The following lines in your Makefile produce an example.o
object file.
main:
avr-gcc -g -Os -Wall -mmcu=atmega328 -c ../src/example.c
The created .o
file only contains the symbols and code from example.c
, not the additional source required to actually make it run on a target system such as interrupt vector jump tables and code to initialise the BSS RAM segment to zeros, and load your initialised data sections.
You'll need to add an additional line something like this to run the linker and produce an output object suitable for download to the AVR part. Alternatively, use avr-ld
, but you'll have to work out all the required linker options.
main.elf: example.o
avr-gcc example.o -o main.elf
You can use avr-objdump --disassemble-all <filename>
on both example.o
and main.elf
yourself to verify the different content of each file.
It's always a good idea to try to reduce your problem in steps to the most simple example possible. In this case, it would probably mean dropping into the AVR Studio software and creating a project running on the simulator using their managed build process. From there, you could them export the Makefile in use by their build process by using the 'Export Makefile' menu option. The generated makefile could then be compared with your version.
Actually, it's probably a good idea to use a Makefile similar to the one generated by AVR Studio because it has the correct rules already defined, you just have to set up some variables with regard to which objects need to be generated and the final target file name.
Your variable Compare
is an array of chars. Your void uart_putchar(char ch)
expects a char, not a char array, so you can't use that one to print Compare
. Your function void uart_puts(const char *s)
does expect a char array, but expects it to be constant as well! You might want to try to change that to void uart_puts(char *s)
.
Also, it's always a good idea to initalize your variable, like this: unsigned char Compare[COMPBUFSIZE] = {0}
- that way you don't get unexpected results when the program didn't write to the variable yet.
By default, stdout is the UART module. So you can also use the standard puts
and putchar
functions to write a string or a character to the UART, like this: puts(Compare)
or putchar(Compare[0])
.
If nothing of this works, I'd recommend you to use the printf
function. The compiler should optimize that.
Best Answer
Here is a 1 to 10 UART switch using cheap and readily available components. I did this design about 5 years ago. Very simple and works like a charm. I can not give away where it is used but let's say it is very reliable.