Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Tools
Old 23rd July 2008, 06:57 AM   #1
Default Hardware SPI with BoostC weirdness

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


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
__________________
=========================
Futz's Microcontrollers & Robotics
=========================

Last edited by futz; 23rd July 2008 at 07:02 AM.
futz is online now  
Reply

Tags
boostc, hardware, spi, weirdness

Thread Tools
Display Modes


Similar
Title Starter Forum Replies Latest
BoostC Charlieplexed PWM 32 Mike, K8LH Micro Controllers 140 27th March 2009 11:19 AM
BoostC Flaw? AtomSoft Micro Controllers 7 19th July 2008 04:32 AM
BoostC USART 18F AtomSoft Micro Controllers 9 29th June 2008 05:02 PM
math.h and lib for BoostC? futz Micro Controllers 3 31st March 2008 06:29 AM
Hi-Tech PICC weirdness futz Micro Controllers 42 29th March 2008 09:46 PM



All times are GMT. The time now is 11:51 PM.


Electronic Circuits  |  Learning Electronics
eXTReMe Tracker