Forum Menu




 


Log in Problems?
New User? Sign Up!
AVR Freaks Forum Index

Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Author Message
Andrea_IT
PostPosted: Jul 05, 2011 - 05:49 PM
Newbie


Joined: Jun 11, 2011
Posts: 12


Hi guys,

after a few days, reading and re-reading the datasheet I could build a library for this OLED display, integrated with a controller SSD1305.
I can write text, draw a pixel etc., but when I try to read I find myself just bad data, someone can help me, thanks.
Put my code and attach a photo.

p.s. Using a Xmega128A1, default set to 2MHz, and AVR Studio 5.0

Code:
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include "SSD1305.h"

#define SSD1305_DATA_PORT      PORTH_OUT
#define SSD1305_DATA_DIR      PORTH_DIR
#define SSD1305_DATA_PIN      PORTH_IN

#define SSD1305_CONTROL_PORT   PORTJ_OUT
#define SSD1305_CONTROL_DIR      PORTJ_DIR

#define SSD1305_RD            (1 << PIN0)   //Read
#define SSD1305_WR            (1 << PIN1)   //Write
#define SSD1305_DC            (1 << PIN2)   //Data Or Command
#define SSD1305_RES            (1 << PIN3)   //Reset
#define SSD1305_CS            (1 << PIN4)   //Chip select

void GLCD_WriteData(unsigned char dataToWrite)
{
SSD1305_CONTROL_PORT |= (SSD1305_RD | SSD1305_DC);
SSD1305_CONTROL_PORT &= ~(SSD1305_CS |SSD1305_WR);
SSD1305_DATA_PORT = dataToWrite;
asm("nop");
SSD1305_CONTROL_PORT |= (SSD1305_WR);
}

void GLCD_WriteCommand(unsigned char commandToWrite)
{
SSD1305_CONTROL_PORT |= (SSD1305_RD);
SSD1305_CONTROL_PORT &= ~(SSD1305_CS |SSD1305_WR | SSD1305_DC);
SSD1305_DATA_PORT = commandToWrite;
asm("nop");
SSD1305_CONTROL_PORT |= (SSD1305_WR);
}

void GLCD_InitializePorts(void)
{   
SSD1305_CONTROL_DIR |= (SSD1305_DC | SSD1305_WR | SSD1305_RD | SSD1305_CS | SSD1305_RES);  //setta direzione 1 output
SSD1305_DATA_DIR = 0xFF;   //setta direzione 1 output
SSD1305_CONTROL_PORT &= ~ (SSD1305_DC | SSD1305_WR | SSD1305_RD | SSD1305_CS | SSD1305_RES); //setta i pin a 0
SSD1305_CONTROL_PORT |= (SSD1305_RES);  //Reset  High
_delay_ms(1);
SSD1305_CONTROL_PORT &= ~ (SSD1305_RES);  //Reset  Low
_delay_ms(10);
SSD1305_CONTROL_PORT |= (SSD1305_RES);  //Reset  High runtime mode
_delay_ms(1);
}

unsigned char GLCD_ReadData(void)
{
unsigned char tmp;
SSD1305_CONTROL_PORT |= (SSD1305_DC | SSD1305_WR);
SSD1305_CONTROL_PORT &= ~(SSD1305_CS | SSD1305_RD);
asm("nop");
SSD1305_DATA_DIR = 0x00;
asm("nop");
tmp =  SSD1305_DATA_PIN;
SSD1305_CONTROL_PORT |= (SSD1305_RD);
return tmp;
}

unsigned char GLCD_ReadByteFromROMMemory(unsigned char * ptr)
{
return pgm_read_byte(ptr);
}

void GLCD_Initialize(void)
{
GLCD_InitializePorts();
GLCD_WriteCommand(SSD1305_DISPLAYOFF);  // 0xAE
GLCD_WriteCommand(SSD1305_SETDISPLAYCLOCKDIV);  // 0xD5
GLCD_WriteCommand(0x80);  // the suggested ratio 0x80
GLCD_WriteCommand(SSD1305_SETMULTIPLEX); // 0xA8
GLCD_WriteCommand(0x3F);  // 0x3F 1/64 duty
GLCD_WriteCommand(SSD1305_SETDISPLAYOFFSET); // 0xD3
GLCD_WriteCommand(0x0); // no offset
GLCD_WriteCommand(SSD1305_SETSTARTLINE); // line #0
//GLCD_WriteCommand(SSD1305_SEGREMAP1); //0xA1
GLCD_WriteCommand(SSD1305_COMSCANDEC); //0xC8
GLCD_WriteCommand(SSD1305_SETCOMPINS); // 0xDA
GLCD_WriteCommand(0x12); // disable COM left/right remap
GLCD_WriteCommand(SSD1305_SETCONTRAST);
GLCD_WriteCommand(0xFF);
GLCD_WriteCommand(SSD1305_SETPRECHARGE); // 0xd9
GLCD_WriteCommand(0xF1);
GLCD_WriteCommand(SSD1305_SETVCOMDETECT); // 0xDB
GLCD_WriteCommand(0x40); // 0x20 is default?
GLCD_WriteCommand(SSD1305_DISPLAYALLON_RESUME); // 0xA4
GLCD_WriteCommand(SSD1305_NORMALDISPLAY); // 0xA6
GLCD_WriteCommand(SSD1305_MEMORYMODE); // 0x20
GLCD_WriteCommand(0x00); // 0x0 act like ks0108
GLCD_WriteCommand(SSD1305_SETLOWCOLUMN | 0x0);  // low col = 0
GLCD_WriteCommand(SSD1305_SETHIGHCOLUMN | 0x0);  // hi col = 0
//GLCD_WriteCommand(SSD1305_SEGREMAP | 0x1);
GLCD_WriteCommand(SSD1305_DISPLAYON);//--turn on oled panel
}




Last edited by Andrea_IT on Jul 07, 2011 - 09:06 AM; edited 2 times in total
 
 View user's profile Send private message  
Reply with quote Back to top
jayjay1974
PostPosted: Jul 05, 2011 - 08:06 PM
Raving lunatic


Joined: Oct 30, 2002
Posts: 5764
Location: The Netherlands

You don't seem to return the dataport back to outputs after reading the response.
 
 View user's profile Send private message  
Reply with quote Back to top
Andrea_IT
PostPosted: Jul 05, 2011 - 08:23 PM
Newbie


Joined: Jun 11, 2011
Posts: 12


ops, right. Tomorrow I correct it and try.
Hope...
 
 View user's profile Send private message  
Reply with quote Back to top
Andrea_IT
PostPosted: Jul 06, 2011 - 11:35 AM
Newbie


Joined: Jun 11, 2011
Posts: 12


I have found a solution, but it's a little mistake:

Code:
unsigned char GLCD_ReadData(void)
{
unsigned char tmp;
SSD1305_DATA_DIR = 0x00;
SSD1305_CONTROL_PORT &= ~(SSD1305_CS);
SSD1305_CONTROL_PORT |= (SSD1305_DC | SSD1305_WR);
SSD1305_CONTROL_PORT &= ~(SSD1305_RD);
SSD1305_CONTROL_PORT |= (SSD1305_RD);
SSD1305_CONTROL_PORT &= ~(SSD1305_RD);
SSD1305_CONTROL_PORT |= (SSD1305_RD);
SSD1305_CONTROL_PORT |= (SSD1305_CS);
tmp =  SSD1305_DATA_PIN;
SSD1305_DATA_DIR = 0xFF;
return tmp;
}


If you see the code, i must repeat RD (low, hight) 2 time, because the first time i read bad data?
Why????
Do you have a answer?
Tnku very much.
When I finish the library i post it here.

p.s. excuse me for my bad english, Im Italian
 
 View user's profile Send private message  
Reply with quote Back to top
jayjay1974
PostPosted: Jul 06, 2011 - 06:30 PM
Raving lunatic


Joined: Oct 30, 2002
Posts: 5764
Location: The Netherlands

Read the datasheet more carefully... the first byte returned is a dummy and should be discarded.
 
 View user's profile Send private message  
Reply with quote Back to top
Andrea_IT
PostPosted: Jul 06, 2011 - 08:11 PM
Newbie


Joined: Jun 11, 2011
Posts: 12


Sad Iam a noob, datasheet is in english, some word escape for me Smile
Tnku jayjay1974
 
 View user's profile Send private message  
Reply with quote Back to top
jayjay1974
PostPosted: Jul 06, 2011 - 08:58 PM
Raving lunatic


Joined: Oct 30, 2002
Posts: 5764
Location: The Netherlands

Does it work now?
 
 View user's profile Send private message  
Reply with quote Back to top
Andrea_IT
PostPosted: Jul 06, 2011 - 10:31 PM
Newbie


Joined: Jun 11, 2011
Posts: 12


Yes perfectly. Very fast write and read. I finish library and then share it.
On the web there isnt ssd1305 library.
I draw pixel, line, rec, circle, text and bitmap, now Im tring to show animation.
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jul 06, 2011 - 11:52 PM
10k+ Postman


Joined: Mar 28, 2001
Posts: 22228
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Quote:
I finish library and then share it.
Per me puoi farlo in Italiano o in Inglese. Wink

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
gchapman
PostPosted: Jul 07, 2011 - 01:40 AM
Raving lunatic


Joined: Jan 09, 2007
Posts: 2560
Location: Arlington, Texas, U.S.A.

Andrea_IT wrote:
On the web there isnt ssd1305 library.
Here is an alternate but it does not appear to be as complete and as re-usable as yours.
http://www.newhavendisplay.com/app_notes/OLED_2_23_12832.txt
Newhaven Display, Graphic OLEDs
 
 View user's profile Send private message  
Reply with quote Back to top
Andrea_IT
PostPosted: Jul 07, 2011 - 08:40 AM
Newbie


Joined: Jun 11, 2011
Posts: 12


Quote:
http://www.newhavendisplay.com/app_notes/OLED_2_23_12832.txt

This use 6800 Parallel Mode, my 8080, but some function are interesting, tnku
 
 View user's profile Send private message  
Reply with quote Back to top
Andrea_IT
PostPosted: Jul 07, 2011 - 09:02 AM
Newbie


Joined: Jun 11, 2011
Posts: 12


I attach my first release.

p.s. E' bello trovare altri italiani, ogni volta mi sembra di essere solo.
 
 View user's profile Send private message  
Reply with quote Back to top
js
PostPosted: Jul 07, 2011 - 10:37 AM
10k+ Postman


Joined: Mar 28, 2001
Posts: 22228
Location: Sydney, Australia (Gum trees, Koalas and Kangaroos, No Edelweiss)

Thanks for sharing your code Andrea. I'm currently playing with a few GLCD for a couple of clients and I think that driver chip number has come up in one of them.

I have forgotten which one though, I have looked at so many in the past few days that my head is spinning...maybe I'm just possesed... Smile

edit as a matter of interst does anyone know of a cross reference chart for different GLCD controllers? There seem to be some with different numbers that are pin and code compatible with each other.

_________________
John Samperi
Ampertronics Pty. Ltd.
www.ampertronics.com.au
* Electronic Design * Custom Products * Contract Assembly
 
 View user's profile Send private message Visit poster's website 
Reply with quote Back to top
Andrea_IT
PostPosted: Jul 07, 2011 - 11:25 AM
Newbie


Joined: Jun 11, 2011
Posts: 12


Surely there are plenty of GLCD controller compatible with each other. Often, many of them are pre-configured, actually, my GLCD BL12832A1 SSD1305 controller which features a factory was set to only use mode 8080. But this can not find it on the datasheet, (IMPORTANT), I had to check with a tester pins BS1 and BS2, and understand how it operated.
I believe that the SSD,SED models, etc will eventually be compatible with each other, the only thing that changes is the address of the command, just replace them and it should go.
Now I want to try a larger GLCD and color soon.
p.s. JS you should write in Italian)
 
 View user's profile Send private message  
Reply with quote Back to top
florisson
PostPosted: Jan 23, 2012 - 06:38 AM
Newbie


Joined: Jan 16, 2012
Posts: 1


Hi Andrea, I'm working working on a project with a display using the SSD1305 chip and have found this post very helpful, thank you. One thing, my display isn't turning on and I've rechecked my wiring countless times, so I suspect its code, do you have any tips on debugging the code, given that I can't see the response from the SSD chip? I suspect it might be the frequency but I can't find any definitive notes in the data sheets that indicate the codes for the multipliers and what the base frequency is.

Thanks
 
 View user's profile Send private message  
Reply with quote Back to top
gmatt_76
PostPosted: May 02, 2012 - 01:45 PM
Newbie


Joined: May 02, 2012
Posts: 1


Hi Andrea, thanks for the library, I consider it very useful. May I ask you about the text management? Does the library provide support for the fonts? Thanks, Gianluca
 
 View user's profile Send private message  
Reply with quote Back to top
Gumptree
PostPosted: Oct 23, 2012 - 09:02 AM
Newbie


Joined: Jun 08, 2012
Posts: 2


Hi Andrea, thank you for your code. It really helped me. But could you possible tell me how did you convert the Bitmap to text to display the Bluetooth logo?
Thanks, Gary
 
 View user's profile Send private message  
Reply with quote Back to top
cwickstr
PostPosted: Apr 05, 2013 - 12:38 PM
Newbie


Joined: Feb 10, 2006
Posts: 3


Hi Andrea, any updates on the library? Planning to use this controller in a project, and looking for different sized fonts, more graphics etc. Are you planning release newer versions of the library?
 
 View user's profile Send private message  
Reply with quote Back to top
Display posts from previous:     
Jump to:  
All times are GMT + 1 Hour
Post new topic   Reply to topic
View previous topic Printable version Log in to check your private messages View next topic
Powered by PNphpBB2 © 2003-2006 The PNphpBB Group
Credits