There is a Problem with hardware SPI with on Arduino Mega and I need some help.
I already work with an Arduino DUE using hardware SPI Hardware SPI with
sclk=76, data=75
for the communication to an QVGA Display.
Therefore I include SPI.H and Ucglib.h
using
Ucglib_ILI9341_18x240x320_HWSPI ucg(/cd=/ 26 , /cs=/ 24, /reset=/ 22);
It works really quick and fine.
Then I try the same with an Arduino Mega changing Hardware Pins to
sclk=52, data=51; including SPI.H and Ucglib.h
using
Ucglib_ILI9341_18x240x320_HWSPI ucg(/cd=/ 26 , /cs=/ 24, /reset=/ 22);
and of course I use an 4050 level shifter.
Setting
pinMode(53, OUTPUT);
digitalWrite(53, HIGH);
but nothing works at all.
If I change to software SPI with
Ucglib_ILI9341_18x240x320_SWSPI ucg(/sclk=/ 52, /data=/ 51, /cd=/26 , /cs=/ 24, /reset=/22);
it works but only very slowly.
who is familiar with hadware SPI on Arduino Mega and can help me?
If you don't use MISO, the slave can't respond to the master.
Also a possible:
Note about Slave Select (SS) pin on AVR based boards
All AVR based boards have an SS pin that is useful when they act as a slave controlled by an external master. Since this library supports only master mode, this pin should be set always as OUTPUT otherwise the SPI interface could be put automatically into slave mode by hardware, rendering the library inoperative.
It is, however, possible to use any pin as the Slave Select (SS) for the devices. For example, the Arduino Ethernet shield uses pin 4 to control the SPI connection to the on-board SD card, and pin 10 to control the connection to the Ethernet controller.
And lastly the speed. Crank it down to 8000000 or 4000000 and no more than 16000000.
It's probably the same for most if not all AVR's running at 16MHz.
That 4MHz is bits per second, 500K chars/sec as opposed to 115200 baud = 11520 chars/sec. SPI has no start and stop characters.
But wait!
If your SPI scheme transfers data from slave to master as the master transfers data out, you get double throughput out of SPI. Technically you could get 2MB/sec through SPI.