20x2 hspiout problem

DavidO

New Member
Hi there,

I'm trying to use the hardware SPI support in the 20x2 but I can't get it to work.

I've wired up a basic circuit:
- usual download circuit
- pin 13 (HSPI SDI) tied to ground via a 4k7 resistor
- pin 14 (B.4) LED + 220R to ground

with this code:

Code:
	symbol LED = B.4

	setfreq m8
	sertxd ("Starting",cr,lf)

	; Flash the LED to indicate reset
	high LED
	pause 500
	low LED

	hspisetup spimode00, spislow
main:
	sertxd ("Sending",cr,lf)
	hspiout (1)
	sertxd ("Sent")
	pause 2000
	goto main
But it never prints out "Sent" - instead it resets after a couple of seconds. I've read the recent post about hardware SPI on the 28X2 (http://www.picaxeforum.co.uk/showthread.php?t=13179&highlight=hspiout) and I think I understand it, but by my reading of it this circuit should work. I've also tried wiring the 20x2 up to an AVR ATMega8 programed to be an SPI slave with no joy but I can't be 100% sure I got the AVR program right. The 20x2 has firmware C.0.

Can anyone spot what I am doing wrong and is anyone else using hardware SPI on the 20x2?

Thanks in advance!

David
 

Janne

Senior Member
Hi,

Looking at the picaxe manual 2 page 79, i would guess that grounding the hardware spi port's input will solve the problem.
 

eclectic

Moderator
DavidO
Welcome to the Forum.
I'm sorry that I can't solve your problem; I get the same symptoms.
20X2 C.0 firmware

However, exactly the same program works on a 28X2 (B.0 firmware).

e

Hi,

Looking at the picaxe manual 2 page 79, i would guess that grounding the hardware spi port's input will solve the problem.
I've just re-tried, grounding sdi (leg 13).
No joy.

e
 

Attachments

DavidO

New Member
Hi Guys, thanks for your help.

@Janne: That seems to be the usual problem, but I've tried that already. I've also tried connecting SDI to SDO without any luck.

@eclectic: Thanks for going to the trouble of reproducing it - I'm glad it isn't just me :) Given that it works on the 28X2, I guess the 20X2 has its own particular hardware SPI gotchas.

Technical said:
Try an 'output b.7' after the hspisetup command.
Ah, interesting. I will try that when I get home from work. I tried an explicit "input" on the SDI pin but I haven't tried this. I'll let you know how it goes.

Thanks, I appreciate the help!

David
 

DavidO

New Member
Hi again,

Technical said:
Try an 'output b.7' after the hspisetup command.
That did the trick, thanks. The hardware SPI is now happily shifting data into the AVR slave. I've yet to get anything sensible back from the AVR but that is more likely to be my imperfect AVR programming than a Picaxe issue.

So, why did 'output b.7' work? :)

Thanks for your help,

David
 

Technical

Technical Support
Staff member
So, why did 'output b.7' work? :)
Ideally you should set the SCL and SDO pins as outputs on the PICAXE - as they need to be outputs to work correctly with hspi. In theory the 'hspisetup' command should automatically 'fix' this issue if you have forgotten to do so manually - by automatically converting these pins to outputs. However a small bug in the 20X2 C.0 firmware means the 20X2 does not correctly set this particular pin. Therefore the extra 'output b.7' line fixes the problem.
 

Technical

Technical Support
Staff member
This will be fixed in the next (future) firmware release. There is no release date as yet.

The workaround is very straight forward. The next 20X2 compiler release will also auto-correct the C.0 version with the workaround anyway.
 
Last edited:

boriz

Senior Member
“There is no release date as yet.”

Prolly wise. Likely to be more teething troubles yet. Full respect to the people who are finding these issues, at their own expense, on our behalf.
 

inglewoodpete

Senior Member
Hi folks, I have a related question: do I need to connect SPI SDI pin if I only need SPI output? Is it ok to leave it floating?
Thx - Pops.
No, hSPIOut works without any hardware or software configuration of the SDI pin.

As an aside, SPI often operates as an exchange of data (send a byte and, at the same time, receive a byte). As far as I know this "full duplex" mode is not possible in a PICAXE: It can only do an hSPIIn or hSPIOut. A disappointing feature that forced me to use another chip type.
 
Top