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 CCS Technical Support

PIC18LF4520 and I2C not working

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



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PIC18LF4520 and I2C not working
PostPosted: Wed Jun 18, 2014 10:13 am     Reply with quote

Compiler PCWHD V4.134 also used for other code that works.

Chip as per subject line.

In my code using
Code:

#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,force_hw) // hardware

output_float(PIN_C3); // pullup 3k3 to Vdd
output_float(PIN_C4); // pullup 3k3 to Vdd

i2c_start();
i2c_write(value);   //  code hangs here


I used this
Code:
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,force_sw) // software

and then
Code:

set_tris_c(0b10000000);

while(1)
{

 output_toggle(PIN_C3);
 delay_ms(1);
 output_toggle(PIN_C4);
 delay_ms(1);
 
}

and pins C3 and 4 toggle nicely so the uP and connected hardware appear to be working.

With the force_sw I monitored the pins and they do not show any indication of being other than pulled high. i.e. no clk and no data

Are there any special FUSES concerning I2C on this PIC18LF4520 ?
I've looked in the device .h and found nothing.

I2C normally works fine, this code is working on PIC18F67K22 !

This looks like a chip failure but I doubt it as it never is :-)

What other tests can I do or what did I miss ?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 10:44 am     Reply with quote

What is the Vdd voltage on the PIC, and what is part number of the
i2c chip ?
temtronic



Joined: 01 Jul 2010
Posts: 9219
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 11:19 am     Reply with quote

also...
run PCMP's 'I2C scanner ' program in the code library.....!!!

hth
jay
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 11:36 am     Reply with quote

PCM programmer wrote:
What is the Vdd voltage on the PIC, and what is part number of the
i2c chip ?


Vdd is 3V3

I2C parts are
LTC6904 Address 0b00101100 (ADR pin = 0) write only chip
LTC6904 Address 0b00101110 (ADR pin = 1) write only chip
AD5245 Address 0b01011010 (AD0 pin = 1) for write

Digital Vdd is applied to all three chips and AD5245 before analog V is applied to the in/out pins of the AD5245 this is mentioned in the data sheet.

The addresses are different. The digital pot is read/write and as I mentioned I'm using known code from anther project (PIC18F67K22) which also runs at Vdd 3V3 and all works OK.
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 11:38 am     Reply with quote

temtronic wrote:
also...
run PCMP's 'I2C scanner ' program in the code library.....!!!

hth
jay


Not sure what that is.

I have a logic analyzer that decodes the I2C bus but there is NO activity on the pins so nothing to analyze !
Ttelmah



Joined: 11 Mar 2010
Posts: 19482

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 11:42 am     Reply with quote

What is 'value'?.

It should be one of the chip addresses.

Shouldn't hang things, but might cause oddities if (for instance) it was the GCA address.
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 12:19 pm     Reply with quote

Ttelmah wrote:
What is 'value'?.

It should be one of the chip addresses.

Shouldn't hang things, but might cause oddities if (for instance) it was the GCA address.


Value is as shown here.

LTC6904 Address 0b00101100 (ADR pin = 0) write only chip
LTC6904 Address 0b00101110 (ADR pin = 1) write only chip
AD5245 Address 0b01011010 (AD0 pin = 1) for write
AD5245 Address 0b01011011 (AD0 pin = 1) for read
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jun 18, 2014 12:23 pm     Reply with quote

Quote:
With the force_sw I monitored the pins and they do not show any indication of being other than pulled high. i.e. no clk and no data

Does it fail with both hardware and software i2c ?

Also, instead of posting code fragments, could you post a small but
complete (compiles without errors) test program that demonstrates
the problem ? There may be things that you're doing (that are not
shown in your posts) that are causing the problem. A test program
will let us see exactly what you are doing. By complete, I mean the
#include for the PIC, #fuses, #use delay(), #defines, variable
declarations, main(), etc.
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Thu Jun 19, 2014 2:44 am     Reply with quote

PCM programmer wrote:
Quote:
With the force_sw I monitored the pins and they do not show any indication of being other than pulled high. i.e. no clk and no data

Does it fail with both hardware and software i2c ?

Also, instead of posting code fragments, could you post a small but
complete (compiles without errors) test program that demonstrates
the problem ? There may be things that you're doing (that are not
shown in your posts) that are causing the problem. A test program
will let us see exactly what you are doing. By complete, I mean the
#include for the PIC, #fuses, #use delay(), #defines, variable
declarations, main(), etc.


Yes that's why I'm lost about what is going on.
I really expected the software version of I2C to work but when it failed also is when I tested the pins by toggling them to demonstrate that the circuit was not shorted etc.

UPDATE:
I did a short program and found it actually works. So clearly I'm having issues in the code.
So I'm breaking the code down into sections testing at each step.

Moving code from one processor to another turned out not to be as easy as I thought it should be.

I'll post my findings when I've nailed down what is happening.

Thanks to everyone for the help so far.
soonc



Joined: 03 Dec 2013
Posts: 215

View user's profile Send private message

PostPosted: Fri Jun 20, 2014 8:05 am     Reply with quote

The problem was me. On the new PCB I'd connected the 3K3 pull up resistors to the Analog Vdd (convenient in the pcb layout) which is also 3V3 but from a separate regulator.
AD5245 makes a point about applying Vdd before any analog section is powered up....

Anyway I moved the 3K3 pull up to the Digital Vdd and the code now works as expected. Moved it back to old connection and it fails.

After thought. The Test program switched on the Digital and analog Vdd at the same time, the real program the analog came on later.

More investigation than that I don't have time for.

Thanks for everyone that replied. Sorry to have caused a storm in a tea cup but perhaps some else can learn from this mistake.

Thanks
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