Forum: Mikrocontroller und Digitale Elektronik AtMega ehwiges Fuse Thema 16 Mhz Quarz


von Metrix (Gast)


Angehängte Dateien:

Lesenswert?

Hallo,

Ich bin entweder blöd, oder mein UART will mich veräppeln!

Und zwar hab in der "never ending loop" eine Pause von 1000ms 
(_delay_ms(1000)); somit müsste er mir jede Sekunde per UART ein Text 
ausgeben.. tut er aber nicht, er tut danach einfach nichts mehr :/

Nutze die Lib von Peter Fleury:
#define UART_BAUD_RATE      57600
#define F_CPU  16000000UL

Ich hab ein AtMega8515 mit Grundbeschaltung und einem externen Quarz, 
(Nein kein Quarzoscilator) die Fuses sind im AVRStudio eingestellt wie 
im Screenshot (Ext. Crystal/Resonator High Freq.;Start-up time: 16K + 
64ms);

Vielleicht kann mir ja jemand helfen. :)

von Christopher G. (cbg)


Lesenswert?

Im Buildlog sind Warnings. Poste mal den Buildlog und deinen Sourcecode.

von Daniel S. (sany)


Lesenswert?

1
#include <stdlib.h>
2
#include <avr/io.h>
3
#include <avr/interrupt.h>
4
#include <util/delay.h>
5
#include "uart.h"
6
7
#define UART_BAUD_RATE      57600
8
9
int main(void)
10
{
11
12
  uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
13
   
14
  sei();
15
16
  const char *text1 = "\f\a\n Diagnose Mobile Terminal V0.1 \r\n";
17
  const char *text2 = "** Kernel: 0.0.0.1\r\n";
18
  const char *text3 = "** Firmware: 0.0.0.1\r\n";
19
20
  uart_puts(text1);
21
  _delay_ms(1000);
22
  uart_puts(text2);
23
  _delay_ms(1000);
24
  uart_puts(text3);
25
  _delay_ms(1000);
26
  uart_puts("OK\r\n");
27
}

Der Warning war noch ein doppel definiertes F_CPU

von Malte M. (maltem)


Lesenswert?

Ich sehe da keine Loop.

Wenn main abgearbeitet ist, bleibt der µC normalerweise stehen (eine 
endlose NOP-Loop) oder macht irgendwas komisches, je nach Compiler. Mach 
um den Block den du wiederholen willst noch ein while(1){ ... }, dann 
tuts auch.

Und sei() würde ich weglassen, wenn du keine Interrupts verwendest.

von Daniel S. (sany)


Lesenswert?

Das hat doch jetzt Primär mit dem Loop nichts zu tun,
Fakt ist das nach uart_puts(text1) gar nichts mehr passiert, keine 
weiteren Texte!

von Malte M. (maltem)


Lesenswert?

Das drück dich bitte nächstes mal präziser aus, wenn ich "loop" und 
"danach" lese, aber keine Schleife sehe, ist das natürlich der erste 
Gedanke.

Ich vermute mal, das der nicht im delay hängenbleibt, sondern in der 
uart-Routine. Poste die mal.

Gehts übrigens, wenn du statt
1
uart_puts(text1);
2
  _delay_ms(1000);
3
  uart_puts(text2);
4
  _delay_ms(1000);

folgendes
1
uart_puts("bla");
2
  _delay_ms(1000);
3
  uart_puts("blubb");
4
  _delay_ms(1000);

machst? Und was empfängt die Gegenstelle überhaupt, den kompletten 
text1, oder nur Teile?

von Daniel S. (sany)


Lesenswert?

Hey ;)

Also es steht im Terminal immer der volle Text,
1
 Diagnose Mobile Terminal V0.1 <\r><\n>

Ab danach kommt nichts mehr ebenfalls wenn ich das ich "bla" änder:
?bla

Die UART Routine ist die von Fleury im Original.
1
/*************************************************************************
2
Title:    Interrupt UART library with receive/transmit circular buffers
3
Author:   Peter Fleury <pfleury@gmx.ch>   http://jump.to/fleury
4
File:     $Id: uart.c,v 1.6.2.2 2009/11/29 08:56:12 Peter Exp $
5
Software: AVR-GCC 4.1, AVR Libc 1.4.6 or higher
6
Hardware: any AVR with built-in UART, 
7
License:  GNU General Public License 
8
          
9
DESCRIPTION:
10
    An interrupt is generated when the UART has finished transmitting or
11
    receiving a byte. The interrupt handling routines use circular buffers
12
    for buffering received and transmitted data.
13
    
14
    The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE variables define
15
    the buffer size in bytes. Note that these variables must be a 
16
    power of 2.
17
    
18
USAGE:
19
    Refere to the header file uart.h for a description of the routines. 
20
    See also example test_uart.c.
21
22
NOTES:
23
    Based on Atmel Application Note AVR306
24
                    
25
LICENSE:
26
    Copyright (C) 2006 Peter Fleury
27
28
    This program is free software; you can redistribute it and/or modify
29
    it under the terms of the GNU General Public License as published by
30
    the Free Software Foundation; either version 2 of the License, or
31
    any later version.
32
33
    This program is distributed in the hope that it will be useful,
34
    but WITHOUT ANY WARRANTY; without even the implied warranty of
35
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
36
    GNU General Public License for more details.
37
                        
38
*************************************************************************/
39
#include <avr/io.h>
40
#include <avr/interrupt.h>
41
#include <avr/pgmspace.h>
42
#include "uart.h"
43
44
45
/*
46
 *  constants and macros
47
 */
48
49
/* size of RX/TX buffers */
50
#define UART_RX_BUFFER_MASK ( UART_RX_BUFFER_SIZE - 1)
51
#define UART_TX_BUFFER_MASK ( UART_TX_BUFFER_SIZE - 1)
52
53
#if ( UART_RX_BUFFER_SIZE & UART_RX_BUFFER_MASK )
54
#error RX buffer size is not a power of 2
55
#endif
56
#if ( UART_TX_BUFFER_SIZE & UART_TX_BUFFER_MASK )
57
#error TX buffer size is not a power of 2
58
#endif
59
60
#if defined(__AVR_AT90S2313__) \
61
 || defined(__AVR_AT90S4414__) || defined(__AVR_AT90S4434__) \
62
 || defined(__AVR_AT90S8515__) || defined(__AVR_AT90S8535__) \
63
 || defined(__AVR_ATmega103__)
64
 /* old AVR classic or ATmega103 with one UART */
65
 #define AT90_UART
66
 #define UART0_RECEIVE_INTERRUPT   SIG_UART_RECV
67
 #define UART0_TRANSMIT_INTERRUPT  SIG_UART_DATA
68
 #define UART0_STATUS   USR
69
 #define UART0_CONTROL  UCR
70
 #define UART0_DATA     UDR  
71
 #define UART0_UDRIE    UDRIE
72
#elif defined(__AVR_AT90S2333__) || defined(__AVR_AT90S4433__)
73
 /* old AVR classic with one UART */
74
 #define AT90_UART
75
 #define UART0_RECEIVE_INTERRUPT   SIG_UART_RECV
76
 #define UART0_TRANSMIT_INTERRUPT  SIG_UART_DATA
77
 #define UART0_STATUS   UCSRA
78
 #define UART0_CONTROL  UCSRB
79
 #define UART0_DATA     UDR 
80
 #define UART0_UDRIE    UDRIE
81
#elif  defined(__AVR_ATmega8__)  || defined(__AVR_ATmega16__) || defined(__AVR_ATmega32__) \
82
  || defined(__AVR_ATmega8515__) || defined(__AVR_ATmega8535__) \
83
  || defined(__AVR_ATmega323__)
84
  /* ATmega with one USART */
85
 #define ATMEGA_USART
86
 #define UART0_RECEIVE_INTERRUPT   SIG_UART_RECV
87
 #define UART0_TRANSMIT_INTERRUPT  SIG_UART_DATA
88
 #define UART0_STATUS   UCSRA
89
 #define UART0_CONTROL  UCSRB
90
 #define UART0_DATA     UDR
91
 #define UART0_UDRIE    UDRIE
92
#elif defined(__AVR_ATmega163__) 
93
  /* ATmega163 with one UART */
94
 #define ATMEGA_UART
95
 #define UART0_RECEIVE_INTERRUPT   SIG_UART_RECV
96
 #define UART0_TRANSMIT_INTERRUPT  SIG_UART_DATA
97
 #define UART0_STATUS   UCSRA
98
 #define UART0_CONTROL  UCSRB
99
 #define UART0_DATA     UDR
100
 #define UART0_UDRIE    UDRIE
101
#elif defined(__AVR_ATmega162__) 
102
 /* ATmega with two USART */
103
 #define ATMEGA_USART0
104
 #define ATMEGA_USART1
105
 #define UART0_RECEIVE_INTERRUPT   SIG_USART0_RECV
106
 #define UART1_RECEIVE_INTERRUPT   SIG_USART1_RECV
107
 #define UART0_TRANSMIT_INTERRUPT  SIG_USART0_DATA
108
 #define UART1_TRANSMIT_INTERRUPT  SIG_USART1_DATA
109
 #define UART0_STATUS   UCSR0A
110
 #define UART0_CONTROL  UCSR0B
111
 #define UART0_DATA     UDR0
112
 #define UART0_UDRIE    UDRIE0
113
 #define UART1_STATUS   UCSR1A
114
 #define UART1_CONTROL  UCSR1B
115
 #define UART1_DATA     UDR1
116
 #define UART1_UDRIE    UDRIE1
117
#elif defined(__AVR_ATmega64__) || defined(__AVR_ATmega128__) 
118
 /* ATmega with two USART */
119
 #define ATMEGA_USART0
120
 #define ATMEGA_USART1
121
 #define UART0_RECEIVE_INTERRUPT   SIG_UART0_RECV
122
 #define UART1_RECEIVE_INTERRUPT   SIG_UART1_RECV
123
 #define UART0_TRANSMIT_INTERRUPT  SIG_UART0_DATA
124
 #define UART1_TRANSMIT_INTERRUPT  SIG_UART1_DATA
125
 #define UART0_STATUS   UCSR0A
126
 #define UART0_CONTROL  UCSR0B
127
 #define UART0_DATA     UDR0
128
 #define UART0_UDRIE    UDRIE0
129
 #define UART1_STATUS   UCSR1A
130
 #define UART1_CONTROL  UCSR1B
131
 #define UART1_DATA     UDR1
132
 #define UART1_UDRIE    UDRIE1
133
#elif defined(__AVR_ATmega161__)
134
 /* ATmega with UART */
135
 #error "AVR ATmega161 currently not supported by this libaray !"
136
#elif defined(__AVR_ATmega169__) 
137
 /* ATmega with one USART */
138
 #define ATMEGA_USART
139
 #define UART0_RECEIVE_INTERRUPT   SIG_USART_RECV
140
 #define UART0_TRANSMIT_INTERRUPT  SIG_USART_DATA
141
 #define UART0_STATUS   UCSRA
142
 #define UART0_CONTROL  UCSRB
143
 #define UART0_DATA     UDR
144
 #define UART0_UDRIE    UDRIE
145
#elif defined(__AVR_ATmega48__) ||defined(__AVR_ATmega88__) || defined(__AVR_ATmega168__) || defined(__AVR_ATmega48P__) || defined(__AVR_ATmega88P__) || defined(__AVR_ATmega168P__) || defined(__AVR_ATmega328P__)
146
 /* ATmega with one USART */
147
 #define ATMEGA_USART0
148
 #define UART0_RECEIVE_INTERRUPT   SIG_USART_RECV
149
 #define UART0_TRANSMIT_INTERRUPT  SIG_USART_DATA
150
 #define UART0_STATUS   UCSR0A
151
 #define UART0_CONTROL  UCSR0B
152
 #define UART0_DATA     UDR0
153
 #define UART0_UDRIE    UDRIE0
154
#elif defined(__AVR_ATtiny2313__)
155
 #define ATMEGA_USART
156
 #define UART0_RECEIVE_INTERRUPT   SIG_USART0_RX 
157
 #define UART0_TRANSMIT_INTERRUPT  SIG_USART0_UDRE
158
 #define UART0_STATUS   UCSRA
159
 #define UART0_CONTROL  UCSRB
160
 #define UART0_DATA     UDR
161
 #define UART0_UDRIE    UDRIE
162
#elif defined(__AVR_ATmega329__) ||defined(__AVR_ATmega3290__) ||\
163
      defined(__AVR_ATmega649__) ||defined(__AVR_ATmega6490__) ||\
164
      defined(__AVR_ATmega325__) ||defined(__AVR_ATmega3250__) ||\
165
      defined(__AVR_ATmega645__) ||defined(__AVR_ATmega6450__)
166
  /* ATmega with one USART */
167
  #define ATMEGA_USART0
168
  #define UART0_RECEIVE_INTERRUPT   SIG_UART_RECV
169
  #define UART0_TRANSMIT_INTERRUPT  SIG_UART_DATA
170
  #define UART0_STATUS   UCSR0A
171
  #define UART0_CONTROL  UCSR0B
172
  #define UART0_DATA     UDR0
173
  #define UART0_UDRIE    UDRIE0
174
#elif defined(__AVR_ATmega2560__) || defined(__AVR_ATmega2561__) || defined(__AVR_ATmega1280__)  || defined(__AVR_ATmega1281__) || defined(__AVR_ATmega640__)
175
/* ATmega with two USART */
176
  #define ATMEGA_USART0
177
  #define ATMEGA_USART1
178
  #define UART0_RECEIVE_INTERRUPT   SIG_USART0_RECV
179
  #define UART1_RECEIVE_INTERRUPT   SIG_USART1_RECV
180
  #define UART0_TRANSMIT_INTERRUPT  SIG_USART0_DATA
181
  #define UART1_TRANSMIT_INTERRUPT  SIG_USART1_DATA
182
  #define UART0_STATUS   UCSR0A
183
  #define UART0_CONTROL  UCSR0B
184
  #define UART0_DATA     UDR0
185
  #define UART0_UDRIE    UDRIE0
186
  #define UART1_STATUS   UCSR1A
187
  #define UART1_CONTROL  UCSR1B
188
  #define UART1_DATA     UDR1
189
  #define UART1_UDRIE    UDRIE1  
190
#elif defined(__AVR_ATmega644__)
191
 /* ATmega with one USART */
192
 #define ATMEGA_USART0
193
 #define UART0_RECEIVE_INTERRUPT   SIG_USART_RECV
194
 #define UART0_TRANSMIT_INTERRUPT  SIG_USART_DATA
195
 #define UART0_STATUS   UCSR0A
196
 #define UART0_CONTROL  UCSR0B
197
 #define UART0_DATA     UDR0
198
 #define UART0_UDRIE    UDRIE0
199
#elif defined(__AVR_ATmega164P__) || defined(__AVR_ATmega324P__) || defined(__AVR_ATmega644P__)
200
 /* ATmega with two USART */
201
 #define ATMEGA_USART0
202
 #define ATMEGA_USART1
203
 #define UART0_RECEIVE_INTERRUPT   SIG_USART_RECV
204
 #define UART1_RECEIVE_INTERRUPT   SIG_USART1_RECV
205
 #define UART0_TRANSMIT_INTERRUPT  SIG_USART_DATA
206
 #define UART1_TRANSMIT_INTERRUPT  SIG_USART1_DATA
207
 #define UART0_STATUS   UCSR0A
208
 #define UART0_CONTROL  UCSR0B
209
 #define UART0_DATA     UDR0
210
 #define UART0_UDRIE    UDRIE0
211
 #define UART1_STATUS   UCSR1A
212
 #define UART1_CONTROL  UCSR1B
213
 #define UART1_DATA     UDR1
214
 #define UART1_UDRIE    UDRIE1
215
#else
216
 #error "no UART definition for MCU available"
217
#endif
218
219
220
/*
221
 *  module global variables
222
 */
223
static volatile unsigned char UART_TxBuf[UART_TX_BUFFER_SIZE];
224
static volatile unsigned char UART_RxBuf[UART_RX_BUFFER_SIZE];
225
static volatile unsigned char UART_TxHead;
226
static volatile unsigned char UART_TxTail;
227
static volatile unsigned char UART_RxHead;
228
static volatile unsigned char UART_RxTail;
229
static volatile unsigned char UART_LastRxError;
230
231
#if defined( ATMEGA_USART1 )
232
static volatile unsigned char UART1_TxBuf[UART_TX_BUFFER_SIZE];
233
static volatile unsigned char UART1_RxBuf[UART_RX_BUFFER_SIZE];
234
static volatile unsigned char UART1_TxHead;
235
static volatile unsigned char UART1_TxTail;
236
static volatile unsigned char UART1_RxHead;
237
static volatile unsigned char UART1_RxTail;
238
static volatile unsigned char UART1_LastRxError;
239
#endif
240
241
242
243
SIGNAL(UART0_RECEIVE_INTERRUPT)
244
/*************************************************************************
245
Function: UART Receive Complete interrupt
246
Purpose:  called when the UART has received a character
247
**************************************************************************/
248
{
249
    unsigned char tmphead;
250
    unsigned char data;
251
    unsigned char usr;
252
    unsigned char lastRxError;
253
 
254
 
255
    /* read UART status register and UART data register */ 
256
    usr  = UART0_STATUS;
257
    data = UART0_DATA;
258
    
259
    /* */
260
#if defined( AT90_UART )
261
    lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
262
#elif defined( ATMEGA_USART )
263
    lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
264
#elif defined( ATMEGA_USART0 )
265
    lastRxError = (usr & (_BV(FE0)|_BV(DOR0)) );
266
#elif defined ( ATMEGA_UART )
267
    lastRxError = (usr & (_BV(FE)|_BV(DOR)) );
268
#endif
269
        
270
    /* calculate buffer index */ 
271
    tmphead = ( UART_RxHead + 1) & UART_RX_BUFFER_MASK;
272
    
273
    if ( tmphead == UART_RxTail ) {
274
        /* error: receive buffer overflow */
275
        lastRxError = UART_BUFFER_OVERFLOW >> 8;
276
    }else{
277
        /* store new index */
278
        UART_RxHead = tmphead;
279
        /* store received data in buffer */
280
        UART_RxBuf[tmphead] = data;
281
    }
282
    UART_LastRxError = lastRxError;   
283
}
284
285
286
SIGNAL(UART0_TRANSMIT_INTERRUPT)
287
/*************************************************************************
288
Function: UART Data Register Empty interrupt
289
Purpose:  called when the UART is ready to transmit the next byte
290
**************************************************************************/
291
{
292
    unsigned char tmptail;
293
294
    
295
    if ( UART_TxHead != UART_TxTail) {
296
        /* calculate and store new buffer index */
297
        tmptail = (UART_TxTail + 1) & UART_TX_BUFFER_MASK;
298
        UART_TxTail = tmptail;
299
        /* get one byte from buffer and write it to UART */
300
        UART0_DATA = UART_TxBuf[tmptail];  /* start transmission */
301
    }else{
302
        /* tx buffer empty, disable UDRE interrupt */
303
        UART0_CONTROL &= ~_BV(UART0_UDRIE);
304
    }
305
}
306
307
308
/*************************************************************************
309
Function: uart_init()
310
Purpose:  initialize UART and set baudrate
311
Input:    baudrate using macro UART_BAUD_SELECT()
312
Returns:  none
313
**************************************************************************/
314
void uart_init(unsigned int baudrate)
315
{
316
    UART_TxHead = 0;
317
    UART_TxTail = 0;
318
    UART_RxHead = 0;
319
    UART_RxTail = 0;
320
    
321
#if defined( AT90_UART )
322
    /* set baud rate */
323
    UBRR = (unsigned char)baudrate; 
324
325
    /* enable UART receiver and transmmitter and receive complete interrupt */
326
    UART0_CONTROL = _BV(RXCIE)|_BV(RXEN)|_BV(TXEN);
327
328
#elif defined (ATMEGA_USART)
329
    /* Set baud rate */
330
    if ( baudrate & 0x8000 )
331
    {
332
       UART0_STATUS = (1<<U2X);  //Enable 2x speed 
333
       baudrate &= ~0x8000;
334
    }
335
    UBRRH = (unsigned char)(baudrate>>8);
336
    UBRRL = (unsigned char) baudrate;
337
   
338
    /* Enable USART receiver and transmitter and receive complete interrupt */
339
    UART0_CONTROL = _BV(RXCIE)|(1<<RXEN)|(1<<TXEN);
340
    
341
    /* Set frame format: asynchronous, 8data, no parity, 1stop bit */
342
    #ifdef URSEL
343
    UCSRC = (1<<URSEL)|(3<<UCSZ0);
344
    #else
345
    UCSRC = (3<<UCSZ0);
346
    #endif 
347
    
348
#elif defined (ATMEGA_USART0 )
349
    /* Set baud rate */
350
    if ( baudrate & 0x8000 ) 
351
    {
352
       UART0_STATUS = (1<<U2X0);  //Enable 2x speed 
353
       baudrate &= ~0x8000;
354
     }
355
    UBRR0H = (unsigned char)(baudrate>>8);
356
    UBRR0L = (unsigned char) baudrate;
357
358
    /* Enable USART receiver and transmitter and receive complete interrupt */
359
    UART0_CONTROL = _BV(RXCIE0)|(1<<RXEN0)|(1<<TXEN0);
360
    
361
    /* Set frame format: asynchronous, 8data, no parity, 1stop bit */
362
    #ifdef URSEL0
363
    UCSR0C = (1<<URSEL0)|(3<<UCSZ00);
364
    #else
365
    UCSR0C = (3<<UCSZ00);
366
    #endif 
367
368
#elif defined ( ATMEGA_UART )
369
    /* set baud rate */
370
    if ( baudrate & 0x8000 ) 
371
    {
372
      UART0_STATUS = (1<<U2X);  //Enable 2x speed 
373
      baudrate &= ~0x8000;
374
    }
375
    UBRRHI = (unsigned char)(baudrate>>8);
376
    UBRR   = (unsigned char) baudrate;
377
378
    /* Enable UART receiver and transmitter and receive complete interrupt */
379
    UART0_CONTROL = _BV(RXCIE)|(1<<RXEN)|(1<<TXEN);
380
381
#endif
382
383
}/* uart_init */
384
385
386
/*************************************************************************
387
Function: uart_getc()
388
Purpose:  return byte from ringbuffer  
389
Returns:  lower byte:  received byte from ringbuffer
390
          higher byte: last receive error
391
**************************************************************************/
392
unsigned int uart_getc(void)
393
{    
394
    unsigned char tmptail;
395
    unsigned char data;
396
397
398
    if ( UART_RxHead == UART_RxTail ) {
399
        return UART_NO_DATA;   /* no data available */
400
    }
401
    
402
    /* calculate /store buffer index */
403
    tmptail = (UART_RxTail + 1) & UART_RX_BUFFER_MASK;
404
    UART_RxTail = tmptail; 
405
    
406
    /* get data from receive buffer */
407
    data = UART_RxBuf[tmptail];
408
    
409
    return (UART_LastRxError << 8) + data;
410
411
}/* uart_getc */
412
413
414
/*************************************************************************
415
Function: uart_putc()
416
Purpose:  write byte to ringbuffer for transmitting via UART
417
Input:    byte to be transmitted
418
Returns:  none          
419
**************************************************************************/
420
void uart_putc(unsigned char data)
421
{
422
    unsigned char tmphead;
423
424
    
425
    tmphead  = (UART_TxHead + 1) & UART_TX_BUFFER_MASK;
426
    
427
    while ( tmphead == UART_TxTail ){
428
        ;/* wait for free space in buffer */
429
    }
430
    
431
    UART_TxBuf[tmphead] = data;
432
    UART_TxHead = tmphead;
433
434
    /* enable UDRE interrupt */
435
    UART0_CONTROL    |= _BV(UART0_UDRIE);
436
437
}/* uart_putc */
438
439
440
/*************************************************************************
441
Function: uart_puts()
442
Purpose:  transmit string to UART
443
Input:    string to be transmitted
444
Returns:  none          
445
**************************************************************************/
446
void uart_puts(const char *s )
447
{
448
    while (*s) 
449
      uart_putc(*s++);
450
451
}/* uart_puts */
452
453
454
/*************************************************************************
455
Function: uart_puts_p()
456
Purpose:  transmit string from program memory to UART
457
Input:    program memory string to be transmitted
458
Returns:  none
459
**************************************************************************/
460
void uart_puts_p(const char *progmem_s )
461
{
462
    register char c;
463
    
464
    while ( (c = pgm_read_byte(progmem_s++)) ) 
465
      uart_putc(c);
466
467
}/* uart_puts_p */
468
469
470
/*
471
 * these functions are only for ATmegas with two USART
472
 */
473
#if defined( ATMEGA_USART1 )
474
475
SIGNAL(UART1_RECEIVE_INTERRUPT)
476
/*************************************************************************
477
Function: UART1 Receive Complete interrupt
478
Purpose:  called when the UART1 has received a character
479
**************************************************************************/
480
{
481
    unsigned char tmphead;
482
    unsigned char data;
483
    unsigned char usr;
484
    unsigned char lastRxError;
485
 
486
 
487
    /* read UART status register and UART data register */ 
488
    usr  = UART1_STATUS;
489
    data = UART1_DATA;
490
    
491
    /* */
492
    lastRxError = (usr & (_BV(FE1)|_BV(DOR1)) );
493
        
494
    /* calculate buffer index */ 
495
    tmphead = ( UART1_RxHead + 1) & UART_RX_BUFFER_MASK;
496
    
497
    if ( tmphead == UART1_RxTail ) {
498
        /* error: receive buffer overflow */
499
        lastRxError = UART_BUFFER_OVERFLOW >> 8;
500
    }else{
501
        /* store new index */
502
        UART1_RxHead = tmphead;
503
        /* store received data in buffer */
504
        UART1_RxBuf[tmphead] = data;
505
    }
506
    UART1_LastRxError = lastRxError;   
507
}
508
509
510
SIGNAL(UART1_TRANSMIT_INTERRUPT)
511
/*************************************************************************
512
Function: UART1 Data Register Empty interrupt
513
Purpose:  called when the UART1 is ready to transmit the next byte
514
**************************************************************************/
515
{
516
    unsigned char tmptail;
517
518
    
519
    if ( UART1_TxHead != UART1_TxTail) {
520
        /* calculate and store new buffer index */
521
        tmptail = (UART1_TxTail + 1) & UART_TX_BUFFER_MASK;
522
        UART1_TxTail = tmptail;
523
        /* get one byte from buffer and write it to UART */
524
        UART1_DATA = UART1_TxBuf[tmptail];  /* start transmission */
525
    }else{
526
        /* tx buffer empty, disable UDRE interrupt */
527
        UART1_CONTROL &= ~_BV(UART1_UDRIE);
528
    }
529
}
530
531
532
/*************************************************************************
533
Function: uart1_init()
534
Purpose:  initialize UART1 and set baudrate
535
Input:    baudrate using macro UART_BAUD_SELECT()
536
Returns:  none
537
**************************************************************************/
538
void uart1_init(unsigned int baudrate)
539
{
540
    UART1_TxHead = 0;
541
    UART1_TxTail = 0;
542
    UART1_RxHead = 0;
543
    UART1_RxTail = 0;
544
    
545
546
    /* Set baud rate */
547
    if ( baudrate & 0x8000 ) 
548
    {
549
      UART1_STATUS = (1<<U2X1);  //Enable 2x speed 
550
      baudrate &= ~0x8000;
551
    }
552
    UBRR1H = (unsigned char)(baudrate>>8);
553
    UBRR1L = (unsigned char) baudrate;
554
555
    /* Enable USART receiver and transmitter and receive complete interrupt */
556
    UART1_CONTROL = _BV(RXCIE1)|(1<<RXEN1)|(1<<TXEN1);
557
    
558
    /* Set frame format: asynchronous, 8data, no parity, 1stop bit */   
559
    #ifdef URSEL1
560
    UCSR1C = (1<<URSEL1)|(3<<UCSZ10);
561
    #else
562
    UCSR1C = (3<<UCSZ10);
563
    #endif 
564
}/* uart_init */
565
566
567
/*************************************************************************
568
Function: uart1_getc()
569
Purpose:  return byte from ringbuffer  
570
Returns:  lower byte:  received byte from ringbuffer
571
          higher byte: last receive error
572
**************************************************************************/
573
unsigned int uart1_getc(void)
574
{    
575
    unsigned char tmptail;
576
    unsigned char data;
577
578
579
    if ( UART1_RxHead == UART1_RxTail ) {
580
        return UART_NO_DATA;   /* no data available */
581
    }
582
    
583
    /* calculate /store buffer index */
584
    tmptail = (UART1_RxTail + 1) & UART_RX_BUFFER_MASK;
585
    UART1_RxTail = tmptail; 
586
    
587
    /* get data from receive buffer */
588
    data = UART1_RxBuf[tmptail];
589
    
590
    return (UART1_LastRxError << 8) + data;
591
592
}/* uart1_getc */
593
594
595
/*************************************************************************
596
Function: uart1_putc()
597
Purpose:  write byte to ringbuffer for transmitting via UART
598
Input:    byte to be transmitted
599
Returns:  none          
600
**************************************************************************/
601
void uart1_putc(unsigned char data)
602
{
603
    unsigned char tmphead;
604
605
    
606
    tmphead  = (UART1_TxHead + 1) & UART_TX_BUFFER_MASK;
607
    
608
    while ( tmphead == UART1_TxTail ){
609
        ;/* wait for free space in buffer */
610
    }
611
    
612
    UART1_TxBuf[tmphead] = data;
613
    UART1_TxHead = tmphead;
614
615
    /* enable UDRE interrupt */
616
    UART1_CONTROL    |= _BV(UART1_UDRIE);
617
618
}/* uart1_putc */
619
620
621
/*************************************************************************
622
Function: uart1_puts()
623
Purpose:  transmit string to UART1
624
Input:    string to be transmitted
625
Returns:  none          
626
**************************************************************************/
627
void uart1_puts(const char *s )
628
{
629
    while (*s) 
630
      uart1_putc(*s++);
631
632
}/* uart1_puts */
633
634
635
/*************************************************************************
636
Function: uart1_puts_p()
637
Purpose:  transmit string from program memory to UART1
638
Input:    program memory string to be transmitted
639
Returns:  none
640
**************************************************************************/
641
void uart1_puts_p(const char *progmem_s )
642
{
643
    register char c;
644
    
645
    while ( (c = pgm_read_byte(progmem_s++)) ) 
646
      uart1_putc(c);
647
648
}/* uart1_puts_p */
649
650
651
#endif
1
#ifndef UART_H
2
#define UART_H
3
/************************************************************************
4
Title:    Interrupt UART library with receive/transmit circular buffers
5
Author:   Peter Fleury <pfleury@gmx.ch>   http://jump.to/fleury
6
File:     $Id: uart.h,v 1.8.2.1 2007/07/01 11:14:38 peter Exp $
7
Software: AVR-GCC 4.1, AVR Libc 1.4
8
Hardware: any AVR with built-in UART, tested on AT90S8515 & ATmega8 at 4 Mhz
9
License:  GNU General Public License 
10
Usage:    see Doxygen manual
11
12
LICENSE:
13
    Copyright (C) 2006 Peter Fleury
14
15
    This program is free software; you can redistribute it and/or modify
16
    it under the terms of the GNU General Public License as published by
17
    the Free Software Foundation; either version 2 of the License, or
18
    any later version.
19
20
    This program is distributed in the hope that it will be useful,
21
    but WITHOUT ANY WARRANTY; without even the implied warranty of
22
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23
    GNU General Public License for more details.
24
    
25
************************************************************************/
26
27
/** 
28
 *  @defgroup pfleury_uart UART Library
29
 *  @code #include <uart.h> @endcode
30
 * 
31
 *  @brief Interrupt UART library using the built-in UART with transmit and receive circular buffers. 
32
 *
33
 *  This library can be used to transmit and receive data through the built in UART. 
34
 *
35
 *  An interrupt is generated when the UART has finished transmitting or
36
 *  receiving a byte. The interrupt handling routines use circular buffers
37
 *  for buffering received and transmitted data.
38
 *
39
 *  The UART_RX_BUFFER_SIZE and UART_TX_BUFFER_SIZE constants define
40
 *  the size of the circular buffers in bytes. Note that these constants must be a power of 2.
41
 *  You may need to adapt this constants to your target and your application by adding 
42
 *  CDEFS += -DUART_RX_BUFFER_SIZE=nn -DUART_RX_BUFFER_SIZE=nn to your Makefile.
43
 *
44
 *  @note Based on Atmel Application Note AVR306
45
 *  @author Peter Fleury pfleury@gmx.ch  http://jump.to/fleury
46
 */
47
 
48
/**@{*/
49
50
51
#if (__GNUC__ * 100 + __GNUC_MINOR__) < 304
52
#error "This library requires AVR-GCC 3.4 or later, update to newer AVR-GCC compiler !"
53
#endif
54
55
56
/*
57
** constants and macros
58
*/
59
60
/** @brief  UART Baudrate Expression
61
 *  @param  xtalcpu  system clock in Mhz, e.g. 4000000L for 4Mhz          
62
 *  @param  baudrate baudrate in bps, e.g. 1200, 2400, 9600     
63
 */
64
#define UART_BAUD_SELECT(baudRate,xtalCpu) ((xtalCpu)/((baudRate)*16l)-1)
65
66
/** @brief  UART Baudrate Expression for ATmega double speed mode
67
 *  @param  xtalcpu  system clock in Mhz, e.g. 4000000L for 4Mhz           
68
 *  @param  baudrate baudrate in bps, e.g. 1200, 2400, 9600     
69
 */
70
#define UART_BAUD_SELECT_DOUBLE_SPEED(baudRate,xtalCpu) (((xtalCpu)/((baudRate)*8l)-1)|0x8000)
71
72
73
/** Size of the circular receive buffer, must be power of 2 */
74
#ifndef UART_RX_BUFFER_SIZE
75
#define UART_RX_BUFFER_SIZE 32
76
#endif
77
/** Size of the circular transmit buffer, must be power of 2 */
78
#ifndef UART_TX_BUFFER_SIZE
79
#define UART_TX_BUFFER_SIZE 32
80
#endif
81
82
/* test if the size of the circular buffers fits into SRAM */
83
#if ( (UART_RX_BUFFER_SIZE+UART_TX_BUFFER_SIZE) >= (RAMEND-0x60 ) )
84
#error "size of UART_RX_BUFFER_SIZE + UART_TX_BUFFER_SIZE larger than size of SRAM"
85
#endif
86
87
/* 
88
** high byte error return code of uart_getc()
89
*/
90
#define UART_FRAME_ERROR      0x0800              /* Framing Error by UART       */
91
#define UART_OVERRUN_ERROR    0x0400              /* Overrun condition by UART   */
92
#define UART_BUFFER_OVERFLOW  0x0200              /* receive ringbuffer overflow */
93
#define UART_NO_DATA          0x0100              /* no receive data available   */
94
95
96
/*
97
** function prototypes
98
*/
99
100
/**
101
   @brief   Initialize UART and set baudrate 
102
   @param   baudrate Specify baudrate using macro UART_BAUD_SELECT()
103
   @return  none
104
*/
105
extern void uart_init(unsigned int baudrate);
106
107
108
/**
109
 *  @brief   Get received byte from ringbuffer
110
 *
111
 * Returns in the lower byte the received character and in the 
112
 * higher byte the last receive error.
113
 * UART_NO_DATA is returned when no data is available.
114
 *
115
 *  @param   void
116
 *  @return  lower byte:  received byte from ringbuffer
117
 *  @return  higher byte: last receive status
118
 *           - \b 0 successfully received data from UART
119
 *           - \b UART_NO_DATA           
120
 *             <br>no receive data available
121
 *           - \b UART_BUFFER_OVERFLOW   
122
 *             <br>Receive ringbuffer overflow.
123
 *             We are not reading the receive buffer fast enough, 
124
 *             one or more received character have been dropped 
125
 *           - \b UART_OVERRUN_ERROR     
126
 *             <br>Overrun condition by UART.
127
 *             A character already present in the UART UDR register was 
128
 *             not read by the interrupt handler before the next character arrived,
129
 *             one or more received characters have been dropped.
130
 *           - \b UART_FRAME_ERROR       
131
 *             <br>Framing Error by UART
132
 */
133
extern unsigned int uart_getc(void);
134
135
136
/**
137
 *  @brief   Put byte to ringbuffer for transmitting via UART
138
 *  @param   data byte to be transmitted
139
 *  @return  none
140
 */
141
extern void uart_putc(unsigned char data);
142
143
144
/**
145
 *  @brief   Put string to ringbuffer for transmitting via UART
146
 *
147
 *  The string is buffered by the uart library in a circular buffer
148
 *  and one character at a time is transmitted to the UART using interrupts.
149
 *  Blocks if it can not write the whole string into the circular buffer.
150
 * 
151
 *  @param   s string to be transmitted
152
 *  @return  none
153
 */
154
extern void uart_puts(const char *s );
155
156
157
/**
158
 * @brief    Put string from program memory to ringbuffer for transmitting via UART.
159
 *
160
 * The string is buffered by the uart library in a circular buffer
161
 * and one character at a time is transmitted to the UART using interrupts.
162
 * Blocks if it can not write the whole string into the circular buffer.
163
 *
164
 * @param    s program memory string to be transmitted
165
 * @return   none
166
 * @see      uart_puts_P
167
 */
168
extern void uart_puts_p(const char *s );
169
170
/**
171
 * @brief    Macro to automatically put a string constant into program memory
172
 */
173
#define uart_puts_P(__s)       uart_puts_p(PSTR(__s))
174
175
176
177
/** @brief  Initialize USART1 (only available on selected ATmegas) @see uart_init */
178
extern void uart1_init(unsigned int baudrate);
179
/** @brief  Get received byte of USART1 from ringbuffer. (only available on selected ATmega) @see uart_getc */
180
extern unsigned int uart1_getc(void);
181
/** @brief  Put byte to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_putc */
182
extern void uart1_putc(unsigned char data);
183
/** @brief  Put string to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_puts */
184
extern void uart1_puts(const char *s );
185
/** @brief  Put string from program memory to ringbuffer for transmitting via USART1 (only available on selected ATmega) @see uart_puts_p */
186
extern void uart1_puts_p(const char *s );
187
/** @brief  Macro to automatically put a string constant into program memory */
188
#define uart1_puts_P(__s)       uart1_puts_p(PSTR(__s))
189
190
/**@}*/
191
192
193
#endif // UART_H

gruß daniel

von Philipp (Gast)


Lesenswert?

Versuchs mal mit 38400 Baud, 57,xx kBaud liegt bei 16Mhz außerhalb der 
empfohlenen Toleranzgrenze.

PS.: Stell dich schon mal darauf ein, dass bald welche kommen und dir 
den Thread hier zerrupfen, weil du so viel Code zitiert hast...

von Daniel S. (sany)


Lesenswert?

Philipp schrieb:
> Versuchs mal mit 38400 Baud, 57,xx kBaud liegt bei 16Mhz außerhalb der
> empfohlenen Toleranzgrenze.
>
> PS.: Stell dich schon mal darauf ein, dass bald welche kommen und dir
> den Thread hier zerrupfen, weil du so viel Code zitiert hast...

Nun, also mit 38400 Klaapts ebenfalls nicht....

von Philipp (Gast)


Lesenswert?

Hmm, vielleicht liegts an den ** im Text, sollte mich aber wundern. 
Ansonsten verkleiner doch mal die delays oder nimm sie ganz raus, dann 
lässt sich das problem ein wenig eingrenzen

von Georg W. (gewe)


Lesenswert?

Ich würde mal sagen, Dein TX Puffer ist zu klein.

Du hast einen Puffer von 32 Bytes:

#define UART_TX_BUFFER_SIZE 32

Wie lang ist Dein erster Text ?

const char *text1 = "\f\a\n Diagnose Mobile Terminal V0.1 \r\n";
                                 1         2         3
                     1  2 345678901234567890123456789012345 6


Versuchs mal mit

#define UART_TX_BUFFER_SIZE 128

Außerdem liegen die Strings im RAM. Du kannst mit der Lib aber auch 
Texte aus dem Flash ausgeben. Das sollte mit uart1_puts_p(PSTR("STRING 
IM FLASH")) gehen.

cu
Georg

von Malte M. (maltem)


Lesenswert?

Georg W. schrieb:
> Ich würde mal sagen, Dein TX Puffer ist zu klein.

Dann würde aber mein vorgeschlagener Test mit "bla" "blubb" tun....

von Daniel S. (sany)


Lesenswert?

Philipp schrieb:
> Hmm, vielleicht liegts an den ** im Text, sollte mich aber wundern.
> Ansonsten verkleiner doch mal die delays oder nimm sie ganz raus, dann
> lässt sich das problem ein wenig eingrenzen

Wenn der AtMega8515 korrekt mit 16 Mhz läuft, müsste er genau 1sec bei 
1000ms warten, ist nur die Frage ob er das delay erreicht oder eben 
nicht. Das werde ich mal testen....
1
#include <stdlib.h>
2
#include <avr/io.h>
3
#include <avr/interrupt.h>
4
#include <util/delay.h>
5
#include "uart.h"
6
7
#define UART_BAUD_RATE      38400
8
9
int main(void)
10
{
11
12
  uart_init( UART_BAUD_SELECT(UART_BAUD_RATE,F_CPU) );
13
   
14
  sei();
15
16
  const char *text1 = "\f\a\n Diagnose Mobile Terminal V0.1 \r\n";
17
  const char *text2 = "** Kernel: 0.0.0.1\r\n";
18
  const char *text3 = "** Firmware: 0.0.0.1\r\n";
19
  while(1)
20
  {
21
    uart_puts("bla\r\n");
22
    uart_puts("jetzt gehts zum delay!\r\n");
23
      _delay_ms(10);
24
      uart_puts("blubb\r\n");
25
      _delay_ms(100);
26
    uart_puts("OK\r\n");
27
    _delay_ms(200);
28
    uart_puts("blaaa\r\n");
29
  }
30
}

HTerminal:
1
?bla<\r><\n> 
2
jetzt gehts zum delay!<\r><\n> (Die 10ms werden eingehalten)
3
blubb<\r><\n> (Auch die 100ms werden noch eingeladen=
4
OK<\r><\n> (Ab 200ms ist dann ende!)

von Ralph B. (rkhb)


Lesenswert?

Daniel Steiner schrieb:
> Das hat doch jetzt Primär mit dem Loop nichts zu tun,
> Fakt ist das nach uart_puts(text1) gar nichts mehr passiert, keine
> weiteren Texte!

Ich habe das mal mit einem ATmega8535 auf einem STK500 probiert - und es 
funktioniert. Es kann also nicht am Baudfehler, an zu kleinem SRAM oder 
an einem Programmierfehler liegen. Probier mal ein anderes 
Terminalprogramm und ein anderes Kabel aus.

Andererseits ist ein 16-MHz-Quarz für UART nicht ideal. Ideal für alle 
möglichen Baudraten sind:

1,8432 MHz, 3,6864 MHz, 7,3728 MHz, 11,0592 MHz und 14,7456 MHz

viele grüße
ralph

von Georg W. (gewe)


Lesenswert?

@Malte:

Stimmt. Aber hat er den Test auch wirklich gemacht?

@Daniel:

Wie viele Zeichen gehen in 110ms bei 57600Baud und 8N1 über die RS232 
raus?

Mach einfach doch mal den Test mit dem TX Puffer.

Ich hatte hier schon genau da selbe Problem.

cu
Georg

von Daniel S. (sany)


Lesenswert?

So, also mit dem Puffer auf 128 Gesetzt, aber ebenfalls leider kein 
Erfolg.

Nun dachte ich mir teste ich das ganze mal in dem ich einfach Pro 
Sekunden ein "A" auf mein LCD Display zeichnen lasse...
1
  while(1)
2
  {
3
    for(i=0; i< 8; i++)
4
    {
5
      lcd_gotoxy(i,1);
6
      lcd_puts("A");
7
      _delay_ms(1000);      
8
    }
9
  }

So und alles unter 100ms funktioniert, bei 1000ms hängt alles.
So nun dachte ich das evtl. der Atmega ein Pfiff weg hat, ersetzt => 
selbiges Problem... ebenfalls schon die Kondensatoren neu eingelötet => 
selbes problem...

Evtl. stimmt was bei den fuses nicht?

Der Quarz hat die Bezeichnung 14-US16,000MHZ

Danke :)

von Huch (Gast)


Lesenswert?

Kannst Du bitte mal schreiben, welche WinAVR-Version oder welche Version 
welchen Compilers sonst Du verwendest und welche Version der avr lib?

Ich habe zwar keinen konkreten Anhaltspunkt, aber das delay bei 200ms 
noch geht und dann nicht mehr, war, glaube ich bis zu einer bestimmten 
Version der lib so. Habe das jetzt nicht mehr so im Kopf. Aber die Suche 
hier sollte einen Haufen Einträge dazu bringen.

von Huch (Gast)


Lesenswert?

Ausserdem muss beim Compiler die Optimierung eingeschaltet sein.

von Daniel S. (sany)


Angehängte Dateien:

Lesenswert?

Hier mal die Einstellungen im Compiler und die aktuell Installierte 
WinAVR

von Karl H. (kbuchegg)


Lesenswert?

Georg W. schrieb:
> Ich würde mal sagen, Dein TX Puffer ist zu klein.

Spielt keine Rolle.
Die Fleury Lib ist so aufgebaut, dass das keine Rolle spielt.
Schlimmstenfalls wartet die put Routine, bis vom Sendeinterrupt die 
ersten Zeichen rausgeblasen wurden und so Platz im Buffer geschaffen 
wird


> Außerdem liegen die Strings im RAM. Du kannst mit der Lib aber auch
> Texte aus dem Flash ausgeben. Das sollte mit uart1_puts_p(PSTR("STRING
> IM FLASH")) gehen.

Das hab ich eher im Verdacht. Das ihm das SRAM ausgeht. 512 Bytes sind 
nicht allzuviel.
Obwohl es bei den delay Schleifen keine Rolle spielen sollte. Die werden 
komplett über Register abgewickelt.

Aber ich seh eigentlich auch nichts, ausser einer möglichen SRAM 
Überlastung. Aber das erklärt nicht, dass es bei kleinen _delays 
funktioniert. Seltsam.

Was sagt denn die Compiler-Statistik. Wie voll ist denn die .data 
Section?

von Philipp (Gast)


Lesenswert?

Ich benutz die gleiche Compilerversion und bei mir steht in der delay.h
1
   The maximal possible delay is 262.14 ms / F_CPU in MHz.
2
3
   When the user request delay which exceed the maximum possible one,
4
   _delay_ms() provides a decreased resolution functionality. In this
5
   mode _delay_ms() will work with a resolution of 1/10 ms, providing
6
   delays up to 6.5535 seconds (independent from CPU frequency).  The
7
   user will not be informed about decreased resolution.

ich würd mir ne eigene funktion schreiben, die in ner schleife so lange 
_delay_ms(10) aufruft, wie du's braucht.

von Georg W. (gewe)


Lesenswert?

Karl heinz Buchegger schrieb:

>> Ich würde mal sagen, Dein TX Puffer ist zu klein.
>
> Spielt keine Rolle.
>

Stimmt.

Ich habe den geposteten Code mal auf einen ATMEGA8515L, der in einem 
STK500 mit 16MHz Quarz läuft gespielt und ich bekomme die Texte im 
Hyperterminal angezeigt.


cu
Georg

von Daniel S. (sany)


Lesenswert?

Georg W. schrieb:
> Karl heinz Buchegger schrieb:
>
>>> Ich würde mal sagen, Dein TX Puffer ist zu klein.
>>
>> Spielt keine Rolle.
>>
>
> Stimmt.
>
> Ich habe den geposteten Code mal auf einen ATMEGA8515L, der in einem
> STK500 mit 16MHz Quarz läuft gespielt und ich bekomme die Texte im
> Hyperterminal angezeigt.
>
>
> cu
> Georg

Der Puffer spielt doch keinerlei Rolle, habs jetzt ebenfalls mal mit der 
Ausgabe auf einem LCD versucht, hat leider den selbigen Erfolg, nämlich 
das mehr als 100 ms nicht drin sind.

(Die .data Section ist aktuell bei 32% Full.

Also das Problem beschränkt sich nicht mehr nur auf das UART.

Der Schaltplan zum Atmega8515 TQFP/MLF: 
http://www.datasheetcatalog.org/datasheet/atmel/2512S.pdf

*) Hab mittlerweile nun den dritten Atmega 8515 ohne erfolg getestet.

Aber ich habe die ganz normale Grundbeschaltung mit einem 16 MHZ Quarz, 
mit 22pF auf GND.

Hab mittlerweile schon die 22pF gegen 33pF getauscht, ebenfalls schon 
den Quarz.

JTAG ist deaktiviert, kann es eventuell sein, das evtl. ein Port belegt 
ist, der den Microprozessor lahm legt?

Welche Ports müsste ich den Überprüfen, die den Programmablauf 
"irritieren" könnten?

Am Atmega8515 hängt noch ein AD822, sowie noch ein RS232 Trans/Receiver, 
jedoch nicht von Maxim selbst.

Vielen dank für Infos!

von Karl H. (kbuchegg)


Lesenswert?

Daniel Steiner schrieb:

> *) Hab mittlerweile nun den dritten Atmega 8515 ohne erfolg getestet.
>
> Aber ich habe die ganz normale Grundbeschaltung mit einem 16 MHZ Quarz,
> mit 22pF auf GND.
>
> Hab mittlerweile schon die 22pF gegen 33pF getauscht, ebenfalls schon
> den Quarz.
>
> JTAG ist deaktiviert, kann es eventuell sein, das evtl. ein Port belegt
> ist, der den Microprozessor lahm legt?

Kannst du dir alles sparen.
Mit ziemlicher Sicherheit ist das kein Hardwareproblem.

von Pete K. (pete77)


Lesenswert?

Hast Du jetzt schon einmal in der delay.h nachgeschaut?

Begrenze delay.h mal auf 200ms, das sollte klappen.

von Karl H. (kbuchegg)


Lesenswert?

Pete K. schrieb:
> Hast Du jetzt schon einmal in der delay.h nachgeschaut?
>
> Begrenze delay.h mal auf 200ms, das sollte klappen.

Die Beschränkung auf (2hundert_irgendwas durch Taktfrequenz) ist schon 
lange aufgehoben. Mein WinAVR ist um einiges älter und hat mit 1000ms 
keinerlei Probleme. Drum verblüfft das Ganze.

Man könnte das natürlich auf sich beruhen lassen, aber IMHO ist das ein 
Hinweis, das da irgendwas in der Konfiguration nicht ganz koscher ist. 
Von daher: Holzauge sei wachsam.

von Huch (Gast)


Lesenswert?

Es sollte auch mit 1000 gehen.
Und bei einigen Leuten hier geht es ja auch.

Ich würde vorschlagen einfach mal ne LED mit 1Hz zu toggeln (also 0,5Hz 
blinken). Alles andere rauswerfen.

von Pete K. (pete77)


Lesenswert?

Daniel Steiner schrieb:
> ?bla<\r><\n>
> jetzt gehts zum delay!<\r><\n> (Die 10ms werden eingehalten)
> blubb<\r><\n> (Auch die 100ms werden noch eingeladen=
> OK<\r><\n> (Ab 200ms ist dann ende!)

Den letzten String kannst Du nicht sehen, weil das Programm beendet 
wird, bevor die Interrupt-Ausgabe beendet ist.

Füge am Ende noch ein _delay_ms(30) ein.

von Huch (Gast)


Lesenswert?

Pete K. schrieb:
> Daniel Steiner schrieb:
> Den letzten String kannst Du nicht sehen, weil das Programm beendet
> wird, bevor die Interrupt-Ausgabe beendet ist.
>
> Füge am Ende noch ein _delay_ms(30) ein.

Das Pgm. wird nicht beendet. Da ist eine while Schleife.

von Daniel S. (sany)


Lesenswert?

Hmm..

Ich werde das mal testen und ggf. diesen Beitrag nochmal öffnen.
Mich verblüfft das ganze nur, weil ich hab in jeder Schaltung die 
gleiche Grundbeschaltung, außer das alle Micro's i.d.R mit einem Oszi 
laufen, und nicht mehr mit einem Quarz.

Ich werde das ganze nochmal überprüfen.

Was ich aber sagen muss, die Platine war bereits schon fertig und wurde 
von mir "übernommen". D.h es war auf der Platine ein NXP 87xxx drauf, 
der mit dem Atmel 8515 TQPF Original 1:1 PIN Kompatibel ist, ebenfalls 
stimmen die 5,00V durch den 7085, dass kann ich auch ausschließen.

Weiter kann ich nur vermuten, das irgendwas das Programm beendet, habs 
bereits schon mit aktiviertem WatchDog probiert, aber sobald ich die 
Fuse setzte, läuft garkein Programm mehr :/

Zumal mir solch ein Problem völlig neu ist, da nun von 15 AtMegas es nur 
jetzt diese probleme gibt.

Bitte melde dich an um einen Beitrag zu schreiben. Anmeldung ist kostenlos und dauert nur eine Minute.
Bestehender Account
Schon ein Account bei Google/GoogleMail? Keine Anmeldung erforderlich!
Mit Google-Account einloggen
Noch kein Account? Hier anmelden.