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.

PIC SPI, how to tell when SSBUF is finished transmitting?

Status
Not open for further replies.

Fred.Amoson

New Member
I'm working with a PIC with hardware SPI. In order to send the data through the SPI you just write to register SSPBUF. However, I've been looking through the data sheet and I can't find what tells you that the transfer is complete. Do you have to add a delay yourself (as I am doing now) or is there some variable I can check to see when it is done? I've read all through the datasheet, and tried different things, but nothing has worked except for the delay yet.
 
16F88 in asm
Code:
spisend	movwf	SSPBUF
	BANKSEL	SSPSTAT
spiloop	btfss	SSPSTAT,BF
	goto	spiloop
	BANKSEL	SSPBUF
	movf	SSPBUF,W
	return

16F819 in asm
Code:
spisend	movwf	SSPBUF
	BANKSEL	SSPSTAT
spiloop	btfss	SSPSTAT,BF
	goto	spiloop
	BANKSEL	SSPBUF
	movf	SSPBUF,W
	return

dsPIC 30F4013 in C
Code:
int spiout(int send)
{
	CS = 0;							//CS low
	SPI1BUF = send;
	while(!SPI1STATbits.SPIRBF){}
	CS = 1;
	return SPI1BUF;
}

And if your program is pressed for time you can use an interrupt.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top