View previous topic :: View next topic |
Author |
Message |
Thomas Guest
|
Question about SPI Write |
Posted: Mon Mar 10, 2003 3:07 am |
|
|
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
|
Re: Question about SPI Write |
Posted: Mon Mar 10, 2003 9:31 am |
|
|
:=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 |
Posted: Mon Mar 10, 2003 12:10 pm |
|
|
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
|
Re: Question about SPI Write |
Posted: Mon Mar 10, 2003 2:00 pm |
|
|
:=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... |
Posted: Thu May 06, 2004 6:35 am |
|
|
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
|
Use the SPI interrupt |
Posted: Thu May 06, 2004 1:17 pm |
|
|
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. |
|
|
|