ATmega328p resetet ständig

OP #4826279
Lesenswert?

Liebe Leute,

ich hoffe es kann mir jemand helfen..

Von einem AtMega328p mit 16Mhz Quarz und FTDI FT232 will ich einen 
String an ein Terminal senden..
1
#define F_CPU 16000000UL
2

3
#include <avr/io.h>
4

5
#define BAUD 300L                  
6
#define UBRR_VAL  ((F_CPU ) / (BAUD * 16) - 1)  
7

8

9
void uart_init() {
10
    UBRR0H = (UBRR_VAL >> 8);
11
    UBRR0L = UBRR_VAL & 0xFF;
12
    UCSR0B = (1 << TXEN0);
13
    UCSR0C = (1<<UCSZ01) | (1<<UCSZ00); // 8bit 1 stopbit
14
}
15

16
void uart_putc (unsigned char data) {
17
    while (( UCSR0A & (1 << UDRE0)) == 0) {};         
18
    UDR0 = data;                                   
19
}
20

21
int main(void) {
22
    uart_init();
23
    char * s = "halo";
24
    char * t = s;
25
    /*
26
    uart_putc(*s);
27
    s++;
28
    uart_putc(*s);
29
    s++;
30
    uart_putc(*s);
31
    s++;
32
    uart_putc(*s);
33
    */
34
    while ( *t != '\0' ) {
35
        uart_putc(*t);
36
        t++;
37
    }
38
    while (1) { };

Es scheint als ob der Controller ständig resetet und es werden laufend 
'h' gesendet.

Wenn ich die Zeichen einzeln sende, wie im Moment auskommentiert und 
dafür die while-Schleife auskommentiere, geht alles hervorragend.

Ja, Abblockkondensatoren sind verbaut.

Weiß jemand Rat?

Danke schonmal
Flolix
OP #4826340
Lesenswert?

Nur main..
Mein String "halo" taucht übrigens indem ganze *.lss-File nicht auf! 
Sollte er das?!?
1
int main(void) {
2
  aa:  cf 93         push  r28
3
  ac:  df 93         push  r29
4
  uart_init();
5
  ae:  0e 94 41 00   call  0x82  ; 0x82 <uart_init>
6
  b2:  c0 e6         ldi  r28, 0x60  ; 96
7
  b4:  d0 e0         ldi  r29, 0x00  ; 0
8
  s++;
9
  uart_putc(*s);
10
  s++;
11
  uart_putc(*s);
12
  */
13
  while ( *t != '\0' ) { 
14
  b6:  02 c0         rjmp  .+4        ; 0xbc <main+0x12>
15
    uart_putc(*t);
16
  b8:  0e 94 4e 00   call  0x9c  ; 0x9c <uart_putc>
17
  s++;
18
  uart_putc(*s);
19
  s++;
20
  uart_putc(*s);
21
  */
22
  while ( *t != '\0' ) { 
23
  bc:  89 91         ld  r24, Y+
24
  be:  88 23         and  r24, r24
25
  c0:  d9 f7         brne  .-10       ; 0xb8 <main+0xe>
26
  c2:  ff cf         rjmp  .-2        ; 0xc2 <main+0x18>
27

28
000000c4 <_exit>:
29
  c4:  f8 94         cli
30

31
000000c6 <__stop_program>:
32
  c6:  ff cf         rjmp  .-2        ; 0xc6 <__stop_program>

ausgabe von avr-gcc.
compiliert und gelinkt..
1
Using built-in specs.
2
COLLECT_GCC=avr-gcc
3
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.5.3/lto-wrapper
4
Target: avr
5
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-libssp --build=i686-linux-gnu --host=i686-linux-gnu --target=avr
6
Thread model: single
7
gcc version 4.5.3 (GCC) 
8
COLLECT_GCC_OPTIONS='-Wall' '-c' '-o' 'o/uart.o' '-Os' '-g' '-mmcu=avr5' '-D__AVR_ATmega328P__' '-v'
9
 /usr/lib/gcc/avr/4.5.3/cc1 -quiet -v -imultilib avr5 -D__AVR_ATmega328P__ uart.c -quiet -dumpbase uart.c -mmcu=avr5 -auxbase-strip o/uart.o -g -Os -Wall -version -o /tmp/ccd9hlQi.s
10
GNU C (GCC) version 4.5.3 (avr)
11
  compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
12
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
13
ignoring nonexistent directory "/usr/lib/gcc/avr/4.5.3/../../../avr/sys-include"
14
#include "..." search starts here:
15
#include <...> search starts here:
16
 /usr/lib/gcc/avr/4.5.3/include
17
 /usr/lib/gcc/avr/4.5.3/include-fixed
18
 /usr/lib/gcc/avr/4.5.3/../../../avr/include
19
End of search list.
20
GNU C (GCC) version 4.5.3 (avr)
21
  compiled by GNU C version 4.6.2, GMP version 5.0.2, MPFR version 3.1.0-p3, MPC version 0.9
22
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
23
Compiler executable checksum: 591284b680435834ad2fbe6642ff4fee
24
COLLECT_GCC_OPTIONS='-Wall' '-c' '-o' 'o/uart.o' '-Os' '-g' '-mmcu=avr5' '-D__AVR_ATmega328P__' '-v'
25
 /usr/lib/gcc/avr/4.5.3/../../../avr/bin/as -mmcu=avr5 -o o/uart.o /tmp/ccd9hlQi.s
26
COMPILER_PATH=/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.5.3/../../../avr/bin/
27
LIBRARY_PATH=/usr/lib/gcc/avr/4.5.3/avr5/:/usr/lib/gcc/avr/4.5.3/../../../avr/lib/avr5/:/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/4.5.3/../../../avr/lib/
28
COLLECT_GCC_OPTIONS='-Wall' '-c' '-o' 'o/uart.o' '-Os' '-g' '-mmcu=avr5' '-D__AVR_ATmega328P__' '-v'
29
Using built-in specs.
30
COLLECT_GCC=avr-gcc
31
COLLECT_LTO_WRAPPER=/usr/lib/gcc/avr/4.5.3/lto-wrapper
32
Target: avr
33
Configured with: ../src/configure -v --enable-languages=c,c++ --prefix=/usr/lib --infodir=/usr/share/info --mandir=/usr/share/man --bindir=/usr/bin --libexecdir=/usr/lib --libdir=/usr/lib --enable-shared --with-system-zlib --enable-long-long --enable-nls --without-included-gettext --disable-libssp --build=i686-linux-gnu --host=i686-linux-gnu --target=avr
34
Thread model: single
35
gcc version 4.5.3 (GCC) 
36
COMPILER_PATH=/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/:/usr/lib/gcc/avr/4.5.3/../../../avr/bin/
37
LIBRARY_PATH=/usr/lib/gcc/avr/4.5.3/avr5/:/usr/lib/gcc/avr/4.5.3/../../../avr/lib/avr5/:/usr/lib/gcc/avr/4.5.3/:/usr/lib/gcc/avr/4.5.3/../../../avr/lib/
38
COLLECT_GCC_OPTIONS='-Wall' '-o' 'elf/uart.elf' '-mmcu=avr5' '-D__AVR_ATmega328P__' '-v'
39
 /usr/lib/gcc/avr/4.5.3/collect2 -m avr5 -o elf/uart.elf /usr/lib/gcc/avr/4.5.3/../../../avr/lib/avr5/crtm16.o -L/usr/lib/gcc/avr/4.5.3/avr5 -L/usr/lib/gcc/avr/4.5.3/../../../avr/lib/avr5 -L/usr/lib/gcc/avr/4.5.3 -L/usr/lib/gcc/avr/4.5.3/../../../avr/lib o/uart.o -lgcc -lc -lgcc
OP #4826375
Lesenswert?

Carl D. schrieb:
> Der String liegt (hier unsichtbar) hinter dem Code und wird in der

habe ihn gefunden! :)
1
avr-objdump -j .data  -d -S elf/uart.elf

Watchdog ist aus!

Fuses 17 mal überprüft..
lfuse reads as FF
hfuse reads as D9
efuse reads as 7


@sylaina
Könntest Du das etwas näher erklären?

@Marc
ja im hex file ist der String... gerade geschaut..

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren