• 0
jagnala

Pmod OLED with pic24f

Question

Hi,

I'm trying to get the Pmod OLED  to work with the PIC24F32KA302, I've used the template file and modified all the register appropriately but I cant get the display to work. It turns on and always display garbage when I try writing to it and even clear the OLED doesn't seem to work, the display does respond to SPI command but just the displays different just pixels.    

any thoughts on what might be wrong, I can post some code if it helps.

2017-05-03_16-41-59.png

Share this post


Link to post
Share on other sites

7 answers to this question

Recommended Posts

  • 0

Sure, see the snippet below for the PmodOLED that I've updated:

I'm using MPLABSX XC16

void OledHostInit()
{
 // Initialize SPI port 2.
    /* The following code sequence shows SPI register configuration for Master mode */
    IFS0bits.SPI1IF = 0; // Clear the Interrupt flag
    IEC0bits.SPI1IE = 0; // Disable the interrupt
    // SPI1CON1 Register Settings
    SPI1CON1bits.DISSCK = 0; // Internal serial clock is enabled
    SPI1CON1bits.DISSDO = 0; // SDOx pin is controlled by the module
    SPI1CON1bits.MODE16 = 0; // Communication is word-wide (16 bits)
    SPI1CON1bits.MSTEN = 1; // Master mode enabled
    SPI1CON1bits.SMP = 0; // Input data is sampled at the middle of data output time
    SPI1CON1bits.CKE = 0; // Serial output data changes on transition from
    SPI1CON1bits.PPRE = 0b11;
    SPI1CON1bits.SPRE = 0b000;
    SPI1CON1bits.SSEN = 0;
    SPI1CON2 = 0;
    // Idle clock state to active clock state
    SPI1CON1bits.CKP = 1; // Idle state for clock is a low level;
    // active state is a high level
    SPI2STATbits.SPIROV = 0;
    SPI1STATbits.SPIEN = 1; // Enable SPI module
    // Interrupt Controller Settings
    IFS0bits.SPI1IF = 0; // Clear the Interrupt flag
    IEC0bits.SPI1IE = 1; // Enable the interrupt

 /* Make power control pins be outputs with the supplies off
 */
 bitVddCtrl = true;
 bitVbatCtrl = true;
 /* Make the Data/Command select, Reset, and SPI CS pins be outputs.
 */
 bitDataCmd = true;
 bitReset = true;
 bitSelect = true;
}

void  OledPutBuffer(int cb, unsigned char * rgbTx)
{
 int  ib;
 unsigned char bTmp;

 /* Bring the slave select line low
 */
 bitSelect = false;
    DelayMS(10);
 /* Write/Read the data
 */
 for (ib = 0; ib < cb; ib++)
    {
        /* Wait for transmitter to be ready
  */
  while (SPI1STATbits.SPITBF != 0);

  /* Write the next transmit byte.
  */
  SPI1BUF = *rgbTx++;

  /* Wait for receive byte.
  */
  while (SPI1STATbits.SPIRBF == 0);

  bTmp = SPI1BUF;

 }

 /* Bring the slave select line high
 */
 bitSelect = true;
 DelayMS(10);
}

 

unsigned char Spi2PutByte(unsigned char bVal)
{
 unsigned char bRx;

 /* Bring the slave select line low
 */
 bitSelect = false;
    DelayMS(10);
   
    while (SPI1STATbits.SPITBF != 0);
 /* Write the next transmit byte.
 */
 SPI1BUF = bVal;

 /* Wait for receive byte.
 */
 while (SPI1STATbits.SPIRBF == 0);

 /* Put the received byte in the buffer.
 */
 bRx = SPI1BUF;

 /* Bring the slave select line high
 */
 bitSelect = true;
 DelayMS(10);
   
 return bRx;

}

Thanks so much

 

Share this post


Link to post
Share on other sites
  • 0

Hello,

This is just my experience, but I always just tied the chipSelect pin to ground since whenever I tried to cycle it on and off, I remember getting some funky displays as well. I don't have an Pmod OLED on me at the moment to verify this though.

To be fair, this isn't the best coding practice for the SPI protocol (especially if you plan to be using other SPI devices with your MCU), but the Basic IO Shield (which has the same OLED) has its CS pin tied to ground with a pull-down resistor and not even have it connected to a digital signal, which is still strange to me, since I would have thought that it would need to be brought to a logic high at some point, but the OLED always worked as expected.

So, I guess my answer is try keeping the CS line logic low.

Thanks,
JColvin

Share this post


Link to post
Share on other sites
  • 0

Hi @jagnala,

First off make sure that you are running you spi clock at the 8 Mhz as shown in our OledHostInit(). Also it looks like you are using spi1 and spi2? Our setup for the PIC32 uses the spi2 as follows in the OledHostInit():

/* Initialize SPI port 2.
    */
    SPI2CON = 0;
    SPI2BRG = 15;                //8Mhz, with 80Mhz PB clock
    SPI2STATbits.SPIROV = 0;
    SPI2CONbits.CKP = 1;
    SPI2CONbits.MSTEN = 1;
    SPI2CONbits.ON = 1;

cheers,

Jon
 

Share this post


Link to post
Share on other sites
  • 0

I've run the clock at 8Mhz and below with so change in results also, I'm using SPI1 for my application.  I saw I posted SPI2STATbits.SPIROV = 0; but its SPI1STATbits.SPIROV = 0; in my code.

Thanks for the hit but still no luck.

Share this post


Link to post
Share on other sites
  • 0

Some good news, its seem the issue is not with the SPI communication, I can configure the contrast and other setting on the display I can see the pattern increase and decrease in brightness. The display also only turns on when I send the Spi2PutByte(0xAF); command so i'm sure messages are being received. I feel like i'm getting close to the issue.

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now