OLED Display ssd1306 mit SPI arbeitet nicht

OP #4343693
Lesenswert?

Hallo,

ich versuche gerade das OLED Display 128x64 (SSD106 Controller) über SPI 
mit einem ATMega88 in Betrieb zu nehmen.

Dafür verwende ich die Library u8glib:
https://code.google.com/p/u8glib/wiki/avr

mit dem Beispielcode:
1
#include "u8g.h"
2
#include <avr/interrupt.h>
3
#include <avr/io.h>
4

5
u8g_t u8g;
6

7
void draw(void)
8
{
9
  u8g_SetFont(&u8g, u8g_font_6x10);
10
  u8g_DrawStr(&u8g, 0, 15, "Hello World!");
11
}
12

13
int main(void)
14
{
15
  /* select minimal prescaler (max system speed) */
16
  CLKPR = 0x80;
17
  CLKPR = 0x00;
18
  /*
19
    CS: PORTB, Bit 2 --> PN(1,2)
20
    A0: PORTB, Bit 1 --> PN(1,1)
21
    SCK: PORTB, Bit 5 --> PN(1,5)
22
    MOSI: PORTB, Bit 3 --> PN(1,3)
23
  */
24
  u8g_InitSPI(&u8g, &u8g_dev_st7565_dogm132_sw_spi, PN(1, 5), PN(1, 3), PN(1, 2), PN(1, 1), U8G_PIN_NONE);
25

26
  for(;;)
27
  {  
28
    u8g_FirstPage(&u8g);
29
    do
30
    {
31
      draw();
32
    } while ( u8g_NextPage(&u8g) );
33
    u8g_Delay(100);
34
  } 
35
}

Die Libraries habe ich wie beschrieben in Atmel Studio 6 eingebunden. 
Kompilierung klappt, aber das Display bleibt finster. Ich habe hier die 
SW-SPI und die HW-SPI probiert, leider ohne Erfolg.

Anbei meine Beschaltung der Pins zwischen UC und Display.
Angehängte Dateien:
OP #4343773
Lesenswert?

m. g. schrieb:
> spess53 schrieb:
>> Hi
>>
>>>&u8g_dev_st7565_dogm132_sw_spi
>>
>> Woher kommt diese Angabe? Du hast weder einen ST7565 Displaycontroller
>> noch ein 132x32 Display.
>>
>> MfG Spess

Ich habe die Funktion nun angepasst und mit SW-SPI und HW-SPI getestet.

SW-SPI:
1
u8g_InitSPI(&u8g, &u8g_dev_ssd1306_128x64_sw_spi, PN(1, 5), PN(1, 3), PN(1, 2), PN(1, 1), U8G_PIN_NONE);

HW-SPI:
1
u8g_InitSPI(&u8g, &u8g_dev_ssd1306_128x64_hw_spi, PN(1, 5), PN(1, 3), PN(1, 2), PN(1, 1), U8G_PIN_NONE);

Kompilierung OK, Display noch dunkel.
Gast #4343859
Lesenswert?

Hi

Passt denn deine Beschaltung? Das hier

>    CS: PORTB, Bit 2 --> PN(1,2)
>    A0: PORTB, Bit 1 --> PN(1,1)

stimmt für das DOG-Display. Du hast aber RESET und D/C.

>Kompilierung OK, Display noch dunkel.

Da ich weder Display noch Library kenne, kann ich da auch nicht weiter 
helfen.

MfG Spess
OP #4343953
Lesenswert?

spess53 schrieb:
> Hi
>
> Passt denn deine Beschaltung? Das hier
>
>>    CS: PORTB, Bit 2 --> PN(1,2)
>>    A0: PORTB, Bit 1 --> PN(1,1)
>
> stimmt für das DOG-Display. Du hast aber RESET und D/C.
>
>>Kompilierung OK, Display noch dunkel.
>
> Da ich weder Display noch Library kenne, kann ich da auch nicht weiter
> helfen.
>
> MfG Spess

Ich verwende genau dieses Display:
http://www.icstation.com/icstation-blue-oled-display-screen-module-p-3803.html

Die blaue Version hat wie hier beschrieben
http://www.icstation.com/icstation-blue-oled-display-screen-module-p-3760.html
den SH1106 als Controller.

Ich verwende die u8glib Library, download hier:
http://www.icstation.com/icstation-blue-oled-display-screen-module-p-3803.html

Den ATMega88 habe ich mit dem Display wie folgt verbunden:

UC         Display
SCK        SCK
MOSI       MOSI
A0 (PB1)   D/C
OP #4345212
Lesenswert?

Michael U. schrieb:
> Hallo,
>
> ich bin jetzt nicht sicher, aber ein Bekannter hat ein 0,96" OLED, das
> startete meist garnicht, es wollte unbedingt eine passenden Reset-Impuls
> nach PowerOn.


Michaels Hinweis war ein Treffer! Das Display funktioniert!
Lt. Datenblatt verlangt das Display einen Resetpuls (>10us) nach dem 
Power ON. Mit dem Portpin PB0 ziehe ich den RST kurz auf GND und schon 
funktioniert das Display!

Hier der angepasste Code (HW-SPI und SW-SPI wurde getestet) aus der 
u8g_lib von olikraus.
1
/*
2
  main.c 
3
  
4
  Hello World for ATMEGA Controller
5

6
  Universal 8bit Graphics Library
7
  
8
  Copyright (c) 2012, olikraus@gmail.com
9
  All rights reserved.
10

11
  Redistribution and use in source and binary forms, with or without modification, 
12
  are permitted provided that the following conditions are met:
13

14
  * Redistributions of source code must retain the above copyright notice, this list 
15
    of conditions and the following disclaimer.
16
    
17
  * Redistributions in binary form must reproduce the above copyright notice, this 
18
    list of conditions and the following disclaimer in the documentation and/or other 
19
    materials provided with the distribution.
20

21
  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND 
22
  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, 
23
  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
24
  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
25
  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR 
26
  CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
27
  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 
28
  NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 
29
  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
30
  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 
31
  STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
32
  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
33
  ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.  
34
  
35
*/
36

37
#include "u8g.h"
38

39
#if defined(__AVR__)
40
#include <avr/interrupt.h>
41
#include <avr/io.h>
42
#endif
43

44
/* 
45
  Software SPI:
46
  uint8_t u8g_InitSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t sck, uint8_t mosi, uint8_t cs, uint8_t a0, uint8_t reset); 
47

48
  Hardware SPI:
49
  uint8_t u8g_InitHWSPI(u8g_t *u8g, u8g_dev_t *dev, uint8_t cs, uint8_t a0, uint8_t reset);
50

51
  Visit 
52
    http://code.google.com/p/u8glib/wiki/device 
53
  for a list of valid devices (second argument of the constructor).
54

55
  The following examples will use the SH1106 device: u8g_dev_sh1106_128x64_sw_spi
56
  Note: The device must match the setup: For example, do not use a sw_spi device with u8g_InitHWSPI().
57
*/
58

59
u8g_t u8g;
60

61
void u8g_setup(void)
62
{  
63
  /*
64
    Test Envionment:
65
  Microcontroller:  ATMEL ATMEGA88 @ 8MHz 
66
  Display:      OLED LCD 128x64 (blue) with SH1106 controller
67
    CS:    PORTB, Bit 2  --> not used
68
    A0:    PORTB, Bit 1  --> to Display´s D/C
69
    SCK:  PORTB, Bit 5  --> to Display´s SCK
70
    MOSI:  PORTB, Bit 3  --> to Display´s MOSI
71
  RST:  PORTB, Bit 0  --> to Display´s RST
72
  */
73
  /***** Software SPI *****/
74
  //u8g_InitSPI(&u8g, &u8g_dev_sh1106_128x64_sw_spi, PN(1, 5), PN(1, 3), PN(1, 2), PN(1, 1), U8G_PIN_NONE);
75
  
76
  /***** Hardware SPI *****/
77
  u8g_InitSPI(&u8g, &u8g_dev_sh1106_128x64_hw_spi, PN(1, 5), PN(1, 3), PN(1, 2), PN(1, 1), U8G_PIN_NONE);
78
}
79

80
void sys_init(void)
81
{
82
  #if defined(__AVR__)
83
    /* select minimal prescaler (max system speed) */
84
    CLKPR = 0x80;
85
    CLKPR = 0x00;
86
  #endif
87
}
88

89
void draw(void)
90
{
91
  u8g_SetFont(&u8g, u8g_font_9x18);
92
  u8g_DrawStr(&u8g, 0, 15, "Hello World!");
93
}
94

95
int main(void)
96
{
97
  DDRB |=(1<<PB0);    
98
  PORTB |=(1<<PB0);    // RST High
99

100
  PORTB &= ~(1<<PB0);    // RST Low
101
  u8g_Delay(30);      // wait 30us
102
  PORTB |=(1<<PB0);    // RST High
103
  
104
  sys_init();
105
  u8g_setup();
106

107
  while(1)
108
  {  
109
    u8g_FirstPage(&u8g);
110
    do
111
    {
112
      draw();
113
    } while ( u8g_NextPage(&u8g) );
114
    u8g_Delay(100);
115
  }
116
}
Angehängte Dateien:
#4345528
Lesenswert?

m. g. schrieb:
> Noch eine Frage zu dieser Übergabe des Adressparameters. Ich verstehe
> hier diese Funktion nicht. Kann mir das bitte jemand erklären?
Was verstehst Du nicht ? Das "&" Zeichen vor der Variable ?
Dabei wird nicht der Wert selber der Variable in der Funktion übergeben,
sondern nur die Adress auf die Variable.

Siehe auch "function parameter by value" oder "function parameter by 
reference" in den C-Büchern. Sorry, weiss die genaue Uebersetzung in 
Deutsch gerade nicht :-)

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