|
|
View previous topic :: View next topic |
Author |
Message |
slahiri Guest
|
How can I write 16 bit data using SPI |
Posted: Sun Mar 09, 2003 8:03 pm |
|
|
<font face="Courier New" size=-1>A) I need to send 000|00000|00011000 using SPI. This is what I wrote, will this work.
void set_voltage (int choice)
{
setup_spi(SPI_MASTER, SPI_H_TO_L , SPI_CLK_DIV_16);
output_low (PIN_C3);
delay_us(30);
if (choice == 1 || choice ==2)
spi_write(24);
spi_write(0)
delay_us(30);
output_high(PIN_C3);
}
b) Can I configure SPI to some other PORTs also other than PORTC, because I need two SPI interface.</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12480 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: How can I write 16 bit data using SPI |
Posted: Mon Mar 10, 2003 4:23 pm |
|
|
<font face="Courier New" size=-1>:=<font face="Courier New" size=-1>A) I need to send 000|00000|00011000 using SPI. This is what I wrote, will this work.
:=
:=void set_voltage (int choice)
:={
:=
:= setup_spi(SPI_MASTER, SPI_H_TO_L , SPI_CLK_DIV_16);
:= output_low (PIN_C3);
:= delay_us(30);
:= if (choice == 1 || choice ==2)
:= spi_write(24);
:= spi_write(0)
:= delay_us(30);
:= output_high(PIN_C3);
:=
:=}
:=
:=b) Can I configure SPI to some other PORTs also other than PORTC, because I need two SPI interface.</font>
---------------------------------------------------------
Your total number of bits is 16, and that's a multiple of 8,
so I think you can use the hardware SPI functions.
However, your sample data shows that you want to send 8 bits
of 0's first. Then it shows 00011000 coming after that.
So your code above is not in the correct order. You need
to change it to put out the 0 byte first. Like this:
spi_write(0);
spi_write(24);
Also, you have this test:
if (choice == 1 || choice ==2)
You need to carefully check which SPI byte should be
affected by that test. Is it the 0 byte or the 0x24 byte ?
-------------------
On your 2nd question:
You can only use the built-in SPI functions with the hardware
SPI port. If you want a 2nd SPI port, you have to do it in
software. For an example, go here, and look at the sample
code for the LTC1298:
<a href="http://www.phanderson.com/PIC/PICC/index.html" TARGET="_blank">http://www.phanderson.com/PIC/PICC/index.html</a>
--
</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 12510 |
|
|
|
|
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
|