Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Hardware SPI with BoostC weirdness

Status
Not open for further replies.

futz

Active Member
EDIT: Never mind! I thought about it some more and realized I had my clock polarity wrong. Changed it and she works perfect! :D


I wrote this little function to send a byte out the SPI, copying the way I used to do it in assembler (which worked fine).
Code:
void spi_out(unsigned char digit)
{
	unsigned char junk;
	sspbuf=digit;
	while(!sspstat.BF);
	junk=sspbuf;
}
But it doesn't work. The byte in the receiving shift register appears to be shifted by one bit, and of course my 7-seg displays junk. If I remove the sspstat.BF test, it displays correctly, but doesn't work right (hard to explain).

The generated assembly code looks fine:
Code:
52:                void spi_out(unsigned char digit)
53:                {
54:                	unsigned char junk;
55:                	sspbuf=digit;
  008A    501F     MOVF 0x1f, W, ACCESS
  008C    6EC9     MOVWF 0xfc9, ACCESS
56:                	while(!sspstat.BF);
  008E    A0C7     BTFSS 0xfc7, 0, ACCESS
  0090    D7FE     BRA 0x8e
57:                	junk=sspbuf;
  0092    50C9     MOVF 0xfc9, W, ACCESS
  0094    6E20     MOVWF 0x20, ACCESS
58:                }
  0096    0012     RETURN 0

Here's the (working) asm code I ported from:
Code:
spisend	movwf	SSPBUF
	BANKSEL	SSPSTAT
spiloop	btfss	SSPSTAT,BF
	goto	spiloop
	BANKSEL	SSPBUF
	movf	SSPBUF,W
	return
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top