Maker Pro
Maker Pro

Newbie AVR-gcc - function weirdness

T

Thomas Ruschival

Hi Group
I am a Student of Electronic engineering and new to program my
own Atmega128 microcontroller, and I started with basic tests to verify the
hardware is correct, it is indeed. For now I am checking the results with
an oscilloscope to eliminate probable hardware bugs.
Here is the weird problem:
if I call a function in my code it doesn't do anything
in following code I expect to get a rectangle signal on PORTD
and a static bitpattern representing the number 17 on PORTC
but none happens, if I comment out the function call I get the rectangle
on PORTD with the funtion call I get nothing.....

I am desperate as I don't understand what is going on......

this is the compile command
avr-gcc test.c -Wall -mmcu=atmega128 -o test.o ;

Here is the simple but not working code:

#include <avr/io.h>
#include <inttypes.h>

void test2(uint8_t c);

int main(){
DDRD = 0xFF;
DDRC = 0xFF;
PORTC = 0xFF; // init port
// wait a bit
asm volatile("nop\n\t"
"nop\n\t"
"nop\n\t"
::);
// test2(17); // uncomment this line and it stops working!!

while (1){
PORTD = 0x00; // init port
// wait a bit
asm volatile("nop\n\t"
"nop\n\t"
"nop\n\t"
::);
PORTD = 0xFF;
// wait a bit
asm volatile("nop\n\t"
"nop\n\t"
"nop\n\t"
::);
}
return 0;
}

void test2(uint8_t c){
PORTC = c;
}
 
T

Thomas Ruschival

Hi group
it seems the problem was not the code but the fuse bits I forgot to
set some of them....
 
Top