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 support@ccsinfo.com

PIC Hardware SPI - need more than 8 bits at a time

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



Joined: 06 Sep 2003
Posts: 82
Location: Hot Tub, California

View user's profile Send private message

PIC Hardware SPI - need more than 8 bits at a time
PostPosted: Sat Jan 18, 2003 12:48 pm     Reply with quote

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
PostPosted: Sat Jan 18, 2003 2:59 pm     Reply with quote

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

View user's profile Send private message

Re: PIC Hardware SPI - need more than 8 bits at a time
PostPosted: Sat Jan 18, 2003 3:46 pm     Reply with quote

:=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
PostPosted: Sat Jan 18, 2003 7:57 pm     Reply with quote

:=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
PostPosted: Tue Jan 21, 2003 10:46 am     Reply with quote

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
PostPosted: Tue Jan 21, 2003 10:03 pm     Reply with quote

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
PostPosted: Wed Jan 22, 2003 10:02 am     Reply with quote

:=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
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