Forum: Mikrocontroller und Digitale Elektronik Unterschied ATMega 324A und 644


von Johannes D. (joed84)


Lesenswert?

Hi.

Ich habe 2 Mikrocontroller. Zum einen den ATMega644 und den ATMega324A.
Soweit ich weiß sollten die beiden sich nur dadurch unterscheiden das 
der 234A eine zweite Serielle Schnittstelle aber nur halb so viel Flash 
Speicher hat.

Ich habe das Programm zum Entprellen der Taster wie hier 
http://www.mikrocontroller.net/articles/Entprellung#Komfortroutine_.28C_f.C3.BCr_AVR.29 
kopiert und angepasst. Die richtigen Ports eingetragen, F_CPU auf 
8000000 gesetzt und die Register angepasst.
Als Takt nutze ich den internen Oszilator mit 8MHz.
Das ganze befindet sich auf einem STK500 und wird über AVRISP mkII 
programmiert.
Entwicklungsumgebung ist AVRStudio5.

Auf dem ATMega644 läuft es ohne Probleme. Auf dem ATMega324 funktioniert 
nichts. Es passiert nichts bei Tastendruck.
Fuses sind bei beiden gleich gesetzt und Device jeweils passend 
umgestellt.

Ich bin mittlerweile total Ratlos.

Vielen Dank für eure Antworten.

von Oliver J. (skriptkiddy)


Lesenswert?

Hast du neu kompiliert für den Atmega324p?

von Johannes D. (joed84)


Lesenswert?

Jupp.

von Steffen H. (avrsteffen)


Lesenswert?

Johannes D. schrieb:
> Soweit ich weiß sollten die beiden sich nur dadurch unterscheiden das
> der 234A eine zweite Serielle Schnittstelle aber nur halb so viel Flash
> Speicher hat.

Genau so ist es. Ich hab auch einfach ein Programm was ich vorher für 
den Mega644 hatte jetzt im Mega324 laufen. Genau wegen der 
2.Schnittstelle (USART1) Natürlich neu kopiliert mit dem richtigen 
Device-Eintrag.

Funktionierte auf Anhieb..

Vielleicht ist dein ATmega324 defekt?

von holger (Gast)


Lesenswert?

>Hast du neu kompiliert für den Atmega324p?
>Jupp.

Dann poste doch mal die beiden HEX Dateien.

von Johannes D. (joed84)


Angehängte Dateien:

Lesenswert?

So. Hier die beiden Hex Dateien. Gerade beide Frisch gebacken.
Wie gehabt. Auf dem 644 läufts. Auf dem 324 tut sich nichts.

Hier noch der Quelltext:
1
/************************************************************************/
2
/*                                                                      */
3
/*                      Debouncing 8 Keys                               */
4
/*                      Sampling 4 Times                                */
5
/*                      With Repeat Function                            */
6
/*                                                                      */
7
/*              Author: Peter Dannegger                                 */
8
/*                      danni@specs.de                                  */
9
/*                                                                      */
10
/************************************************************************/
11
 
12
#include <stdint.h>
13
#include <avr/io.h>
14
#include <avr/interrupt.h>
15
#include <avr/wdt.h>
16
 
17
#ifndef F_CPU
18
#define F_CPU           8000000                   // processor clock frequency
19
#warning kein F_CPU definiert
20
#endif
21
 
22
#define KEY_DDR         DDRA
23
#define KEY_PORT        PORTA
24
#define KEY_PIN         PINA
25
#define KEY0            0
26
#define KEY1            1
27
#define KEY2            2
28
#define ALL_KEYS        (1<<KEY0 | 1<<KEY1 | 1<<KEY2)
29
 
30
#define REPEAT_MASK     (1<<KEY1 | 1<<KEY2)       // repeat: key1, key2
31
#define REPEAT_START    50                        // after 500ms
32
#define REPEAT_NEXT     20                        // every 200ms
33
 
34
#define LED_DDR         DDRB
35
#define LED_PORT        PORTB
36
#define LED0            0
37
#define LED1            1
38
#define LED2            2
39
 
40
volatile uint8_t key_state;                                // debounced and inverted key state:
41
                                                  // bit = 1: key pressed
42
volatile uint8_t key_press;                                // key press detect
43
 
44
volatile uint8_t key_rpt;                                  // key long press and repeat
45
 
46
 
47
ISR( TIMER0_OVF_vect )                            // every 10ms
48
{
49
  static uint8_t ct0, ct1, rpt;
50
  uint8_t i;
51
 
52
  TCNT0 = (uint8_t)(int16_t)-(F_CPU / 1024 * 10e-3 + 0.5);  // preload for 10ms
53
 
54
  i = key_state ^ ~KEY_PIN;                       // key changed ?
55
  ct0 = ~( ct0 & i );                             // reset or count ct0
56
  ct1 = ct0 ^ (ct1 & i);                          // reset or count ct1
57
  i &= ct0 & ct1;                                 // count until roll over ?
58
  key_state ^= i;                                 // then toggle debounced state
59
  key_press |= key_state & i;                     // 0->1: key press detect
60
 
61
  if( (key_state & REPEAT_MASK) == 0 )            // check repeat function
62
     rpt = REPEAT_START;                          // start delay
63
  if( --rpt == 0 ){
64
    rpt = REPEAT_NEXT;                            // repeat delay
65
    key_rpt |= key_state & REPEAT_MASK;
66
  }
67
}
68
 
69
///////////////////////////////////////////////////////////////////
70
//
71
// check if a key has been pressed. Each pressed key is reported
72
// only once
73
//
74
uint8_t get_key_press( uint8_t key_mask )
75
{
76
  cli();                                          // read and clear atomic !
77
  key_mask &= key_press;                          // read key(s)
78
  key_press ^= key_mask;                          // clear key(s)
79
  sei();
80
  return key_mask;
81
}
82
 
83
///////////////////////////////////////////////////////////////////
84
//
85
// check if a key has been pressed long enough such that the
86
// key repeat functionality kicks in. After a small setup delay
87
// the key is reported being pressed in subsequent calls
88
// to this function. This simulates the user repeatedly
89
// pressing and releasing the key.
90
//
91
uint8_t get_key_rpt( uint8_t key_mask )
92
{
93
  cli();                                          // read and clear atomic !
94
  key_mask &= key_rpt;                            // read key(s)
95
  key_rpt ^= key_mask;                            // clear key(s)
96
  sei();
97
  return key_mask;
98
}
99
 
100
///////////////////////////////////////////////////////////////////
101
//
102
uint8_t get_key_short( uint8_t key_mask )
103
{
104
  cli();                                          // read key state and key press atomic !
105
  return get_key_press( ~key_state & key_mask );
106
}
107
 
108
///////////////////////////////////////////////////////////////////
109
//
110
uint8_t get_key_long( uint8_t key_mask )
111
{
112
  return get_key_press( get_key_rpt( key_mask ));
113
}
114
 
115
 
116
void WDT_Prescaler_Change(void)
117
{
118
  cli();
119
  wdt_reset();
120
  /* Start timed equence */
121
  WDTCSR |= (1<<WDCE) | (1<<WDE);
122
  /* Set new prescaler(time-out) value = 64K cycles (~0.5 s) */
123
  WDTCSR = (1<<WDE) | (1<<WDP3) | (1<<WDP0);
124
  sei();
125
}
126
127
void WDT_off(void)
128
{
129
  cli();
130
  wdt_reset();
131
  /* Clear WDRF in MCUSR */
132
  MCUSR &= ~(1<<WDRF);
133
  /* Write logical one to WDCE and WDE */
134
  /* Keep old prescaler setting to prevent unintentional time-out */
135
  WDTCSR |= (1<<WDCE) | (1<<WDE);
136
  /* Turn off WDT */
137
  WDTCSR = 0x00;
138
  sei();
139
}
140
141
void  led_lauflicht() {
142
  uint8_t i = LED_PORT;
143
  i = (i & 0x07) | ((i << 1) & 0xF0);
144
  if( i < 0xF0 )
145
  i |= 0x08;
146
  LED_PORT = i;        
147
}
148
149
 
150
int main( void )
151
{
152
  WDT_off();
153
154
  LED_DDR = 0xFF;
155
  LED_PORT = 0xFF;                     
156
 
157
  // Configure debouncing routines
158
  KEY_DDR &= ~ALL_KEYS;                // configure key port for input
159
  KEY_PORT |= ALL_KEYS;                // and turn on pull up resistors
160
 
161
  TCCR0B = (1<<CS02)|(1<<CS00);         // divide by 1024
162
  TCNT0 = (uint8_t)(int16_t)-(F_CPU / 1024 * 10e-3 + 0.5);  // preload for 10ms
163
  TIMSK0 |= 1<<TOIE0;                   // enable timer interrupt
164
 
165
  sei();
166
 
167
  while(1){
168
  
169
  //wdt_reset();
170
    if( get_key_short( 1<<KEY1 ))
171
      LED_PORT ^= 1<<LED1;
172
 
173
    if( get_key_long( 1<<KEY1 ))
174
      LED_PORT ^= 1<<LED2;
175
 
176
  //led_lauflicht();
177
    // single press and repeat
178
 
179
    if( get_key_press( 1<<KEY2 ) || get_key_rpt( 1<<KEY2 )){
180
      uint8_t i = LED_PORT;
181
 
182
      i = (i & 0x07) | ((i << 1) & 0xF0);
183
      if( i < 0xF0 )
184
        i |= 0x08;
185
      LED_PORT = i;      
186
    }
187
  }
188
}

Wie Wahrscheinlich ist es das 2 ATMega324 defekt sind?
Einfaches Einschalten der LEDs funktioniert übrigens.
Auch nicht entprellte Taster funktionieren. Nur wenn es was aufwendiger 
wird dann tut sich nichts mehr.

von Oliver J. (skriptkiddy)


Lesenswert?

Johannes D. schrieb:
> Wie Wahrscheinlich ist es das 2 ATMega324 defekt sind?
Sehr unwahrscheinlich.

Wirf doch einen UART an und mach damit an diversen Stellen des 
Programmes Debugausgaben.

von Johannes D. (joed84)


Lesenswert?

Werde ich morgen mal probieren.
Jetzt schonmal vielen Dank!

von Johannes D. (joed84)


Lesenswert?

Ich habe heute jetzt mal etwas anderes probiert.
Ich habe auf einem Laptop AVR Studio 4 aufgesetzt und damit das Beispiel 
noch mal neu geschrieben. Es dann per AVRISP mkII auf den ATMega324A 
kopiert.
So hat es funktioniert!

Also das Hex-File auf den USB Stick kopiert und am Desktop PC mittels 
des selben AVRISP mkII auf den ATMEga324A kopiert.
Das hat nicht funktioniert!

Jetzt die Frage. Wo könnte das Problem liegen? AVR-Studio5/AVRISP mkII? 
USB-Verbindung?
Und warum macht der ATMega644P mit der selben Kombination keine 
Probleme?

von Johannes D. (joed84)


Angehängte Dateien:

Lesenswert?

Ok. Kleine Korrektur. Am Programmer liegt es scheinbar doch nicht. Nach 
einem Reset des uC funktionierte das Hex File auch mit dem Programmer am 
Desktop Rechner.

Resümee:
Hex-File aus Studio4 funktioniert. (Atmega324_Test.hex)
Hex-File aus Studio5 funktioniert nicht. (ATMEGA_324A_Desktop.hex)
Bei selbem Quellcode.

Also bleibt jetzt nur noch AVR-Studio5 bzw. Einstellungen dort übrig.

Ich hänge mal die verschiedenen Hex-Files und die Konsolenausgabe von 
STudio5 an.

____________
1
------ Build started: Project: ATMEGA_324A_Desktop, Configuration: Debug AVR ------
2
Build started.
3
Project "ATMEGA_324A_Desktop.avrgccproj" (default targets):
4
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
5
Target "CoreBuild" in file "C:\Programme\Atmel\AVR Studio 5.0\Vs\AvrGCC.targets" from project "C:\Dokumente und Einstellungen\labor.RAC85129\Eigene Dateien\AVRStudio\ATMEGA_324A_Desktop\ATMEGA_324A_Desktop\ATMEGA_324A_Desktop.avrgccproj" (target "Build" depends on it):
6
  Task "RunAvrGCC"
7
    C:\Programme\Atmel\AVR Studio 5.0\AVR ToolChain\bin\make.exe all 
8
ATMEGA_324A_Desktop.c
9
    Invoking: AVR/GNU C Compiler
10
    "C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe" -funsigned-char -funsigned-bitfields -DF_CPU=8000000  -Os -fpack-struct -fshort-enums -Wall -c -std=gnu99  -mmcu=atmega324a   -MD -MP -MF"ATMEGA_324A_Desktop.d" -MT"ATMEGA_324A_Desktop.d" -o"ATMEGA_324A_Desktop.o" ".././ATMEGA_324A_Desktop.c"
11
    Finished building: .././ATMEGA_324A_Desktop.c
12
    Building target: ATMEGA_324A_Desktop.elf
13
    Invoking: AVR/GNU C/C++ Linker
14
    "C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-gcc.exe"  -mmcu=atmega324a  -Wl,-Map=ATMEGA_324A_Desktop.map -o ATMEGA_324A_Desktop.elf  ATMEGA_324A_Desktop.o  
15
    Finished building target: ATMEGA_324A_Desktop.elf
16
    "C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature  "ATMEGA_324A_Desktop.elf" "ATMEGA_324A_Desktop.hex"
17
    "C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objdump.exe" -h -S "ATMEGA_324A_Desktop.elf" > "ATMEGA_324A_Desktop.lss"
18
    "C:/Programme/Atmel/AVR Studio 5.0/AVR ToolChain/bin/avr-objcopy.exe" -j .eeprom --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0 --no-change-warnings -O ihex "ATMEGA_324A_Desktop.elf" "ATMEGA_324A_Desktop.eep" || exit 0
19
    AVR Memory Usage
20
    ----------------
21
    Device: atmega324a
22
    Program:     502 bytes (1.5% Full)
23
    (.text + .data + .bootloader)
24
    Data:          6 bytes (0.3% Full)
25
    (.data + .bss + .noinit)
26
  Done executing task "RunAvrGCC".
27
Done building target "CoreBuild" in project "ATMEGA_324A_Desktop.avrgccproj".
28
Target "PostBuildEvent" skipped, due to false condition; ('$(PostBuildEvent)' != '') was evaluated as ('' != '').
29
Target "Build" in file "C:\Programme\Atmel\AVR Studio 5.0\Vs\Avr.common.targets" from project "C:\Dokumente und Einstellungen\labor.RAC85129\Eigene Dateien\AVRStudio\ATMEGA_324A_Desktop\ATMEGA_324A_Desktop\ATMEGA_324A_Desktop.avrgccproj" (entry point):
30
Done building target "Build" in project "ATMEGA_324A_Desktop.avrgccproj".
31
Done building project "ATMEGA_324A_Desktop.avrgccproj".
32
33
Build succeeded.
34
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

von Johannes D. (joed84)


Lesenswert?

Ich habe das Problem gelöst!

Ein wechsel der internen Toolchain zu der von WinAVR hat das Problem 
beseitigt.

Weiterhin die Frage, woran kann das liegen? Ein Bug in den Bibliotheken/ 
der Toolchain von Atmel?

Oder gibt es da noch irgendetwas das ich übersehen habe?

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.