Please remove
Hi flukey
From a quick look at the datasheet ...
1 GND - (internally connected to SS/CS) - I have plugged this into the Arduino GND
2 VCC- connected to 1k resistor - connected to pin 5
I think VCC can connect directly to +5V - no series resistor required.
3 CLK - Plugged into Arduino 52
4 Data (MISO/MOSI (SISO?) - Plugged into Arduino 50
CLK should go to Mega SCK - pin 52 is right.
DATA should go to Mega MOSI (master out, slave in) - that is pin 51.
int gndPin = GND //Probably not needed or incorrect
int vccPin = 5V //Probably not needed or incorrect
int clkPin = 52
int datPin = 50
int swtPin = A0
The SPI library defines the pins you need - no need for these declarations.
SPI.setClockDivider(SPI_CLOCK_DIV4); // set up arduino to 4mhz clock speed = match Q5 clock speed as per pdf
SPI.setDataMode(SPI_MODE0); // Please let me know what this should be 0,1,2,3
SPI.setBitOrder(LSBFIRST); // either LSBFIRST or MSBFIRST
Bit order should be MSBFIRST. I think the data mode is SPI_MODE2.
You need to add this at the start of setup()
SPI.begin();
To test the SPI connection, you could convert just one part of the sample code to Arduino, for example, this backlight setting code.
SPIOut(0x42) ; // cmd 0x42 writes backlight with red, green and blue
SPIOut(R) ; // value red max 0x7F
SPIOut(G) ; // value green max 0x7F
SPIOut(B) ; // value blue max 0x7F
SPIOut(0x43) ; // value for end of command is 0x43
Since the switch does not use a slave select pin, you just need to convert each SPIOut statement to SPI.transfer() statements. For example:
SPI.transfer(0x42);
SPI.transfer(0x7F);
SPI.transfer(0x00);
SPI.transfer(0x00);
SPI.transfer(0x43);
Regards
Ray