PDA

View Full Version : problems using HW SPI for NHD-2.8-25664UCY2 display with Teensy 3.1 and audio board



Al Dodson
02-05-2016, 03:23 PM
I've see other folks in this forum having similar problems.
The display is NHD-2.8-25664UCY2.

The MOSI (pin 7) and SCK (pin 14) pins are being used by the SD card and serial flash memory.
Yet, I can only make the display work using the standard SPI pins MOSI (pin 11), SCK (pin 13), -CS (pin 10) and RS (pin 9).
This will certainly interfere with the audio board which uses pins 11 & 13 for I2S communication with the codec.

Code is posted below and attached .ino file

Thanks in advance to anyone who has some insight into this situation.

/*
This is eventually going to be an audio project. An audio tester of sorts
that generates test signals and displays the response. A little audio
spectrum analyzer. The audio portion, FFTs and all, are working ok. Actually,
the project will work running the display with software SPI. It's just that
the screen updates take about 450ms. I need a faster rate.

I'm trying to get the Teensy 3.1 to run an NHD-2.8-25664UCY2 OLED display
using the alternative hardware SPI pins. I see from the schematic that the
standard SPI pins are used by the audio codec chip for I2S. My project will
not be using the SD card or serial flash memory. So, I thought it would be
OK to 'borrow' pin 10 for the display's -CS line. It works using pin 10.
Using the same logic, it seems OK to 'borrow' pin 6. But that doesn't work.
I see no activity on the -CS line on my oscilloscope in that condition.
Similarly, I can't move the register select line(rs), either. I using pin 9.
If I try pin 8, it doesn't work. So, I seem to be stuck using the standard pins:

rs = pin 9
cs = pin 10
sd = pin 11
sck = pin 13

The code below works.

If I re-wire and include the SPI.setMOSI(7) and SPI.setSCK(14) commands, the
display remains blank and no activity on the SCK line.

I hope you can shed some light on this situation. I love the Teensy board,
by the way, and the audio board. And I'm kinda stuck on this display for now.


*/
//
#include "U8glib.h"
#include <u8g_teensy.h>
#include <SPI.h>
#include <Audio.h>
#include <Wire.h>
#include <SD.h>
#include <SerialFlash.h>
//
int rst = 2; // reset pin - your choice
int rs = 9; // register select pin - your choice
int cs = 10; // SPI ss
int sd = 7; // SPI mosi
int sck = 14; // SPI sck
int test = 16;
byte k = 0; // loop counter
// constuctor for u8glib - software SPI
// U8GLIB_NHD31OLED_2X_BW u8g(sck, sd, cs, rs, rst);
// constuctor for u8glib - hardware SPI
U8GLIB display(&u8g_dev_ssd1322_nhd31oled_2x_bw_hw_spi, u8g_com_hw_spi_fn);
U8GLIB_NHD31OLED_2X_BW u8g(cs, rs, rst);
//
// ************************************************** *********************
void setup(void) {
Serial.begin(9600);
// select font
u8g.setFont(u8g_font_unifont);
// flip screen, if required
u8g.setRot180();
// set SPI backup if required
//u8g.setHardwareBackup(u8g_backup_avr_spi);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 ) {
u8g.setColorIndex(255); // white
}
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT ) {
u8g.setColorIndex(3); // max intensity
}
else if ( u8g.getMode() == U8G_MODE_BW ) {
u8g.setColorIndex(1); // pixel on
}
else if ( u8g.getMode() == U8G_MODE_HICOLOR ) {
u8g.setHiColorByRGB(255,255,255);
}
pinMode(rst,OUTPUT);
pinMode(rs,OUTPUT);
pinMode(cs,OUTPUT);
pinMode(sck,OUTPUT);
pinMode(sd,OUTPUT);
pinMode(test,OUTPUT);
//
digitalWrite(rst,HIGH);
digitalWrite(rs,HIGH);
digitalWrite(cs,HIGH);
digitalWrite(sck,HIGH);
digitalWrite(sd,HIGH);
digitalWrite(test,HIGH);
//
// reset the display
digitalWrite(rst,LOW);
delay(10);
digitalWrite(rst,HIGH);
//
// empty loop to clear the screen
u8g.firstPage();
do {
} while( u8g.nextPage() );
//
//SPI.setMOSI(7);
//SPI.setSCK(14);
//
}
//
// ************************************************** *********************
void loop(void) {
digitalWrite(test,HIGH);
delay(1);
digitalWrite(test,LOW);
// picture loop
k = k -1;
u8g.firstPage();
do {
draw();
} while( u8g.nextPage() );
}
// ************************************************** *********************
void draw(void) {
u8g.drawStr(255 -k, 35, "Hello World!");
}
// ************************************************** *********************

Al Dodson
02-05-2016, 07:03 PM
I'm replying to my own post.

The constructor I'm using for HW SPI for this display is U8GLIB_NHD31OLED_2X_BW u8g(cs, rs, rst);
You don't specify the SCK or MOSI pins. They're 'assumed' by the library. So, how does one inform the u8glib library that
these pins have moved to the alternative pins? Maybe u8glib only works for the standard pins, I don't know.

PaulStoffregen
02-05-2016, 07:36 PM
They're 'assumed' by the library. So, how does one inform the u8glib library that
these pins have moved to the alternative pins? Maybe u8glib only works for the standard pins, I don't know.

I haven't used this library, so I don't know if this will really work, but perhaps the same way that works for the SD library will work for u8glib?

Look at File > Examples > Audio > WavFilePlayer for the example. Notice the 2 lines right before SD.begin(). Give those a try. Please let us know if it works or fails?

Al Dodson
02-05-2016, 08:28 PM
Yes, I've used the SPI.setMOSI(7) & SPI.setSCK(14) commands. See line 102 of the code I posted. If I uncomment those lines and leave the display wired such that sd = pin 11 & sck = pin 13, it works ok. As if it ignored those commands. If I move the wires such that sd = pin 7 & sck = pin 13, the display remains blank and there's no activity on the sck line.

I'm thinking of getting the DISPLAY_ILI9341 for $8.00. It looks like you've tested this model for HW SPI operation and verified that it works. Do you recommend that model for projects using teensy 3.1 and the audio board? Maybe I could save myself some time & grief by just going with a different display.

PaulStoffregen
02-05-2016, 09:10 PM
Do you recommend that model for projects using teensy 3.1 and the audio board?

Yes.

In fact, if you watch the audio tutorial video, you can see the display used together with the library. That part is near the very end of the video.