Interface Winstar OLEDs using the SPI interface

nick12ab

Senior Member
#1


Anyone who has read the datasheet for the Winstar OLEDs that Rev-Ed sell as part of the AXE133Y should have noticed a brief mention of the SPI interface and a vague description of how the interface works. However it doesn't tell you how to use the SPI interface!

Luckily, badge engineering firm Newhaven Display has found out for us! Some jumpers on the back of the OLED module simply have to be moved around, then the display can be used in SPI mode.

Jumper selections

[TABLE="class: grid"]
[TR]
[TD]MPU interface[/TD]
[TD]L_PS_H[/TD]
[TD]J68_J80[/TD]
[TD]L_SHL_H[/TD]
[TD]L_CS_H[/TD]
[TD]JCS[/TD]
[/TR]
[TR]
[TD]6800 parallel (default)[/TD]
[TD]H[/TD]
[TD]J68[/TD]
[TD]H[/TD]
[TD]L[/TD]
[TD]Don't Care[/TD]
[/TR]
[TR]
[TD]8080 parallel[/TD]
[TD]H[/TD]
[TD]J80[/TD]
[TD]H[/TD]
[TD]L[/TD]
[TD]Don't Care[/TD]
[/TR]
[TR]
[TD]SPI[/TD]
[TD]L[/TD]
[TD]Don't Care[/TD]
[TD]H[/TD]
[TD]Open[/TD]
[TD]Short[/TD]
[/TR]
[/TABLE]
To convert a Winstar WEH001602E 16x2 OLED as supplied by Rev-Ed to SPI, simply move the L_PS_H resistor from the H side to the L side and the L_CS_H resistor to JCS.



Pinout of the OLED module in SPI mode

[TABLE="class: grid"]
[TR]
[TD]Pin[/TD]
[TD]Symbol[/TD]
[TD]Function[/TD]
[/TR]
[TR]
[TD]1[/TD]
[TD]Vss[/TD]
[TD]Ground[/TD]
[/TR]
[TR]
[TD]2[/TD]
[TD]Vdd[/TD]
[TD]Supply voltage[/TD]
[/TR]
[TR]
[TD]3-11[/TD]
[TD]NC[/TD]
[TD]Not connected[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]SCL[/TD]
[TD]Serial Clock Signal[/TD]
[/TR]
[TR]
[TD]13[/TD]
[TD]SDO[/TD]
[TD]Serial Data Output Signal (connected to PICAXE data input where used)[/TD]
[/TR]
[TR]
[TD]14[/TD]
[TD]SDI[/TD]
[TD]Serial Data Input Signal (connected to PICAXE data output)[/TD]
[/TR]
[TR]
[TD]15[/TD]
[TD]NC[/TD]
[TD]Not connected[/TD]
[/TR]
[TR]
[TD]16[/TD]
[TD]CS[/TD]
[TD]Active LOW Chip Select signal[/TD]
[/TR]
[/TABLE]
SPI interface description by Newhaven Display



As you can see here, the RS and R/W bits need to be repeated after each instruction but not after each data byte, which is weird considering it says that CS must go high when switching between instructions and data. In the code example, a single procedure for transmitting instructions will be used and it will make CS low, send one instruction, then make CS high again. It is rare to need to send multiple instructions in a row so there's little point in going to the trouble of enabling multiple instructions to be sent in a single period of CS being low.

The code example is written for the PICAXE-08M microcontroller but can easily be adapted for different PICAXE microcontrollers. Remember that SDO on the PICAXE is connected to SDI on the OLED module. SDO on the OLED module is not used in this example (it's only needed if you want to read from the module).

All SPI transmissions on the PICAXE are bit banged which makes it very slow even compared to the AXE133 serial interface. The situation can be improved by increasing the clock speed but what's really needed is for Rev-Ed to implement this in the PICAXE firmware however this, along with the sale of SPI Winstar OLEDs, is unlikely as it would hurt sales of the AXE133 PCB and only new PICAXE chips would be able to use it effectively anyway.

PICAXE Code Example
Code:
#picaxe 08M

symbol cs = 1					'Connect cs pin of OLED to this PICAXE pin
symbol sdo = 0					'Connect sdi pin of OLED to this PICAXE pin
symbol sdopin = outpin0				'Pin variable must be for the same pin as the sdo pin constant
symbol sck = 2					'Connect scl pin of OLED to this PICAXE pin
symbol lcddata = b0
symbol loopcounter = b1

main:
	high cs							'Initialise cs pin to 1
	high sck							'Initialise sck pin to 1
	low sdo							'Initialise sdo pin to 0
	
	lcddata = %00111011 : gosub instructionOut	'Function Set: 8-bit, 2 lines, font 11
	lcddata = %00000001 : gosub instructionOut	'Clear display
	lcddata = %00001100 : gosub instructionOut	'Display on/off control: Display on, cursor off, blink off
	lcddata = %00000110 : gosub instructionOut	'Entry mode set: Increment, cursor shift
	
	lcddata = 128						'Cursor position: start of 1st line
	gosub instructionOut					'Set cursor position
	
	gosub startData
	for loopcounter = 0 to 15				'Writes the message to the display
		lookup loopcounter,("Winstar OLED SPI"),lcddata
		gosub dataOut
	next
	gosub endData
	
	lcddata = 192						'Cursor position: start of 2nd line
	gosub instructionOut					'Set cursor position
	
	gosub startData
	for loopcounter = 0 to 15				'Writes the message to the display
		lookup loopcounter,("  on PICAXE-08M "),lcddata
		gosub dataOut
	next
	gosub endData
	do : loop							'End program

instructionOut:
	low cs					'Put cs, sck and
	low sck					'sdo in correct
	low sdo					'states
	pulsout sck,1				'clock in RS (0)
	pulsout sck,1				'clock in RW (0)
	gosub outByte				'Send contents of lcddata to the display
	high cs
	return

startData:
	low cs					'Put cs, sck and
	low sck					'sdo in correct
	high sdo					'states
	pulsout sck,1				'clock in RS (1)
	low sdo
	high sck					'clock in RW (0)
	return

dataOut:
	low sck
	gosub outByte				'Send contents of lcddata to the display
	return

endData:
	high cs					'Set cs high to end data transmission
	return
	
outByte:
	sdopin = bit7				'Set sdo to bit7 (of lcddata)
	pulsout sck,1				'Pulse clock pin
	sdopin = bit6				'Set sdo to bit6
	pulsout sck,1				'Pulse clock pin
	sdopin = bit5				'Set sdo to bit5
	pulsout sck,1				'Pulse clock pin
	sdopin = bit4				'Set sdo to bit4
	pulsout sck,1				'Pulse clock pin
	sdopin = bit3				'Set sdo to bit3
	pulsout sck,1				'Pulse clock pin
	sdopin = bit2				'Set sdo to bit2
	pulsout sck,1				'Pulse clock pin
	sdopin = bit1				'Set sdo to bit1
	pulsout sck,1				'Pulse clock pin
	sdopin = bit0				'Set sdo to bit0
	high sck					'Set clock pin high
	return
The modification should also work with the 20x4 OLED modules, although their jumpers are in different places and the CS pin will also be pin 15 as it is connected to the JCS1 jumper and pin 16 isn't connected to anything.
 
Top