• We recently switched our forum platform. If you experience any issues please email support@crystalfontz.com

CFAL12832D-B connection and programming with PIC

miskol

New member
Hi,

i am unable to get the CFAL12832D-B working with my PIC18F25K50 (the OLED was bought directly from CF).

as attached are the schematic for the OLED connection with the PIC. a level shifter CD4050 are used since the PIC is powered with 5V.

Please help, TQ.

p/s: for initial testing, i bought the OLED already connected with a break-out board from adafruit (https://www.adafruit.com/products/661) and connected it with dsPIC30F6014A. with below programming code, the display works.


here is the programming:
Code:
#include <test1.h>

#define DC   PIN_A1
#define RES   PIN_A2
#define CS1   PIN_C7

void WriteCommand(byte command)
{
   OUTPUT_LOW(CS1);             // chip selected
   OUTPUT_LOW(DC);              // command mode
   spi_write(command);			// set up data on bus
   OUTPUT_HIGH(CS1);            // deselect chip
}

void WriteData(byte data)
{
   OUTPUT_LOW(CS1);             // chip selected
   OUTPUT_HIGH(DC);             // data mode
   spi_write(data);   			// set up data on bus
   OUTPUT_HIGH(CS1);            // deselect chip
}

void reset_display(void)
{
   OUTPUT_LOW(RES);
   delay_ms(10000);
   OUTPUT_HIGH(RES);
   delay_ms(10000);
}

void init_OLED(void)
{
   WriteCommand(0xAE);      //--Set Display off

   WriteCommand(0x00);      //--set low column address
   WriteCommand(0x10);      //--set high column address   
   WriteCommand(0x81);      //--set contrast control register
   WriteCommand(0x7f);
   WriteCommand(0xa1);      //--set segment re-map 95 to 0
   WriteCommand(0xA6);      //--set normal display
   WriteCommand(0xa8);      //--set multiplex ratio(1 to 16)
   WriteCommand(0x1f);      //--duty 1/32
   WriteCommand(0xd3);      //--set display offset
   WriteCommand(0x00);      //--not offset
   WriteCommand(0xd5);      //--set display clock divide ratio/oscillator frequency
   WriteCommand(0xf0);      //--set divide ratio
   WriteCommand(0xd9);      //--set pre-charge period
   WriteCommand(0x22);
   WriteCommand(0xda);      //--set com pins hardware configuration
   WriteCommand(0x02);      //disable left/right remap and set for sequential
   WriteCommand(0xdb);      //--set vcomh
   WriteCommand(0x49);      //--0.83*vref
   WriteCommand(0x8d);      //--set DC-DC enable
   WriteCommand(0x14);
   WriteCommand(0xAF);      //--turn on oled panel
   WriteCommand(0xA4);      //--Entire Display ON
}

byte boot_logo[4][132] = 
{
{0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0x0C,0x06,0x03,0x01,0x03,0x06,0xCC,0xE0,0xF0,0xF8,0xFC,0x06,0x03,0x01,0x03,0x06,0x0C,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0x00,0x00,0xE0,0xF8,0x38,0x1C,0x1C,0x1C,0x3C,0x78,0xF0,0xC0,0x00,0x00,0x7C,0xFC,0xC0,0x00,0x00,0x00,0x00,0x00,0xF1,0xFF,0x1F,0x7C,0xE0,0x00,0x00,0x00,0x30,0x38,0x1C,0x8C,0xCC,0xF8,0xF0,0x00,0x00,0x78,0xFC,0x0C,0x0C,0x00,0x78,0xFC,0xCC,0x8C,0x98,0xFC,0xFC,0x00,0x00,0x3C,0xFC,0xC0,0x00,0x7C,0xFC,0xC0,0x00,0x00,0xF0,0xF8,0x1C,0x0C,0x0C,0x1C,0x38,0xF0,0xC0,0x00,0x7C,0xFC,0xC0,0x00,0x00,0x00,0x3C,0xFC,0xC0,0x00,0x78,0xFC,0x0C,0x0C,0x00,0x1C,0x3C,0x7C,0xCC,0x8C,0x0C,0x0C,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x1F,0x7F,0xF0,0xC0,0x80,0x80,0x80,0x80,0xC0,0xF0,0x30,0x00,0x00,0x3F,0x3F,0x0C,0x18,0x38,0x20,0x00,0x3F,0x3F,0x00,0x00,0x03,0x1F,0x3C,0x20,0x00,0x0F,0x1F,0x33,0x31,0x31,0x38,0x18,0x00,0x30,0x3F,0xFC,0xB0,0x30,0x00,0x0C,0x1C,0x31,0x31,0x31,0x3F,0x1F,0x00,0x00,0x7F,0xFF,0x80,0x30,0x7F,0xFF,0xB0,0x30,0x07,0x0F,0x1C,0x38,0x30,0x30,0x38,0x1F,0x07,0x00,0x00,0x3F,0x3F,0x0C,0x10,0x30,0x30,0x3F,0x1F,0x00,0x30,0x3F,0xFC,0xB0,0x30,0x00,0x30,0x30,0x31,0x33,0x3E,0x3C,0x38,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x30,0x60,0xC0,0x80,0xC0,0x60,0x33,0x07,0x0F,0x1F,0x3F,0x60,0xC0,0x80,0xC0,0x60,0x30,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x01,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};

void show_bitmap(unsigned char bitmap)
{
   unsigned char j=0;
   unsigned char i=0;

   WriteCommand(0x00);      //lower column address
   WriteCommand(0x10);      //upper column address

   WriteCommand(0xB0);      //set page address
   for(i=0;i<8;i++)
   {
      WriteCommand(0x00);      //lower column address
      WriteCommand(0x10);      //upper column address
      WriteCommand(0xB0+i);   //set page address
      for(j=0;j<128;j++)
      {
         if(bitmap==0)
         {
            WriteData(boot_logo[i][j]);
         }
      }
   }
}

void main()
{
   setup_spi(SPI_MASTER|SPI_SS_DISABLED |SPI_XMIT_L_TO_H|SPI_SAMPLE_AT_END);
   
   OUTPUT_HIGH(RES); 
   init_OLED(); 
   //reset_display();
   
   show_bitmap(0);      // display boot logo
   delay_ms(1000);
   
   while(TRUE)
   {
   }
}
OLED.jpg
Looking for additional LCD resources? Check out our LCD blog for the latest developments in LCD technology.
 
What is the clock frequency of your SPI link? The CD4050B is a fairly slow device and maybe the rise/fall and TPD times are too long. Just a WAG.
 

CF Support

Administrator
Your schematic has it set up for 3-wire SPI, but your code is for 4-wire SPI. If you take pin 9 (BS0) and also tie it to ground, your code will most likely work.

Hi,

i am unable to get the CFAL12832D-B working with my PIC18F25K50 (the OLED was bought directly from CF).

as attached are the schematic for the OLED connection with the PIC. a level shifter CD4050 are used since the PIC is powered with 5V.

Please help, TQ.

p/s: for initial testing, i bought the OLED already connected with a break-out board from adafruit (https://www.adafruit.com/products/661) and connected it with dsPIC30F6014A. with below programming code, the display works.


here is the programming:
Code:
#include <test1.h>

#define DC   PIN_A1
#define RES   PIN_A2
#define CS1   PIN_C7

void WriteCommand(byte command)
{
   OUTPUT_LOW(CS1);             // chip selected
   OUTPUT_LOW(DC);              // command mode
   spi_write(command);			// set up data on bus
   OUTPUT_HIGH(CS1);            // deselect chip
}

void WriteData(byte data)
{
   OUTPUT_LOW(CS1);             // chip selected
   OUTPUT_HIGH(DC);             // data mode
   spi_write(data);   			// set up data on bus
   OUTPUT_HIGH(CS1);            // deselect chip
}

void reset_display(void)
{
   OUTPUT_LOW(RES);
   delay_ms(10000);
   OUTPUT_HIGH(RES);
   delay_ms(10000);
}

void init_OLED(void)
{
   WriteCommand(0xAE);      //--Set Display off

   WriteCommand(0x00);      //--set low column address
   WriteCommand(0x10);      //--set high column address   
   WriteCommand(0x81);      //--set contrast control register
   WriteCommand(0x7f);
   WriteCommand(0xa1);      //--set segment re-map 95 to 0
   WriteCommand(0xA6);      //--set normal display
   WriteCommand(0xa8);      //--set multiplex ratio(1 to 16)
   WriteCommand(0x1f);      //--duty 1/32
   WriteCommand(0xd3);      //--set display offset
   WriteCommand(0x00);      //--not offset
   WriteCommand(0xd5);      //--set display clock divide ratio/oscillator frequency
   WriteCommand(0xf0);      //--set divide ratio
   WriteCommand(0xd9);      //--set pre-charge period
   WriteCommand(0x22);
   WriteCommand(0xda);      //--set com pins hardware configuration
   WriteCommand(0x02);      //disable left/right remap and set for sequential
   WriteCommand(0xdb);      //--set vcomh
   WriteCommand(0x49);      //--0.83*vref
   WriteCommand(0x8d);      //--set DC-DC enable
   WriteCommand(0x14);
   WriteCommand(0xAF);      //--turn on oled panel
   WriteCommand(0xA4);      //--Entire Display ON
}

byte boot_logo[4][132] = 
{
{0x00,0x00,0x00,0x00,0x00,0x80,0xC0,0xE0,0xF0,0xF8,0x0C,0x06,0x03,0x01,0x03,0x06,0xCC,0xE0,0xF0,0xF8,0xFC,0x06,0x03,0x01,0x03,0x06,0x0C,0xF8,0xF0,0xE0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0xC0,0xC0,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
{0x00,0x00,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0xFE,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0xB6,0x00,0x00,0xE0,0xF8,0x38,0x1C,0x1C,0x1C,0x3C,0x78,0xF0,0xC0,0x00,0x00,0x7C,0xFC,0xC0,0x00,0x00,0x00,0x00,0x00,0xF1,0xFF,0x1F,0x7C,0xE0,0x00,0x00,0x00,0x30,0x38,0x1C,0x8C,0xCC,0xF8,0xF0,0x00,0x00,0x78,0xFC,0x0C,0x0C,0x00,0x78,0xFC,0xCC,0x8C,0x98,0xFC,0xFC,0x00,0x00,0x3C,0xFC,0xC0,0x00,0x7C,0xFC,0xC0,0x00,0x00,0xF0,0xF8,0x1C,0x0C,0x0C,0x1C,0x38,0xF0,0xC0,0x00,0x7C,0xFC,0xC0,0x00,0x00,0x00,0x3C,0xFC,0xC0,0x00,0x78,0xFC,0x0C,0x0C,0x00,0x1C,0x3C,0x7C,0xCC,0x8C,0x0C,0x0C,0x00,0x00,0x00},
{0x00,0x00,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x7F,0x00,0x00,0x00,0xFF,0xFF,0xFF,0xFF,0xFF,0x00,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x6D,0x00,0x00,0x1F,0x7F,0xF0,0xC0,0x80,0x80,0x80,0x80,0xC0,0xF0,0x30,0x00,0x00,0x3F,0x3F,0x0C,0x18,0x38,0x20,0x00,0x3F,0x3F,0x00,0x00,0x03,0x1F,0x3C,0x20,0x00,0x0F,0x1F,0x33,0x31,0x31,0x38,0x18,0x00,0x30,0x3F,0xFC,0xB0,0x30,0x00,0x0C,0x1C,0x31,0x31,0x31,0x3F,0x1F,0x00,0x00,0x7F,0xFF,0x80,0x30,0x7F,0xFF,0xB0,0x30,0x07,0x0F,0x1C,0x38,0x30,0x30,0x38,0x1F,0x07,0x00,0x00,0x3F,0x3F,0x0C,0x10,0x30,0x30,0x3F,0x1F,0x00,0x30,0x3F,0xFC,0xB0,0x30,0x00,0x30,0x30,0x31,0x33,0x3E,0x3C,0x38,0x00,0x00},
{0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x07,0x0F,0x1F,0x30,0x60,0xC0,0x80,0xC0,0x60,0x33,0x07,0x0F,0x1F,0x3F,0x60,0xC0,0x80,0xC0,0x60,0x30,0x1F,0x0F,0x07,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x03,0x03,0x03,0x03,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x03,0x00,0x00,0x01,0x03,0x03,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00},
};

void show_bitmap(unsigned char bitmap)
{
   unsigned char j=0;
   unsigned char i=0;

   WriteCommand(0x00);      //lower column address
   WriteCommand(0x10);      //upper column address

   WriteCommand(0xB0);      //set page address
   for(i=0;i<8;i++)
   {
      WriteCommand(0x00);      //lower column address
      WriteCommand(0x10);      //upper column address
      WriteCommand(0xB0+i);   //set page address
      for(j=0;j<128;j++)
      {
         if(bitmap==0)
         {
            WriteData(boot_logo[i][j]);
         }
      }
   }
}

void main()
{
   setup_spi(SPI_MASTER|SPI_SS_DISABLED |SPI_XMIT_L_TO_H|SPI_SAMPLE_AT_END);
   
   OUTPUT_HIGH(RES); 
   init_OLED(); 
   //reset_display();
   
   show_bitmap(0);      // display boot logo
   delay_ms(1000);
   
   while(TRUE)
   {
   }
}
View attachment 2025
 

miskol

New member
Hi,

TQ for the response.

unfortunately the PCB has been fabricated and thus will be difficult to change the hardware connections, especially at the small OLED connector pins.

please correct me if i'm wrong, but i think that the code is also for 3-wire SPI since there is no Serial Data In (SDI) used. however, i since this the only option left for me, i will re-look at the code and do some revision.


Thank you.
 

CF Support

Administrator
Hi,

TQ for the response.

unfortunately the PCB has been fabricated and thus will be difficult to change the hardware connections, especially at the small OLED connector pins.

please correct me if i'm wrong, but i think that the code is also for 3-wire SPI since there is no Serial Data In (SDI) used. however, i since this the only option left for me, i will re-look at the code and do some revision.


Thank you.
I think if you port over the code we used for the ATMEGA2561 here:

http://www.crystalfontz.com/products/document/3119/demo_CFAL12832D_3WSPI.zip

You'll be good to go.
 

miskol

New member
Hi,

i'm not sure about the SPI frequency, i would look into it. However would you advise what is the recommended SPI frequency for this OLED? TQ.

What is the clock frequency of your SPI link? The CD4050B is a fairly slow device and maybe the rise/fall and TPD times are too long. Just a WAG.
 
Hi,

i'm not sure about the SPI frequency, i would look into it. However would you advise what is the recommended SPI frequency for this OLED? TQ.
Actually, I'm not really familiar with this display, so I can't make a recommendation for SPI speed. I was just commenting on the slow cmos chip being used in a (I presume) high frequency path. You could get rid of that potential issue by switching to a 74HC4050 chip, which is pin compatible.
 

miskol

New member
Your schematic has it set up for 3-wire SPI, but your code is for 4-wire SPI. If you take pin 9 (BS0) and also tie it to ground, your code will most likely work.
Hi,

sorry for the long no-progress. i gave up with trying to port the 4-wire code and also gave trying to repair the hardware connection. so i fabricated a new breakout board for the display with the new connection (BS0 to GND). it worked! but only for a few seconds ;(

when it worked, i turned it off, prepared a double-sided tape and wanted to fixed the board properly (got excited of course!). then when i turned it ON again, the display have some bad pixels, i restarted it became worse, restart again and it just wont turn back on again...

do you have reseller in Malaysia?

Thank you.
 

miskol

New member
Hi,

i just received my breakout board to test the OLED.

it is actually working, but the problem is after a few seconds, it would turn off. if i resolder the connections on the FPC, the OLED would function again and after few seconds it turns off again. what do u guys think the problem is?

i did it few times, it repeats as such. i soldered a new set of board, the same thing.

2014-06-19 16.30.40.jpg

Please help, thank you.
 

miskol

New member
Hi,

i tried with another spare OLED that i have, the problem still occurs... it was working nicely but after a few seconds, it would turn off. if i turned the OLED off and let it be maybe around 30 mins, try turning it on again, it would work and after a few seconds, would turned off again...

please help, thanks.
 
I am confused by your attached photo of your breakout board. The legend on the breakout board does not match the pins of the Crystalfontz breakout board.

Your breakout board has a pin on one end labeled "Vin 5V" and has a red wire to the connector. The CFAL12832D-B page says this in the description: "Thanks to the SSD1306 OLED controller's built-in voltage generation, only a single 3.3v supply is needed."

So my question is: what voltage(s) are you supplying to the breakout board? Is there 5V on any of the pins?
 

miskol

New member
Hi,

thanks for the reply.

No, there's no 5V on any of the OLED pins.

Supply and signal levels of 5V comes from the PIC. i used 3.3V voltage regulator to supply the OLED and IC CD4050 for the logic-level conversion between the PIC and the OLED.
 
I tried with another spare OLED that i have, the problem still occurs... it was working nicely but after a few seconds, it would turn off. if i turned the OLED off and let it be maybe around 30 mins, try turning it on again, it would work and after a few seconds, would turned off again...
This description sounds like the classic overheating situation. Since two different displays act the same, the next suspect is the 3.3 volt regulator. You should monitor the 3.3 volt supply and see what happens when the display stops working. Its hard to imaging that the regulator would fold back with a load of less than 50 mA, so you could also put a current meter in series with the 3.3 volts and see if an unexpectedly high current is being drawn. Thats all I can think of to try, for now.

Afterthought: you don't show any connection for the 6th section of the CD4050. CMOS devices can draw a lot of current if an input is left floating.
 

miskol

New member
very sorry guys, apparently it is software related... the SPI speed is too high.

i reduced the SPI speed, added programming to loop images and it is working nicely!

i'm sure that by at least playing with ADC to read analog input values and show it real-time on the OLED will make me very happy, unfortunately that will take some time since currently i dont have the PIC library to easily do that on this OLED.

oh what a relief!!


What is the clock frequency of your SPI link? The CD4050B is a fairly slow device and maybe the rise/fall and TPD times are too long. Just a WAG.
seems like your earlier suggestion was not related to the first problem (before breakout board) but i think it is related with the current problem of this breakout board. it makes sense, since the Adafruit's OLED is working nicely with the same code but not on my own breakout board. their translator IC is HC4050M while i'm using CD4050B.

Thanks for your help :)
 
Top