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

SPI communication between PIC18F4550 and ADS1254 ADC

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



Joined: 29 Mar 2013
Posts: 24

View user's profile Send private message

SPI communication between PIC18F4550 and ADS1254 ADC
PostPosted: Mon Apr 01, 2013 8:52 pm     Reply with quote

Hi!!!! everyone

I'm trying make a SPI communication between PIC 18F4550 and ADS1254 (Delta sigma ADC) but the adc sends a 24 bits word into a 1 bit stream.
My trouble is:

1. How can I receive the data if the function SPI_READ() just give me 8 bits ?
2Reading the compiler manual, it makes mention that by using #USE SPI, I can modify the word size to be sent and specify the name of the variable where is stored this word.
Is not it right?

2. The ADS1254 indicate across BIT SDO which the data is ready. and then the data is shifted out in the same pin, I suppose the #INT_SSP and read_spi() give it to me the result or I should wait some time to receive data.
Like you see, I have many questions.
I hope that someone can help me smile.
best regard!!!!!! Very Happy
alan



Joined: 12 Nov 2012
Posts: 350
Location: South Africa

View user's profile Send private message

PostPosted: Mon Apr 01, 2013 11:52 pm     Reply with quote

The way I do it, maybe there are better ways:
Code:

output_low(CS);
b1=spi_read();
b2=spi_read();
b3=spi_read();
output_high(CS);

JosedeJesusC



Joined: 29 Mar 2013
Posts: 24

View user's profile Send private message

PostPosted: Tue Apr 02, 2013 10:31 am     Reply with quote

Hi Alan thanks for your reply !!

OK! like I said there are options to drive the amount of bits you want to send but I'm not sure.
I'm going to use your example code, if the way using the preprossesing directive #USE SPI is right I am in glad to tell you.

best regards!!!
alan



Joined: 12 Nov 2012
Posts: 350
Location: South Africa

View user's profile Send private message

PostPosted: Tue Apr 02, 2013 11:13 am     Reply with quote

Yes that will be when you use software SPI and write your own bit-banging functions.

Regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Apr 02, 2013 11:23 am     Reply with quote

Quote:
output_low(CS);
b1=spi_read();
b2=spi_read();
b3=spi_read();
output_high(CS);

These spi_read() statements will not generate the SPI clock signal,
so no data will be clocked out of the SPI slave chip. You must have
a parameter for spi_read(), which is usually 0x00. Then a clock signal
will come out of the SCLK pin on the master. See the 24-bit read
routine in the sample code in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=41059

All the things that are done in that sample code may not apply to the
ADS1254 chip, but at least you can see how to do an SPI driver.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Apr 02, 2013 12:42 pm     Reply with quote

I have used this part , and it helps to understand HOW to use it.

Do you change the input MUX settings or stay on a single port ?

There are ways to get into trouble with the ADS1254 in terms failure to
understand the Dout/Dready function.

Your code makes no provision for knowing WHEN to begin clocking out the data you want. Otherwise you risk getting junk results

the datasheet page 11,12,13 are essential reading if you want your driver to actually work.

perhaps you'd like to post more code ?
JosedeJesusC



Joined: 29 Mar 2013
Posts: 24

View user's profile Send private message

PostPosted: Tue Apr 02, 2013 3:38 pm     Reply with quote

Hi asmboy and PCM Programmer.
Thanks so much both for you reply!!!!

I have some doubts.
The master must wait 36 MCLK cycles till data is ready to read like the data sheet says because the pin SDO/DRDY has double functions as a flag to indicate the data is ready and as a port to send the 1bit stream that represents the result.
The function spi_read(0) or #INT_SSP makes all that by default ------ or I must get in a delay before to read Confused

what does mean that? SPI_H_TO_L | SPI_XMIT_L_TO_H .

About with SPI communication.... if the master works with 48 MHz and SPI prescaler of 16,
Then the frequency of SPI should be 3 MHz. is it right?.

Respect with the MUX. I work with one channel. But after to get the driver of the DAS1254, I'm going to extend to 4 channels. Like you said asmboy I will get in trouble if the master makes not following steps:
Do not change from channel till the data is ready.
So first read the data and then change from a channel to other.
Hide first 5 results because this ADC works averaging old data.

I'll post the code please wait me a time.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Apr 02, 2013 6:40 pm     Reply with quote

the code i wrote to support this part uses bit banging NOT the spi interface at all.
That made it much simpler to manage the data stream, at least for my use of the part.

LOOK at the timing diagrams and keep your eye on SCLK after last bit of data is clocked out..

it is just not very suited to simple SPI transfer , IMHO-

let me add that Dout is used as a combined "ready flag" and data_out pin on MANY of the BB/TI low end A/D chips, and once you master this one, many others become EZ to control as well.
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