SPI Question (emulate SCK from a digital pin)

Hi All,

I have a very small 64x32 SPI RGB backlit LCD display that only uses 2 wires from SPI (DATA and Clock) & 2 wires for power

to connect to the Arduino Mega 2560 i use GND/5V/MOSI/SCK

The display works perfectly, however.. I cannot connect any other SPI device as it does not have a slave select pin. (always active)

Is there a way that I can enable/disable a pin for the SerialClock for my LCD display which is completely isolated from the standard pin that the ethernet shield is using? I'm thinking maybe I can emulate a clock line?

The idea is that I want to do the following
write a basic browser based form to control the display (I have done this already with 10 standard parralel LCD displays with "ease" (okay it took a while but I got there)!

However because my LCD display is constantly receiving data, when I use the ethernet shield it is sending the information that should be going to the ethernet shield, to the LCD display as well resulting in corrupt data displayed on the LCD.

The only options I can think of are

  • emulate a clock line on a digital pin when writing to the LCD display (turn off once transfer of data is complete)
  • have a relay on the clock line running to the LCD display that is controlled by a digital pin

Many thanks for any advice given!

Best Regards

RB

Add a logic gate to provide slave select functionality.
A simple AND gate with an active High chip select on one input and SCK on the other will only let SCK toggle when the the other input is High.

You could also use software SPI on another pair of pins to drive the display. SPI does not require much code to emulate the hardware.

Software is a lot slower, why do that to yourself when controlling one IO pin, which you would need anyway if it was a normal SPI interface, to an AND gate will give you the same 8 MHz speed all the other SPI devices can use? Hardware SPI can be nearly 1uS/byte (17 clocks) with proper coding. Vs using 2 pins for a software SPI port?

Thanks for both your replies,

I am looking for a software fix if possible - my LCD display works from 2-4Mhz but I will need to check what speed the ethernet controller requires.

With regards to speed of uploads etc, it really isn't an issue I am happy for the process to be slow as long as it works if thats possible?

Order of events to be as follows

  1. Use ethernet shield for web based form
  2. send data via form to arduino
  3. disable ethernet shield
  4. enable LCD display
  5. use form data to write to LCD display
  6. disable LCD display
  7. enable ethernet shield and wait for next update from web based form

to emulate SPI on another set of pins - would i use digital or analog? do I just need to look into the original SPI library - duplicate it and change a few pin numbers.. make sure there are no conflicts and load both libraries.. or is it much more complicated than that?

Thank you for both of your advice - and if I have to.. I will use a hardware solution, I'm just trying to break away from as much additional hardware as possible,

BR Rob

Extra info -

This is the setup I use currently for the SPI

void setup() {
SPI.begin(); // INITIALISE SPI
SPI.setDataMode(SPI_MODE2); // MODE2 Required
}

If you want a hardware solution, reply #1 describes one possibility.

You are currently using the hardware SPI module built in to the Arduino. If you wish, the functions of that module can be emulated with software (using digital I/O pins), in about 10 lines of code.