chipKIT® Development Platform

Inspired by Arduino™

Adafruit_PCD8544 Nokia Display Library

Created Fri, 29 Jan 2016 16:05:57 +0000 by ricklon


ricklon

Fri, 29 Jan 2016 16:05:57 +0000

I'm configuring one of the Adafruit PCD8544 Nokia displays: https://www.adafruit.com/products/338

It's pretty easy to get it show graphics. But there is a clock speed error. If I comment out setting the clock speed it defaults to 1Mhz which actually works OK. But the claim is that the device is 4Mhz.

My question is what clockDivider value should be used to get 4Mhz or 1Mhz by use setClockDivider.

Details below: Working library here: https://github.com/ricklon/Adafruit-PCD8544-Nokia-5110-LCD-library Changes to Adafruit_PCD8544.h

#if defined(__SAM3X8E__)
  typedef volatile RwReg PortReg;
  typedef uint32_t PortMask;
#elif defined(__PIC32MX1XX__) || defined(__PIC32MX2XX__) || defined(__PIC32MZXX__) || defined(__PIC32MX47X__)
  typedef volatile uint32_t PortReg;
  typedef uint32_t PortMask;
#else
  typedef volatile uint8_t PortReg;
  typedef uint8_t PortMask;
#endif

changes to Adafruit_PCD8544.cpp

if (isHardwareSPI()) {
    // Setup hardware SPI.
    SPI.begin();
//    SPI.setClockDivider(PCD8544_SPI_CLOCK_DIV);
    SPI.setDataMode(SPI_MODE0);
    SPI.setBitOrder(MSBFIRST);
  }

I did have to comment out the Sotware SPI. Because of data type errors:

/*
  else {
    // Setup software SPI.

    // Set software SPI specific pin outputs.
    pinMode(_din, OUTPUT);
    pinMode(_sclk, OUTPUT);

    // Set software SPI ports and masks.
    clkport     = portOutputRegister(digitalPinToPort(_sclk));
    clkpinmask  = digitalPinToBitMask(_sclk);
    mosiport    = portOutputRegister(digitalPinToPort(_din));
    mosipinmask = digitalPinToBitMask(_din);
  }*/

majenko

Fri, 29 Jan 2016 20:22:01 +0000

What clock divider to use depends on the speed of the peripheral clock. What the speed of the peripheral clock is depends on the bootloader.

Some have a 1:1 peripheral clock (so 80MHz or whatever the chip runs at) and some (Digilent ones maybe?) have a 1:8 peripheral clock - so 10MHz (or 1/8 of the CPU clock).

You can, of course, use getPeripheralClock() to find out what the clock is and then do some calculations to decide what the divider should be. Or you could switch the whole thing to using DSPI which has setSpeed() which does it all for you.


ricklon

Mon, 01 Feb 2016 15:43:23 +0000

In the end I set the clock divider to 20 and it works nicely. Of course this would be for an 80Mhz chip.

The getPeripheralClock() works, but does not update with new clock settings.

--Rick