Alarm Keypad SPI interface trouble

I have a keypad and led display that I have pulled from an old house alarm and I am trying to get the display half going with a 20X2 (haven't tried the keypad half yet). But I am having no luck. I can clock the data in manually by connecting the clock and data lines to ground but I cannot get it to work with the 20X2. Here is the code that I have been trying:
Code:
symbol clock = b.7		; clock on b.7
symbol pattern = w0     	; variable to hold the LED pattern
symbol delaytime = b15		;variable to hold the delay beetween changes

init: low clock				;Set up the chip and outputs etc
      pattern = %0000000000000001	
      delaytime = 1			
	hspisetup spimode11, spislow	
	output b.7				

main:								;Change the pattern then 
	DO
		GOSUB out_595				;gosub to output the data 
		pause delaytime
		pattern = pattern <<1
	loop until pattern=%1000000000000000
	DO
		GOSUB out_595
		pause delaytime
		pattern = pattern >>1
	loop until pattern=%0000000000000001
	goto main

out_595:			;transmit the data to the board
	hspiout (b1)
	hspiout (b0)
	return
I found the original code on this forum somewhere and then modified it for hspi and to transmit 16bits instead of 8
 

Attachments

westaust55

Moderator
you will need an extra program line like:
LET DIRSB = %xxxxxxxx
at the start of the program to make the corresponding PICAXE portB pins into outputs
for example
let DIRSB = %00000011
switches pins B.0 and B.1 to outputs

See PICAXE Manual 2 page 130
 

westaust55

Moderator
Ah, apologies on the OUTPUT vs DIRS – yes both do the same thing.
I have not used hspi in general myself as it uses the same pins as i2c comms and I typiclaly have i2c devices connected as well.



A thought (untested):
You have pin B.7 identified as a clock which corresponds with the 20X2 hspi, clock pin.
I wonder if your defining it as an output AFTER the hspisetup command is changing something and preventing the hspi control of the clock pin.
Maybe try removing the OUTPUT B.7 command (comment it out for now.

Also, you can combine the two lines
hspiout (b1)
hspiout (b0)
into
hspiout (b1,b0)


Is there some form of 595 chip on the board? if so, how are you controlling the Latching of the data to the outputs to drive the LEDs?
If you were to upload your schematic it may help. (A photo only goes so far)
 
The 20X2 that i have is firmware version C.0 so following what it said in the firmware.txt file I added the output command straight after. I will change it and see if it makes a difference.

I am in the process of making a schematic as I couldn't find one on the net. I uploaded the pictures in the mean time. The board has 3 shift registers on it and one 4093 gate.
The two SIPO are MC14021BCP and the PISO is a MC14094BCP
 

westaust55

Moderator
The 20X2 that i have is firmware version C.0 so following what it said in the firmware.txt file I added the output command straight after. I will change it and see if it makes a difference.

I am in the process of making a schematic as I couldn't find one on the net. I uploaded the pictures in the mean time. The board has 3 shift registers on it and one 4093 gate.
The two SIPO are MC14021BCP and the PISO is a MC14094BCP
Some confict of information here. My datasheets indicate:
The MC14021 is a parallel input to serial output device ie Asynchronous Parallel Input/Serial Output (MC14021B)
and
The MC14094BCP is the serial input to parallel output device. In addition to the clock and data lines to transfer you also need to latch the data to the outputs and enable the outputs (this may be permanently enabled).

are you conencting the PICAXE tio the correct shift register?

Could I respectfully suggest that you try and get it working with the X2's inbult SHIFTOUT command *still faster than bit-bashed methods) first and then progress to the still faster HSPI methods when the ahrdware is sorted.
 
Ah yes my bad. They are back to front in my last post. The enable is permanently enabled and the latch is driven with the clock pin. All the shift registers run off the same clock and data line and I am using the only Clock and Data terminals that work when I connect them to ground and manually clock the data in.
 

westaust55

Moderator
Cascading the shift registers so the clock signal acts upon all shift registers simultaneously and the data enters the first register then is passed onto subsequent registers is quite normal.
Tentatively using the clock pulses onto the Latch as well will work but your outputs will see the data ripple along.

The stated max clock frequency for the SIPO device is 1.25 MHz for Vcc = 5 Volts.
So with SPUISETUP at slow all should be well.

Cannot think of anything further as an obvious cause of the problem at this moment. Other than as mentioned to trying with the SHIFTOUT command to verify the hardware aspects first..
 
Top