CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Question about SPI Write

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Thomas
Guest







Question about SPI Write
PostPosted: Mon Mar 10, 2003 3:07 am     Reply with quote

Hello,
Will it be data overflow if I do the following?

spi_write(data1);
spi_write(data2);
spi_write(data3);
spi_write(data4);
spi_write(data5);

Do I need a delay between each "spi_write"? Will data1 get overwritten by data5? Thank you in advance!
Thomas
___________________________
This message was ported from CCS's old forum
Original Post ID: 12483
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Question about SPI Write
PostPosted: Mon Mar 10, 2003 9:31 am     Reply with quote

:=Hello,
:=Will it be data overflow if I do the following?
:=
:=spi_write(data1);
:=spi_write(data2);
:=spi_write(data3);
:=spi_write(data4);
:=spi_write(data5);
:=
:=Do I need a delay between each "spi_write"? Will data1 get overwritten by data5? Thank you in advance!
:=Thomas

I use it in this manner to send an recieve 5 bytes. The outgoing data1 byte is over written by the incomming data1 byte. The delay between writes allows the slave time to read and write to the SPI buffer. This works from one pic to another.

Master code.

data1=spi_write(data1);
delay_cycles(8);
data2=spi_write(data2);
delay_cycles(8);
data3=spi_write(data3);
delay_cycles(8);
data4=spi_write(data4);
delay_cycles(8);
data5=spi_write(data5);

Slave code.

data1=spi_write(data1);
data2=spi_write(data2);
data3=spi_write(data3);
data4=spi_write(data4);
data5=spi_write(data5);
___________________________
This message was ported from CCS's old forum
Original Post ID: 12495
thomas
Guest







Re: Question about SPI Write
PostPosted: Mon Mar 10, 2003 12:10 pm     Reply with quote

Thank you for your reply. The delay time you mentioned depends on your SPI_CLK_DIV_X value. Is it correct?

Another thing, is there a way to tell when the last byte is sent? I need to de-select the ICs on the SPI bus after the SPI transmision is done. Thanks!
Thomas
___________________________
This message was ported from CCS's old forum
Original Post ID: 12499
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Question about SPI Write
PostPosted: Mon Mar 10, 2003 2:00 pm     Reply with quote

:=Thank you for your reply. The delay time you mentioned depends on your SPI_CLK_DIV_X value. Is it correct?
:=
:=Another thing, is there a way to tell when the last byte is sent? I need to de-select the ICs on the SPI bus after the SPI transmision is done. Thanks!
:=Thomas

In this example the delays are there to allow time for the slave to read and load the SPI buffer. The SPI_CLK_DIV_X value determines the rate of the SPI clock relative to the system clock.

Master code.

Activate Slave Select pin
data1=spi_write(data1);
delay_cycles(8);
data2=spi_write(data2);
delay_cycles(8);
data3=spi_write(data3);
delay_cycles(8);
data4=spi_write(data4);
delay_cycles(8);
data5=spi_write(data5);
Deactivate Slave Select pin

Slave code.

data1=spi_write(data1);
data2=spi_write(data2);
data3=spi_write(data3);
data4=spi_write(data4);
data5=spi_write(data5);
___________________________
This message was ported from CCS's old forum
Original Post ID: 12505
steve
Guest







Yes but...
PostPosted: Thu May 06, 2004 6:35 am     Reply with quote

This example very good if you are happy for your slave to just sit and wait. What if it needs to other things?
Birdasaur



Joined: 07 Oct 2003
Posts: 29

View user's profile Send private message

Use the SPI interrupt
PostPosted: Thu May 06, 2004 1:17 pm     Reply with quote

You gotta be careful when you enable any interrupts, but if you take the slave code and drop it in an SPI interrupt handler, your slave can go about its business.

Be careful with interrupts as they change the rules a bit on how memory and the stack is handled.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group