Forum: Mikrocontroller und Digitale Elektronik Displayplatine Problem mit SPI DOGL128-6


von CG (Gast)


Angehängte Dateien:

Lesenswert?

Hallo zusammen,
hoffe mir kann jemand helfen.
Ich habe eine Displayplatine mit einem ATMEGA32A und einem DOGL128-6 
aufgebaut jedoch tauchen leider ein paar Probleme beim Display auf.

Ich schaffe es das Display zu inizialisieren und anschließend drei mal 
eine Ausgabe aufs Display zu schreiben. Anschließend hängt sich mein 
Programm an der Stelle
1
while(! (SPSR & (1<<SPIF)));  // warten bis die Übertragung beendet ist
auf. (Habe ich mit den LED's kontrolliert)

Kann es sein das ich auch ein Hardwarefehler habe? Oder mache ich was in 
der Software falsch?

Verwendeter Microcontroller ATMEGA32A mit 16MHz
gesetzte Fuses:
JTAGEN, SPIEN
Bootsz -> Boot Flash size=2048 words start address=$3800
BODLEVEL -> Brown-out detection at VCC=2,7V
SUT_CKSEL -> Ext. Crystal/Resonator High Freq Start-up time: 16K CK 
+64ms


Hoffe mir kann da jemand helfen. :-)
Falls Eckdaten fehlen sollten bitte einfach bescheid sagen

Zum Code:
1
/*
2
 * SoftwareTerrariumDisplay.c
3
 *
4
 * Created: 23.09.2014 09:04:12
5
 *  Author: u308488
6
 */ 
7
#define F_CPU 16000000
8
9
#include <avr/io.h>      // Header-Datei f. IO-Register
10
#include <avr/interrupt.h>  // Header-Datei f. Interruptfunktion
11
#include <stdint.h>         // Header-Datei f. standard Datentypen
12
#include <avr/pgmspace.h>
13
#include <util/delay.h>
14
15
#include "SoftwareTerrariumDisplay.h"
16
#include "Treiber/eadog128-6.h"
17
18
/********************************************************************************
19
Function Prototypes
20
********************************************************************************/
21
void initPort(void);
22
23
/********************************************************************************
24
Variablen
25
********************************************************************************/
26
int zustand_taster1, zustand_taster2, zustand_taster3, zustand_taster4, zustand_taster5;
27
int i, count;
28
29
/********************************************************************************
30
Main Programm
31
********************************************************************************/
32
int main(void)
33
{
34
  initPort();          // Portinitalisierung
35
  display_init();        // Inizialisierung Display
36
  
37
  SET_LED_TASTER_HIGH;
38
  SET_DISPLAY_BRIGHTNESS_ON; //Hintergrundbeleuchung einschalten
39
  
40
    while(1)
41
    {
42
    SWITCH_LED1;  
43
    display_write("TEST",0,1);  
44
    _delay_ms(500);
45
  }
46
}
47
48
/********************************************************************************
49
PortInizialisierung
50
********************************************************************************/
51
void initPort(void)
52
{    
53
  // Portinitialisierung LED1 bis 3 definiren
54
  DDR_LED |= (1<<PIN_LED1) | (1<<PIN_LED2) | (1<<PIN_LED3); // LED's als Ausganggang definieren
55
  CLEAR_LED1;  // LED1 ausschalten 
56
  CLEAR_LED2; // LED2 ausschalten
57
  CLEAR_LED3; // LED3 ausschalten
58
  
59
  // Portinitialisierung Tasterhintergrundbeleuchtung 
60
  DDR_V_LED_TASTER |=  (1<<PIN_V_LED_TASTER); // als Ausganggang definieren
61
  CLEAR_LED_TASTER_HIGH;  // Hintergrundbeleuchtung ausschalten 
62
  
63
  // Portinitialisierung Taster 
64
  DDR_TASTER &= ~(1<<PIN_TASTER1) | (1<<PIN_TASTER2) | (1<<PIN_TASTER3) | (1<<PIN_TASTER4) | (1<<PIN_TASTER5)  ; // als Eingang definieren
65
}
66
67
/*
68
 * SoftwareTerrariumDisplay.h
69
 *
70
 * Created: 22.01.2015 09:29:02
71
 *  Author: u308488
72
 */ 
73
74
75
#ifndef GLOABAL_H_
76
#define GLOABAL_H_
77
#define F_CPU 16000000
78
//const PROGMEM char pic1[] = LOGO;
79
80
//V_LED_TASTER PC7
81
#define PORT_V_LED_TASTER      PORTA
82
#define DDR_V_LED_TASTER       DDRA
83
#define PIN_V_LED_TASTER       4    //PA4
84
#define SET_LED_TASTER_HIGH    PORT_V_LED_TASTER |= (1<<PIN_V_LED_TASTER)    // LED Hintergurndbeleuchtung an
85
#define CLEAR_LED_TASTER_HIGH  PORT_V_LED_TASTER &= ~(1<<PIN_V_LED_TASTER)    // LED Hintergurndbeleuchtung aus
86
87
//LED Pins
88
#define PORT_LED        PORTA
89
#define DDR_LED         DDRA
90
#define PIN_LED1         7    //PA7
91
#define PIN_LED2         6    //PA6
92
#define PIN_LED3         5    //PA5
93
#define SET_LED1      PORT_LED &= ~(1<<PIN_LED1);
94
#define SET_LED2      PORT_LED &= ~(1<<PIN_LED2);
95
#define SET_LED3      PORT_LED &= ~(1<<PIN_LED3);
96
#define CLEAR_LED1      PORT_LED |= (1<<PIN_LED1);
97
#define CLEAR_LED2      PORT_LED |= (1<<PIN_LED2);
98
#define CLEAR_LED3      PORT_LED |= (1<<PIN_LED3);
99
#define SWITCH_LED1      PORT_LED ^= (1 << PIN_LED1);    // LED1 umschalten
100
#define SWITCH_LED2      PORT_LED ^= (1 << PIN_LED2);    // LED2 umschalten
101
#define SWITCH_LED3      PORT_LED ^= (1 << PIN_LED3);    // LED3 umschalten
102
103
// TASTER Pins
104
#define PORT_TASTER      PORTC
105
#define DDR_TASTER      DDRC
106
#define PIN_TASTER_EINGANG  PINC
107
#define PIN_TASTER1      7    // PC7
108
#define PIN_TASTER2      6    // PC6
109
#define PIN_TASTER3      5    // PC5
110
#define PIN_TASTER4      4    // PC4
111
#define PIN_TASTER5      3    // PC3
112
113
// ###############  Pinfestlegung Display
114
//A0 Port
115
#define PORT_A0        PORTB
116
#define DDR_A0         DDRB
117
#define PIN_A0         2    //PB2
118
119
//Reset Port
120
#define PORT_RST       PORTB
121
#define DDR_RST        DDRB
122
#define PIN_RST        3    //PB3
123
124
//SPI Port
125
#define PORT_SPI      PORTB
126
#define DDR_SPI        DDRB
127
#define PIN_SPI_CS1B    0    //PB0
128
#define PIN_SPI_CS3      4    //PB4
129
#define PIN_SPI_MOSI    5    //PB5
130
#define PIN_SPI_MISO    6    //PB6  
131
#define PIN_SPI_SCK      7    //PB7  
132
133
//Hintergrundbeleuchtung PWM
134
#define BRIGHTNESS_PWM_DDR        DDRD
135
#define BRIGHTNESS_PWM_PORT        PORTD
136
#define BRIGHTNESS_PWM_PIN        7    //PD7
137
#define SET_DISPLAY_BRIGHTNESS_OFF    BRIGHTNESS_PWM_PORT &= ~(1<<BRIGHTNESS_PWM_PIN)  // Hintergrundbeleuchtung OFF
138
#define SET_DISPLAY_BRIGHTNESS_ON    BRIGHTNESS_PWM_PORT |=(1<<BRIGHTNESS_PWM_PIN) // Hintergrundbeleuchtung ON
139
140
#endif /* GLOABAL_H_ */
141
142
/*
143
 * eadog128_6.h
144
 *
145
 * Created: 22.01.2015 09:17:18
146
 *  Author: Dipl.- Ing. C. Graci
147
 */ 
148
149
150
#ifndef EADOG128_6_H_
151
#define EADOG128_6_H_
152
153
154
#define DISPLAY_OFFSET    4  
155
  
156
#define LINE1        5      
157
  
158
#define LINE2        1
159
  
160
//size of the LCD
161
#define LCD_WIDTH      128
162
#define LCD_HEIGHT      64
163
  
164
// ###############  Funkions
165
void display_init(void);
166
void display_write_byte(unsigned cmd_data, unsigned char data);
167
void display_clear(void);
168
void display_go_to (unsigned char x, unsigned char y);
169
void display_write(unsigned char *string, int x, int y);
170
171
volatile unsigned char char_x,char_y,char_height_mul,char_width_mul;
172
173
  
174
175
//write to lc-display command or data register
176
#define CMD    1
177
#define DATA  0
178
  
179
//Befehlstabelle EA DOGM128-6 Seite 5
180
// (1) Display ON/OFF
181
#define DISPLAY_ON             0xAF  //LCD_DISPLAY_ON
182
#define DISPLAY_OFF            0xAE  //LCD_DISPLAY_OFF
183
184
// (3) Page address set
185
#define DISPLAY_PAGE_ADDRESS    0xB0
186
187
// (4) Column address set upper bit
188
#define DISPLAY_COL_ADDRESS_MSB    0x10
189
// (4) Column address set lower bit
190
#define DISPLAY_COL_ADDRESS_LSB    0x00  
191
192
// (5) Status read (doesn't work in SPI mode)
193
194
// (6) Display data write
195
  
196
// (7) Display data read (doesn't work in SPI mode)
197
  
198
// (8) ADC select
199
#define DISPLAY_BOTTOMVIEW      0xA0  
200
#define DISPLAY_TOPVIEW        0xA1  
201
202
// (9) Display normale/reverse
203
#define DISPLAY_NORMAL         0xA6
204
#define DISPLAY_REVERSE        0xA7
205
206
// (10) Display all points ON/OFF
207
#define DISPLAY_SHOW_NORMAL      0xA4
208
#define DISPLAY_SHOW_ALL_POINTS    0xA5
209
210
// (11) LCD bias set
211
#define DISPLAY_BIAS_1_9      0xA2
212
#define DISPLAY_BIAS_1_7      0xA3
213
214
// (12) Read-modify-write (doesn't work in SPI mode)
215
216
// (13) End clear read/modify/write (doesn't work in SPI mode)
217
218
// (14) RESET
219
#define DISPLAY_RESET_CMD      0xE2
220
221
// (15) Common output mode select
222
#define DISPLAY_SCAN_DIR_NORMAL    0xC0  
223
#define DISPLAY_SCAN_DIR_REVERSE  0xC8  
224
225
// (16) Power control set
226
#define DISPLAY_POWER_CONTROL    0x28
227
#define DISPLAY_POWER_LOW_POWER    0x2F
228
#define DISPLAY_POWER_WIDE_RANGE  0x2F 
229
#define DISPLAY_POWER_LOW_VOLTAGE  0x2B 
230
231
// (17) V0 voltage regulator internal resistor ratio set
232
#define DISPLAY_VOLTAGE            0x20
233
234
// (18) Electronic volume mode set
235
#define DISPLAY_VOLUME_MODE_1      0x81
236
// (18) Register
237
#define DISPLAY_VOLUME_MODE_2      0x00
238
239
// (19) Static indicator ON/OFF
240
#define DISPLAY_INDICATOR_ON         0xAD  
241
#define DISPLAY_INDICATOR_OFF        0xAC  
242
// (19) Static indicator register set
243
#define DISPLAY_INDICATOR_MODE_OFF   0x00
244
#define DISPLAY_INDICATOR_MODE_1HZ   0x01
245
#define DISPLAY_INDICATOR_MODE_2HZ   0x10
246
#define DISPLAY_INDICATOR_MODE_ON    0x11
247
248
// (20) Booster ratio set
249
#define DISPLAY_BOOSTER_SET        0xF8
250
#define DISPLAY_BOOSTER_234        0x00
251
#define DISPLAY_BOOSTER_5          0x01
252
#define DISPLAY_BOOSTER_6          0x03
253
254
// (21) Power save
255
256
// (22) NOP
257
#define LCD_NOP                  0xE3
258
259
#endif /* EADOG128_6_H_ */
260
261
/*
262
 * eadog128_6.c
263
 *
264
 * Created: 22.01.2015 09:17:05
265
 *  Author: Dipl.- Ing. C. Graci
266
 */ 
267
268
269
#include <avr/interrupt.h>
270
#include <avr/pgmspace.h>
271
#include <avr/io.h>
272
#include <stdlib.h>
273
#include <stdarg.h>
274
#include <ctype.h>
275
#include <string.h>
276
277
#include "eadog128-6.h"
278
#include "font.h"
279
#include "../SoftwareTerrariumDisplay.h"
280
281
//##############################################################################################
282
//Init LC-Display
283
//##############################################################################################
284
void display_init(void)
285
{
286
  //Set TIMER0 (PWM OC2 Pin)
287
/*
288
  BRIGHTNESS_PWM_DDR |= (1<<BRIGHTNESS_PWM_PIN);//PWM PORT auf Ausgang (OC2)
289
  TCCR2 |= (1<<WGM21|1<<WGM20|1<<COM21|1<<CS20);  
290
  OCR2 = 50;
291
*/  
292
  //set outputs AO und RESET
293
  DDR_A0  |= (1<<PIN_A0);             
294
  DDR_RST |= (1<<PIN_RST);
295
  
296
  //Set SPI PORT
297
  DDR_SPI |= (1<<PIN_SPI_SCK)|(1<<PIN_SPI_MOSI)|(1<<PIN_SPI_CS1B);
298
  PORT_SPI |= (1<<PIN_SPI_CS1B);
299
  //Enable SPI, SPI in Master Mode
300
  SPCR = (1<<SPE)|(1<<MSTR);   
301
 
302
    //Reset the Display Controller
303
  PORT_RST &= ~(1<<PIN_RST);                   
304
  PORT_RST |= (1<<PIN_RST);
305
//  asm("nop");
306
  
307
  // init commands to Display
308
/*  display_write_byte(CMD, 0x40);    // set display start line to 0 
309
  display_write_byte(CMD, 0xa1);    // ADC set to reverse 
310
  display_write_byte(CMD, 0xc0);    // common output mode  
311
  display_write_byte(CMD, 0xa6);    // display normal
312
  display_write_byte(CMD, 0xa2);    // LCD bias 1/9 
313
  display_write_byte(CMD, 0x2f);    // all power  control circuits on 
314
  display_write_byte(CMD, 0xf8);    // set booster ratio to 
315
  display_write_byte(CMD, 0x00);    // 4x 
316
  display_write_byte(CMD, 0x27);    // set V0 voltage resistor ratio to large
317
  display_write_byte(CMD, 0x81);    // set contrast 
318
  display_write_byte(CMD, 0x10);    // contrast value, EA default: 0x016 
319
  display_write_byte(CMD, 0xac);    // indicator 
320
  display_write_byte(CMD, 0x00);    // disable 
321
  display_write_byte(CMD, 0xaf);    // display on 
322
*/    
323
  display_write_byte(CMD, 0x40);    // set display start line to 0 
324
  display_write_byte(CMD, 0xa0);    // ADC set to not reverse 
325
  display_write_byte(CMD, 0xc8);    // common output mode 
326
  display_write_byte(CMD, 0xa6);    // display normal, bit val 0: LCD pixel off. 
327
  display_write_byte(CMD, 0xa2);    // LCD bias 1/9 
328
  display_write_byte(CMD, 0x2f);    // all power  control circuits on 
329
  display_write_byte(CMD, 0xf8);    // set booster ratio to 
330
  display_write_byte(CMD, 0x00);    // 4x 
331
  display_write_byte(CMD, 0x27);    // set V0 voltage resistor ratio to large
332
  display_write_byte(CMD, 0x81);    // set contrast 
333
  display_write_byte(CMD, 0x18);    // contrast value, EA default: 0x016 
334
  display_write_byte(CMD, 0xac);    // indicator 
335
  display_write_byte(CMD, 0x00);    // disable 
336
  display_write_byte(CMD, 0xaf);    // display on 
337
  
338
  display_clear();
339
  
340
  display_go_to(0,0);
341
}
342
343
//##############################################################################################
344
//Writes one byte to data or cmd register
345
//##############################################################################################
346
void display_write_byte(unsigned cmd_data, unsigned char data) 
347
{
348
  PORT_SPI &= ~(1<<PIN_SPI_CS1B);
349
  _delay_us(10);
350
  if(cmd_data == 0)
351
  {
352
    PORT_A0 |= (1<<PIN_A0);
353
  }
354
  else
355
  {
356
    PORT_A0 &= ~(1<<PIN_A0);
357
  }
358
  _delay_us(10);
359
  SPDR = data;
360
  while(! (SPSR & (1<<SPIF)));  // warten bis die Übertragung beendet ist
361
//  spi_send (data, PIN_SPI_CS1B);
362
  PORT_SPI |= (1<<PIN_SPI_CS1B);
363
  _delay_us(10);
364
}
365
366
/********************************************************************************
367
Function to clear Display
368
********************************************************************************/
369
void display_clear(void)
370
{
371
  unsigned char page, col;
372
  
373
  for(page=0;page<8;page++) 
374
  {
375
    display_go_to(1,page);
376
  
377
    for (col=0;col<LCD_WIDTH;col++)
378
    {
379
      display_write_byte(0,0x00);
380
    }
381
  }
382
  display_go_to(0,0);
383
}
384
385
/********************************************************************************
386
Function to go to x,y
387
********************************************************************************/
388
void display_go_to (unsigned char x, unsigned char y)
389
{
390
  // x = x + 4;  // offset von 4 mit einrechnen
391
  display_write_byte(1,DISPLAY_PAGE_ADDRESS | ((y) & 0x0F));
392
  display_write_byte(1,DISPLAY_COL_ADDRESS_MSB | ((x>>4) & 0x0F));
393
  display_write_byte(1,DISPLAY_COL_ADDRESS_LSB | ((x) & 0x0F));
394
  return;
395
}
396
397
/********************************************************************************
398
Ausgabe einer Zeichenkette
399
********************************************************************************/
400
void display_write(unsigned char *string, int x, int y)
401
{
402
  char data[128];
403
  int i;
404
  x = x + 4;  // offset von 4 mit einrechnen
405
  display_go_to(x,y);    // an Stelle x,y springen
406
407
  for(i=0; i<128; i++)  // Datenspeicher löschen
408
  {
409
    data[i] = 0x00;
410
  }
411
  
412
  for(i=0; i<strlen(string); i++) // Umwandlung in Grafikzeichen
413
  {
414
    memcpy(data + 8*i, cs[string[i]], 8);
415
  }
416
  
417
  for(i=0; i<128; i++)  // Schreiben der Daten ans Display
418
  {
419
    display_write_byte(0, data[i]);
420
  }
421
}

von spess53 (Gast)


Lesenswert?

Hi

>#define PIN_SPI_CS3      4    //PB4

Das wird im Programm nicht verwendet und hängt, wenn ich nichts 
übersehen habe, in der Schaltung in der Luft. Da das aber das SS-Pin vom 
SPI ist und es auf Eingang liegt, kann es passieren, das das SPI durch 
Einstreuungen auf den Pin in den Slave-Mode wechselt. Siehe Datenblatt:

 19.3 SS Pin Functionality

MfG Spess

von dummy (Gast)


Lesenswert?

>Anschließend hängt sich mein
>Programm an der Stelle
>
>while(! (SPSR & (1<<SPIF)));  // warten bis die Übertragung beendet ist
>
>auf.

Das passiert wenn der SS Pin kein Ausgang ist.

von CG (Gast)


Lesenswert?

Oh mann danke für eure Hilfe
das war der Fehler :-)
Hab es gerade ausprobiert und siehe da es geht.... das habe ich ganz 
übersehen!
Super dankeschön :-)

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.