View previous topic :: View next topic |
Author |
Message |
JosedeJesusC
Joined: 29 Mar 2013 Posts: 24
|
SPI communication between PIC18F4550 and ADS1254 ADC |
Posted: Mon Apr 01, 2013 8:52 pm |
|
|
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: 357 Location: South Africa
|
|
Posted: Mon Apr 01, 2013 11:52 pm |
|
|
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
|
|
Posted: Tue Apr 02, 2013 10:31 am |
|
|
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: 357 Location: South Africa
|
|
Posted: Tue Apr 02, 2013 11:13 am |
|
|
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
|
|
Posted: Tue Apr 02, 2013 11:23 am |
|
|
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
|
|
Posted: Tue Apr 02, 2013 12:42 pm |
|
|
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
|
|
Posted: Tue Apr 02, 2013 3:38 pm |
|
|
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
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
|
|
Posted: Tue Apr 02, 2013 6:40 pm |
|
|
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. |
|
|
|