View previous topic :: View next topic |
Author |
Message |
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
Interface LTC1854 with pic18f8680, SPI |
Posted: Fri Nov 25, 2011 10:47 pm |
|
|
I'm new to controller and I'm having problem in interfacing ltc1854 with pic controller through spi.
I tried to much, I'm sending data through controller, being checked by me on oscilloscope. The master (pic18f8680) sdo, read, clk, all are sending data, slave(adc) 'sdo' is not responding. Plz help. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Nov 26, 2011 3:20 am |
|
|
Use the standard nomenclature:
SDO - serial data out
SDI - serial data in
SCK - serial clock
Using 'read', doers not make it clear what line you are referring to.....
First, check your connections....
The _master_ does _not_ generate anything on SDI. This is an _input_, and comes from the SDO line on the slave. The SDO on the master connects to the SDI line on the slave. If you have data on the SDI line at the master, then the slave _is_ responding.....
Then check your SPI mode.
Use the standard constants:
Code: |
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
|
The ltc1854, if I remember correctly, uses mode 3.
The ltc1854, allows SPI up to 20MHz, so speed should not be an issue. Do a basic routine to setup the ADC, and read one value, with the header you are using, and the clock settings, and post it. It should be kept short. The odds are that when you shorten the code and tidy things up you'll suddenly find the problem, but is not, it makes something we can start from....
Best Wishes |
|
|
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
|
Posted: Sat Nov 26, 2011 8:53 am |
|
|
I did it, I tried all modes, I'm doing it for whole week,
but that stupid ic didn't respond.
Is there any kind of simulation of ltc1854 ic ?
Is there any device check or something ?
All the pin configuration is set, I'm not receiving any change when I check my first channel of adc. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19520
|
|
Posted: Sat Nov 26, 2011 3:33 pm |
|
|
Other people have in the past posted here 'near working' ltc1854 code, that worked for one channel at least - search here for the chip name, so if you are not getting even this far, try starting with this....
Best Wishes |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Sat Nov 26, 2011 4:48 pm |
|
|
suggestions to make life easier:
assuming you are using hardware SPI ......
whatever your master clock freq, while testing
START CLOCKING AT A LOW SPI rate - on a breadboard or haywired -
you could be glitching away and not know it.
the timer 2 option yields the slowest clocking that can be set by hardware:
if its not working at THAT slow rate you really do have trouble
Code: |
setup_timer_2( T2_DIV_BY_1, 255, 1 ); //
setup_spi(SPI_MASTER|SPI_H_TO_L|SPI_XMIT_L_TO_H|SPI_CLK_T2);
|
also be sure of how you manage CONVST and NOT BUSY response
and the RDO state timing diagram for the converter |
|
|
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
|
Posted: Thu Dec 01, 2011 10:17 pm |
|
|
I have tried, adc is working, in default, means if you send no command to it, it will read channel 0. So all my code goes wrong, adc is not accepting the data, but its constantly reading channel 0.
Is there any errata avalible of ltc1854 ? I google it, but can't find it.
And I want to thank you for doing my correction and help me to write data in adc ltc1854. |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Fri Dec 02, 2011 8:18 am |
|
|
since you are using hardware - i'm going to assume you are now properly using code like :
Code: |
rcvbyte=SPI_READ(nextsendbyte);
|
so that for each byte of command out - you are getting a byte back
as i said before , with this part - you need to pay close attention to
the TIMING data as regards the control pins and WHAT your code does and WHEN -- to get it fully working.
page 17 of the data sheet is your friend and while what you have to do is non-trivial - it can obviously can be done with a PIC. i would be more specific but since you did not post a schematic - i have no way to give you any further guidance in the matter.
if i actually knew what your circuit was - and what connection you have to the pic other than SDI- SDO SCK i could tell you more
a picture ( the schematic) is worth more than another pargraph of description. |
|
|
electronx.x.2
Joined: 25 Nov 2011 Posts: 17 Location: Pakistan
|
|
Posted: Sat Dec 03, 2011 11:23 pm |
|
|
Code: |
#define conver_start pin_e5
#define read pin_e6
#define SPI_MODE_0 (SPI_L_TO_H | SPI_XMIT_L_TO_H)
#define SPI_MODE_1 (SPI_L_TO_H)
#define SPI_MODE_2 (SPI_H_TO_L)
#define SPI_MODE_3 (SPI_H_TO_L | SPI_XMIT_L_TO_H)
#define Adc_Channel_1 0b10000000
#define adc_resolution 0.0024414
unsigned int8 b[2];
unsigned int16 result,bit_value;
float adc;
void main()
{
setup_adc_ports(NO_ANALOGS|VSS_VDD);
setup_adc(ADC_OFF);
setup_psp(PSP_DISABLED);
setup_spi(SPI_MASTER|SPI_MODE_3|SPI_CLK_T2);
setup_wdt(WDT_OFF);
setup_timer_0(RTCC_INTERNAL);
setup_timer_1(T1_DISABLED);
setup_timer_2( T2_DIV_BY_1, 255, 1 );
setup_timer_3(T3_DISABLED|T3_DIV_BY_1);
setup_comparator(NC_NC_NC_NC);
setup_vref(FALSE);
while(true)
{
delay_ms(20);
output_low(read); // enable chip
spi_write(0b10000000); //read command
delay_us(1); //hold
spi_write(0); //dont care value
output_high(read);//disable chip
delay_us(5);//hold
output_high(conver_start);
delay_us(6);//hold
output_low(conver_start);
delay_us(6);//wait for conversion
output_low(read);//enable chip
b[1] = spi_read(0);
b[0]= spi_read(0);
output_high(read);//disable chip
result=b[1];
result= result<<8;
//b[0]= b[0] & 0xf0;
result=result | b[0];
result=result>>4;
bit_value=result;
if((result&0x0800)==0) //TRUE for positive values
{
adc=(result*adc_resolution)/2;
}
else
{
result=(~result+1)&0x07ff; //2's compliment if MSB is one
adc=result*adc_resolution*-1;
}
printf("\f Bit value read from adc(in hex)= 0x%lx and equivalent voltage= %g",bit_value,adc);
spi_write(0b10000000); //read command. This command isn't working. I check it on oscilloscope. The data is right, but ic doing conversion for adc channel 0 which is default, there is no use to write this command..... |
|
|
|
|