PIC32 SSD1331 library - Page 1
Forum section: electronics / general

author: adi1525
author_rank: Newbie
timestamp: February 26, 2017, 06:48:01 pm
content: Hi,I'm looking for the SSD1331 library for PIC32, I found only for STM32 and arduino. I tried change function from Adafruit-SSD1331 but the screen doesn't show anything.And why only for the PIC there is no this library ??

author: Buriedcode
author_rank: Super Contributor
timestamp: February 26, 2017, 07:40:11 pm
content: Well it shouldn't be too difficult to convert the Arduino library to standard 'C' for the C32 compiler. What did you change in the original library? The most obvious would be the lower level SPI or GPIO drivers.Rather than just hook it all together and see if the screen 'shows' something, perhaps taking it one step at a time would be better practice. First of all make sure the hardware is set up, and try to draw a few pixels - higher functionality can come later.

author: adi1525
author_rank: Newbie
timestamp: February 26, 2017, 08:49:20 pm
content: I did that. I used function only for initiate the screen, it's my code:Code:#include <xc.h>#include "SSD1331.h"#include <plib.h>#define DRAW_LINE 0x21#define DRAW_RECTANGLE 0x22#define COPY_WINDOW 0x23#define DIM_WINDOW 0x24#define CLEAR_WINDOW 0x25#define FILL_WINDOW 0x26#define DISABLE_FILL 0x00#define ENABLE_FILL 0x01#define CONTINUOUS_SCROLLING_SETUP 0x27#define DEACTIVE_SCROLLING 0x2E#define ACTIVE_SCROLLING 0x2F#define SET_COLUMN_ADDRESS 0x15#define SET_ROW_ADDRESS 0x75#define SET_CONTRAST_A 0x81#define SET_CONTRAST_B 0x82#define SET_CONTRAST_C 0x83#define MASTER_CURRENT_CONTROL 0x87#define SET_PRECHARGE_SPEED_A 0x8A#define SET_PRECHARGE_SPEED_B 0x8B#define SET_PRECHARGE_SPEED_C 0x8C#define SET_REMAP 0xA0#define SET_DISPLAY_START_LINE 0xA1#define SET_DISPLAY_OFFSET 0xA2#define NORMAL_DISPLAY 0xA4#define ENTIRE_DISPLAY_ON 0xA5#define ENTIRE_DISPLAY_OFF 0xA6#define INVERSE_DISPLAY 0xA7#define SET_MULTIPLEX_RATIO 0xA8#define DIM_MODE_SETTING 0xAB#define SET_MASTER_CONFIGURE 0xAD#define DIM_MODE_DISPLAY_ON 0xAC#define DISPLAY_OFF 0xAE#define NORMAL_BRIGHTNESS_DISPLAY_ON 0xAF#define POWER_SAVE_MODE 0xB0#define PHASE_PERIOD_ADJUSTMENT 0xB1#define DISPLAY_CLOCK_DIV 0xB3#define SET_GRAy_SCALE_TABLE 0xB8#define ENABLE_LINEAR_GRAY_SCALE_TABLE 0xB9#define SET_PRECHARGE_VOLTAGE 0xBB#define SET_V_VOLTAGE 0xBE#define CE LATDbits.LATD0//CS-set device#define RST LATDbits.LATD1//reset#define CLK LATDbits.LATD2//SCK1#define SDI1 LATDbits.LATD3//DIN#define DC LATDbits.LATD6//1-data 0-instructionvoid InitPIN(){TRISBbits.TRISB0=0;TRISBbits.TRISB1=0;TRISBbits.TRISB2=0;TRISBbits.TRISB3=0;TRISBbits.TRISB4=0;TRISBbits.TRISB6=0;SS1R=0b0100; //RPD4//Can set like GPIO, this set allows more deviceSDI1R=0b0000; //RPD3}void main(){InitPIN();OpenSPI1(FRAME_ENABLE_ON|FRAME_SYNC_OUTPUT|ENABLE_SDO_PIN|SPI_MODE16_ON|SPI_SMP_ON|SPI_CKE_ON|SLAVE_ENABLE_OFF|CLK_POL_ACTIVE_HIGH|MASTER_ENABLE_ON|SEC_PRESCAL_8_1|PRI_PRESCAL_64_1,SPI_ENABLE|SPI_IDLE_STOP);SpiChnOpen(1, SPICON_MSTEN|SPICON_FRMEN|SPICON_MODE16|SPICON_SMP|SPICON_ON, 512);DC=0;RST=0;RST=1;CE=0;WriteSPI1(DISPLAY_OFF); //Display OffWriteSPI1(SET_CONTRAST_A); //Set contrast for color AWriteSPI1(0xFF); //145 0x91WriteSPI1(SET_CONTRAST_B); //Set contrast for color BWriteSPI1(0xFF); //80 0x50WriteSPI1(SET_CONTRAST_C); //Set contrast for color CWriteSPI1(0xFF); //125 0x7DWriteSPI1(MASTER_CURRENT_CONTROL);//master current controlWriteSPI1(0x06); //6WriteSPI1(SET_PRECHARGE_SPEED_A);//Set Second Pre-change Speed For ColorAWriteSPI1(0x64); //100WriteSPI1(SET_PRECHARGE_SPEED_B);//Set Second Pre-change Speed For ColorBWriteSPI1(0x78); //120WriteSPI1(SET_PRECHARGE_SPEED_C);//Set Second Pre-change Speed For ColorCWriteSPI1(0x64); //100WriteSPI1(SET_REMAP); //set remap & data formatWriteSPI1(0x72); //0x72WriteSPI1(SET_DISPLAY_START_LINE);//Set display Start LineWriteSPI1(0x0);WriteSPI1(SET_DISPLAY_OFFSET); //Set display offsetWriteSPI1(0x0);WriteSPI1(NORMAL_DISPLAY); //Set display modeWriteSPI1(SET_MULTIPLEX_RATIO); //Set multiplex ratioWriteSPI1(0x3F);WriteSPI1(SET_MASTER_CONFIGURE); //Set master configurationWriteSPI1(0x8E);WriteSPI1(POWER_SAVE_MODE); //Set Power Save ModeWriteSPI1(0x00); //0x00WriteSPI1(PHASE_PERIOD_ADJUSTMENT);//phase 1 and 2 period adjustmentWriteSPI1(0x31); //0x31WriteSPI1(DISPLAY_CLOCK_DIV); //display clock divider/oscillator frequencyWriteSPI1(0xF0);WriteSPI1(SET_PRECHARGE_VOLTAGE);//Set Pre-Change LevelWriteSPI1(0x3A);WriteSPI1(SET_V_VOLTAGE); //Set vcomHWriteSPI1(0x3E);WriteSPI1(DEACTIVE_SCROLLING); //disable scrollingWriteSPI1(NORMAL_BRIGHTNESS_DISPLAY_ON);//set display onDC=1;CE=1;}I'm not sure about setting prescaller, I used 20 mhz crystal resonator and processor used 100Mhz speed

author: jaromir
author_rank: Unknown
timestamp: February 26, 2017, 09:03:13 pm
content: Does the SPI output anything? The remap function of remappable peripherals pins need proper unlock sequence.Does the GPIO behave as expected?I can't see any config bits (or oscillator setup in code), are those set up in another file?The main function doesn't end with endless loop, is that intended?Don't get me wrong, it looks like you need to start with blinking a LED.

author: bktemp
author_rank: Super Contributor
timestamp: February 26, 2017, 09:06:30 pm
content: SSD1331 uses 8bit data, in your code SPI is set to 16bit transfers.

author: adi1525
author_rank: Newbie
timestamp: February 27, 2017, 05:45:45 pm
content: Jaromir I'm used a bootloader so I don't need config oscillator. Program can end without endless loop because I config the screen and that's all, am I right ??Bktemp I set up the 8 bit mode and don't show anything.

author: bktemp
author_rank: Super Contributor
timestamp: February 27, 2017, 06:00:28 pm
content: I have never used PLBIB, but it looks like you have selected some unusual options, like SPICON_FRMEN, FRAME_ENABLE_ON and FRAME_SYNC_OUTPUT, but you are also controlling the CE line in software. Check if the selected SPI settings match the timing required by the display.It also is a good practice to set CE to high between individual commands to make sure SPI starts at a known state for each new command.

author: adi1525
author_rank: Newbie
timestamp: March 06, 2017, 09:54:03 pm
content: I give delay after setting CE and delete SPICON_FRMEN, FRAME_ENABLE_ON and FRAME_SYNC_OUTPUT option and It's work.Very thank you Bktemp