PCF 8814 soft SPI to hard SPI help

hi,
can someone help me to change a library that uses shiftOut to use hardware spi. I am fairly new to working with microcontrollers. using a pcf8814 and shiftOut is too slow for what I need. I should only change the function that sends data to the lcd, someone correct me if I'm wrong: P.

void PCF8814::send(unsigned char type, unsigned char data)
{
digitalWrite(this->pin_sdin, type);
digitalWrite(this->pin_sce, LOW);
digitalWrite(this->pin_sclk, HIGH);
digitalWrite(this->pin_sclk, LOW);
shiftOut(this->pin_sdin, this->pin_sclk, MSBFIRST, data);
digitalWrite(this->pin_sce, HIGH);
}

What performance do you need?
What platform?

in the reference there is an intro about SPI - http://arduino.cc/en/Reference/SPI -
on the right side there are functions to be used.

should get you started

i read the reference about spi but nothing seams to work. I use arduino uno, and about the speed, it takes about 200 ms to send data that fill the lcd, I use the lcd and also a wireless serial connection with another arduino and because that 200 ms the communication is slow

you might take a look at my fastshiftout

To include SPI one need to look at the library at a whole, where did you get it?
do you have a link?

200ms == 200milli seconds ?

that is quite a time for a screen full of data. How much bytes are we talking about?

Hardware SPI is quite easy to implement. Below is an example to send one data byte to a device at a 8 mhz clock rate on an Uno. This may be too high for some spi devices. To change, you simple change the clock divider value.

You can find the spi.cpp and spi.h files in the arduino_install_dir\hardware\arduino\avr\libraries\SPI folder.

//
#include <SPI.h>              // provide prototypes for the SPI library
//
// SPI Ports defines (for Arduino Uno)
//
#define SS         10               // Pin mapping to Arduino = SELECT
#define MOSI      11               // Pin mapping to Arduino = Master Out Slave In
#define SCLK      13               // Pin mapping to Arduino = Serial clock
#define MISO      12               // Pin mapping to Arduino = Master IN slave OUT
//
#define myDevice 0x3f
//
void setup()
{
  pinMode (SS, OUTPUT);
  SPI.begin();
  SPI.setClockDivider(SPI_CLOCK_DIV2);
  SPI.setDataMode(SPI_MODE0);
  SPI.setBitOrder(MSBFIRST);
  sendSPI(myDevice,0x10);
  SPI.end();
}

void sendSPI(int device, int tx_data)
{
  PORTB &= 0b11111011;          // set CS low with direct write to digital pin 10
  SPI.transfer(device);               // device address write bit already 1ow
  SPI.transfer(tx_data); 
  PORTB |= 0b00000100;          // set CS high with direct write to digital pin 10
}

void loop(){}

I wanna thank you for your replay Rob Tillaart, I will look at your fastshiftout library and try it

The library i use is here,

the FastShiftOut library is still slow and i modify my send function with spi and still not workin. my connection pin are : sclk = 13, sdin = 11, reset = 7, sce = 10
and the modified cod:

void PCF8814::send(unsigned char type, unsigned char data)
{
    digitalWrite(this->pin_sdin, type);
    digitalWrite(this->pin_sce, LOW);
	digitalWrite(this->pin_sclk, HIGH);
	digitalWrite(this->pin_sclk, LOW);
	
	pinMode (this->pin_sce, OUTPUT);
	SPI.begin();
	SPI.setClockDivider(SPI_CLOCK_DIV16);
	SPI.setDataMode(SPI_MODE2);
	SPI.setBitOrder(MSBFIRST);
		PORTB &= 0b11111011;        	          		  
		SPI.transfer(data); 
		PORTB |= 0b00000100;         	  
	SPI.end();
	
    //shiftOut(this->pin_sdin, this->pin_sclk, MSBFIRST, data);
    digitalWrite(this->pin_sce, HIGH);
}

Of course it does not function.

You have initialization code in your send routine. The send routine should be very simple:

PORTB &= 0b11111011; // set the CS line low
SPI.transfer(data);
PORTB |= 0b00000100; // return CS to high

There is some other handling that needs to be done, I think the "type" variable is a flag for a command or data. You'll have to sort that out yourself.

The initialization code gets added to the ::begin subroutine:

SPI.begin();
SPI.setClockDivider(SPI_CLOCK_DIV16);
SPI.setDataMode(SPI_MODE0);
SPI.setBitOrder(MSBFIRST);

The PCF8544 samples the data input on the leading rising edge of the SCK line so your setup of SPI_MODE2 is incorrect which samples on the leading failing edge.

It should be SPI_MODE0 to sample on the leading rising edge.

The SPI:end(); call goes into whatever code gets called when the program is done with the SPI port.

The PCF8814 also needs needs hardware pins PS0 and PS1 set correctly in hardware to function in SPI mode, I do not know if this was done in the display you are using, it may well be setup for I2C mode. You can find the datasheet on SourceForge here: http://mylcd.sourceforge.net/files/pcf8814.pdf

As an afterthought, why don't you have a look at a library that uses hardware SPI for that display: