Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 4 of 4

Thread: SPI and Digole Display Clock divider problems.

  1. #1

    SPI and Digole Display Clock divider problems.

    Hardware:

    I am trying to get my Teensy to communicate with the Digole display over an SPI interface however I can not seem to get the display to respond.
    Using the Digole Library everthing works perfectly however I am forced to use 24MHz clock speed which I would rather not do.

    I believe this is a case of newb programmer missing something important, so please enlighten me as to why the following code will not work:
    Code:
    #include <SPI.h>  // include the SPI library:
    
    const int slaveSelectPin = 10;
    
    SPISettings settingsA(1600000, MSBFIRST, SPI_MODE1);
    
    void setup() {
      // set the slaveSelectPin as an output:
      pinMode (slaveSelectPin, OUTPUT);
      // initialize SPI:
      SPI.begin();
      delay(10);  //waiting for display model ready
      ClearScreen();
    }
    
    void loop(){
      WriteChar('5');
      delay(1000);
    }
    
    void ClearScreen(){
      SPI.beginTransaction(settingsA);
      digitalWrite(slaveSelectPin,LOW);
      //  send in the address and value via SPI:
      SPI.transfer('C');
      SPI.transfer('L');
      // take the SS pin high to de-select the chip:
      digitalWrite(slaveSelectPin,HIGH); 
      SPI.endTransaction();
    }
    
    void WriteChar(int integer){
      SPI.beginTransaction(settingsA);
      digitalWrite(slaveSelectPin,LOW);
      //  send in the address and value via SPI:
      SPI.transfer('TT');
      SPI.transfer(integer);
      // take the SS pin high to de-select the chip:
      digitalWrite(slaveSelectPin,HIGH);
      SPI.endTransaction(); 
    }
    Last edited by jacky4566; 11-26-2014 at 04:36 AM.

  2. #2
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    20,174
    16 MHz is almost certainly too fast for the PIC18F26K20 chip on that product.

    If you look at the PIC datasheet, table 26-17 on page 395 says the minimum SPI high and low time is "1.25 Tcy + 30" ns, and Tcy = 4 clocks at 64 MHz, from table 26-6 on page 385. That works out to be 108.125 ns, for both high and low, or a max SPI clock of 4.62 MHz.

    You should really use this (or slower) to meet the PIC18F26K20 requirements:

    Code:
    SPISettings settingsA(4620000, MSBFIRST, SPI_MODE1);
    Last edited by PaulStoffregen; 11-26-2014 at 09:24 AM.

  3. #3
    Thanks for the quick reply Paul.
    So I have adjusted the clock speed however I still can not get any response from this LCD.
    Where would be the next place to look?
    In the Arduino code they use shiftOut. This method should work in the same way as SPI.Transfer() correct?

  4. #4
    OK! So for anyone that finds this thread I did find a dirty workaround.
    Within the DigoleSerial.h I rewrote the shiftOut function.
    So I added these lines and replaced shiftOut with the new shiftOut2.
    Hope this helps someone else.
    //Rewrite the Shiftout function for the Teensy 3.1 clock speed
    //Teensy MHz || delayMicroseconds
    // 24 || 5
    // 48 || 10
    // 72 || 20
    // 96 || 20
    void shiftOut2(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val){
    uint8_t i;

    for (i = 0; i < 8; i++) {
    if (bitOrder == LSBFIRST)
    digitalWrite(dataPin, !!(val & (1 << i)));
    else
    digitalWrite(dataPin, !!(val & (1 << (7 - i))));

    digitalWrite(clockPin, HIGH);
    digitalWrite(clockPin, LOW);
    delayMicroseconds(20);
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •