View previous topic :: View next topic |
Author |
Message |
john cutler
Joined: 06 Sep 2003 Posts: 82 Location: Hot Tub, California
|
PIC Hardware SPI - need more than 8 bits at a time |
Posted: Sat Jan 18, 2003 12:48 pm |
|
|
Looking at the hardware SPI data in the Microchip PDF, it appears that it is set up ONLY to send and receive 8 bit chunks of data. I need to address a dual 12 bit DAC with a total serial data chunk of 24bits between chip enable cycles.
While I know how to do this bit-bang, I am hoping there's a way to utilize the hardware spi to accomplish the task.
Does anyone out there have any ideas?
Thank you.
John Cutler
___________________________
This message was ported from CCS's old forum
Original Post ID: 10788 |
|
|
Hans Wedemeyer Guest
|
Re: PIC Hardware SPI - need more than 8 bits at a time |
Posted: Sat Jan 18, 2003 2:59 pm |
|
|
3 times 8 = 24 !
Send three bytes !
I know when you look at DAC and ADC etc. data sheets it appears that 24 bits are needed in an uninterrupted stream. Most if not all will accept 3 bytes the invening delay for loading each byte does not infleunece the end result.
Best Regards
hansw
___________________________
This message was ported from CCS's old forum
Original Post ID: 10790 |
|
|
john cutler
Joined: 06 Sep 2003 Posts: 82 Location: Hot Tub, California
|
Re: PIC Hardware SPI - need more than 8 bits at a time |
Posted: Sat Jan 18, 2003 3:46 pm |
|
|
:=3 times 8 = 24 !
:=Send three bytes !
:=I know when you look at DAC and ADC etc. data sheets it appears that 24 bits are needed in an uninterrupted stream. Most if not all will accept 3 bytes the invening delay for loading each byte does not infleunece the end result.
:=Best Regards
:=hansw
Thanks Hans - I guess as long as I keep the chip enable (data latch) line of the 12 bit DAC stable until all three data bytes are clocked in, it won't mind and will latch the 2 12 bit words properly when the chip enable line changes state. All I need do is make sure the clock transitions are correct, and I guess the PIC does that automatically.
Thanks again
John
___________________________
This message was ported from CCS's old forum
Original Post ID: 10795 |
|
|
Hans Wedemeyer Guest
|
Re: PIC Hardware SPI - need more than 8 bits at a time |
Posted: Sat Jan 18, 2003 7:57 pm |
|
|
:=Thanks Hans - I guess as long as I keep the chip enable (data latch) line of the 12 bit DAC stable until all three data bytes are clocked in, it won't mind and will latch the 2 12 bit words properly when the chip enable line changes state. All I need do is make sure the clock transitions are correct, and I guess the PIC does that automatically.
SPI need to be configured so that it matches the device. Study the data sheet and you will soon see there are several combinations. Look for Clock Idle High/Low and Where the data is clocked on the trailing/leading edge!
CCS does allow many selections but there a a few that you need to set/clear various bits and setup the SSPCON
Use the #bit like this
these are valuse for PIC18
#bit SMP = 0XFC7.7
#bit CKE = 0XFC7.6
#bit CKP = 0XFC6.4
value for PIC16
#bit SMP = 0X94.7
#bit CKE = 0X94.6
#bit CKP = 0X14.4
Then you can simply SMP=1; or SMP=0; Etc. I find this cleaner than bit_set(address,bit); but that works also.
Which DAC are you using, may be I've already used it and can advise the correct setting.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10796 |
|
|
juan Guest
|
Re: PIC Hardware SPI - need more than 8 bits at a time |
Posted: Tue Jan 21, 2003 10:46 am |
|
|
Do you know the configuration for the 16 bits AD7715 ?????
___________________________
This message was ported from CCS's old forum
Original Post ID: 10855 |
|
|
Hans Wedemeyer Guest
|
Re: PIC Hardware SPI - need more than 8 bits at a time |
Posted: Tue Jan 21, 2003 10:03 pm |
|
|
I have not used this device, but the data sheet Page 22 Rev.C
is very clear about the SPI interface.
The clock idles High and the data is strobed in in the middle of the data, so the standard CCS routine should work
Untested example for master:
setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4 );
Clock speed can be set as needed.
___________________________
This message was ported from CCS's old forum
Original Post ID: 10876 |
|
|
R.J.Hamlett Guest
|
Re: PIC Hardware SPI - need more than 8 bits at a time |
Posted: Wed Jan 22, 2003 10:02 am |
|
|
:=I have not used this device, but the data sheet Page 22 Rev.C
:=is very clear about the SPI interface.
:=
:=The clock idles High and the data is strobed in in the middle of the data, so the standard CCS routine should work
:=
:=Untested example for master:
:=
:=setup_spi(SPI_MASTER | SPI_L_TO_H | SPI_CLK_DIV_4 );
:=
:=Clock speed can be set as needed.
It is also worth looking at the descriptions of the SPI lines (and especially the data clock), where the following text is present:
"Serial clock. Logic Input. An external serial clock is applied to this input to access serial data from the AD7715. This serial clock can be a continuous clock, with all data transmitted in a continuous stream of pulses. Alternatively, it can be a noncontinuous clock with the information being transmitted to the AD7715 in smaller batches of data."
Page 24 of the data sheet then adds the following to this:
"Most of the registers on the AD7715 are 8-bit registers.
This facilitates easy interfacing to the 8-bit serial ports of microcontrollers.
Some of the registers on the part are up to 16 bits, but
data transfers to these 16-bit registers can consist of a full 16-bit transfer or two 8-bit transfers to the serial port of the microcontroller.
DSP processors and microprocessors generally transfer
16 bits of data in a serial data operation. Some of these processors,
such as the ADSP-2105, have the facility to program the
amount of cycles in a serial transfer. This allows the user to
tailor the number of bits in any transfer to match the register
length of the required register in the AD7715."
So the chip is specifically designed to interface to 8 bit SPI ports, with two transfers for each word, but on processors that support a programmable word lengths for the SPI interface, 16 bit transfers can be used instead for the larger registers.
Best wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 10891 |
|
|
|