View previous topic :: View next topic |
Author |
Message |
geolover
Joined: 08 Feb 2011 Posts: 18
|
How can I write 16-bit in SPI with a PI24FJ? |
Posted: Wed Feb 23, 2011 6:47 am |
|
|
I used a PIC24FJ128GA010 for my sensor project, I found that CCS compiler is able to set the SPI to 16-bit mode, however, spi_write command can only write 8-bit data, is there a way that I could get the PIC simply sending 16-bit data over the SPI without sending 8-bit data twice with SPI set to 8 bit mode? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19496
|
|
Posted: Wed Feb 23, 2011 8:06 am |
|
|
No.
This is all the CCS software does.
It is worth understanding that SPI, has a buffer register. There is the buffer, and the shift register. You can load a second byte into the buffer register, as soon as the first byte transfers to the shift register, so the two bytes are sent one after the other, just as if there was a 16bit write command.
However it doesn't matter even if there is a gap betwene bytes. The whole point about SPI, is that it includes a clock, so couldn't actually care if the data is sent one bit at a time, two bits at a time etc..
Best Wishes |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Wed Feb 23, 2011 8:09 am |
|
|
Quote: | is there a way that I could get the PIC simply sending 16-bit data over the SPI without sending 8-bit data twice with SPI set to 8 bit mode? |
Yes, by writing to the PIC24 SFR registers directly. You have to handle the status bits yourself. But I don't however understand, what's your problem with sending two bytes with spi_write()? |
|
|
geolover
Joined: 08 Feb 2011 Posts: 18
|
|
Posted: Fri Feb 25, 2011 8:56 am |
|
|
FvM wrote: | Quote: | is there a way that I could get the PIC simply sending 16-bit data over the SPI without sending 8-bit data twice with SPI set to 8 bit mode? |
Yes, by writing to the PIC24 SFR registers directly. You have to handle the status bits yourself. But I don't however understand, what's your problem with sending two bytes with spi_write()? |
Thank you!
I would like to write a 16-bit sine wave look-up table and interface it with a DA Converter to create a DDS module. Each sine wave sample is 16-bit, and I don't know how can I do it by writing 8-bit... |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Fri Feb 25, 2011 9:06 am |
|
|
e.g.
Code: | spi_write(make8(data16,1));
spi_write(make8(data16,0)); |
|
|
|
|