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

I2C intermittent problem
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Matro
Guest







PostPosted: Mon Apr 07, 2008 1:56 pm     Reply with quote

mskala wrote:
Matro wrote:
... you have a PIC running at a voltage that is not the same as the bus... of course you have troubles...
Matro.


For I2C, if you have a device running on 3.3V, but the pins are 5V-tolerant, then it is perfectly fine to use the pullups to 5V and run the other devices at 5V, without any type of level-shifter. Everything on the bus is open-collector.

By my look at the datasheet, those pins are 5V tolerant.

Here a short excerpt of the datasheet :
Quote:
Pins that are used as digital only inputs are able to handle DC voltages up to 5.5V.

I don't think that when we are talking about a I²C master we are talking of "inputs" but of "outputs".
And in this case the 5.5V tolerance doesn't apply and random behavior sould appear.

Matro.
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

I pasted teh same line twice by accident
PostPosted: Mon Apr 07, 2008 2:32 pm     Reply with quote

mskala wrote:
Matro wrote:
... you have a PIC running at a voltage that is not the same as the bus... of course you have troubles...
Matro.


For I2C, if you have a device running on 3.3V, but the pins are 5V-tolerant, then it is perfectly fine to use the pullups to 5V and run the other devices at 5V, without any type of level-shifter. Everything on the bus is open-collector.

By my look at the datasheet, those pins are 5V tolerant.




Hello all,

Yes, the PIC16F677 is a 5V part, and the PIC18F65J10 has 5V tolerant I/O pins because they are open collector, unless you activate the internal pull-ups. Also, my mistake, I pasted the same code twice by accident:

This is correct MASTER Use statement:
Code:
#USE i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3, force_hw)   
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

Re: I pasted teh same line twice by accident
PostPosted: Mon Apr 07, 2008 2:41 pm     Reply with quote

davefromnj wrote:
mskala wrote:
Matro wrote:
... you have a PIC running at a voltage that is not the same as the bus... of course you have troubles...
Matro.


For I2C, if you have a device running on 3.3V, but the pins are 5V-tolerant, then it is perfectly fine to use the pullups to 5V and run the other devices at 5V, without any type of level-shifter. Everything on the bus is open-collector.

By my look at the datasheet, those pins are 5V tolerant.




Hello all,

Yes, the PIC16F677 is a 5V part, and the PIC18F65J10 has 5V tolerant I/O pins because they are open collector, unless you activate the internal pull-ups. Also, my mistake, I pasted the same code twice by accident:

This is correct MASTER Use statement:
Code:
#USE i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3, force_hw)   



For the purposes of testing, I will lower the 5V mcu's voltage rail to 3.3V to see if it helps. Thank you all for looking into this problem, your help and attention is GREATLY APPRECIATED.

--Dave
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 07, 2008 2:41 pm     Reply with quote

Quote:

#USE i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3, force_hw)

As part of the trouble-shooting, you can try it with a software i2c master.
Just delete the 'force_hw' parameter. This will test if there is some
problem with the MSSP module in the master PIC.
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

I tried out the 3.3V rail idea
PostPosted: Mon Apr 07, 2008 2:56 pm     Reply with quote

I tried lowering the slave board to 3.3VDC, it's using a 4MHz ceramic resonator, so it is within spec to run at 3.3VDC.

Unfortnately, the code is stuck at the same place, on known-bad boards no change.

--Dave
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

Thanks
PostPosted: Mon Apr 07, 2008 2:58 pm     Reply with quote

PCM programmer wrote:
Quote:

#USE i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3, force_hw)

As part of the trouble-shooting, you can try it with a software i2c master.
Just delete the 'force_hw' parameter. This will test if there is some
problem with the MSSP module in the master PIC.


This is a good idea. I will try this now.


--Dave
Matro
Guest







PostPosted: Mon Apr 07, 2008 3:04 pm     Reply with quote

A very strange thing I just notice :
Code:

if (SSPOV)
{
    SSPOV = 0;
}

if (WCOL)
{
    WCOL = 0;
}

i2c_start();

temp = i2c_write(slave_address)
///////THE ABOVE COMMAND IS WHERE THE PROCESSOR HANGS.
if (temp)
{
     i2c_stop();
     i2c_timer = 0;
     if (++i2c_timer >= I2C_POLL_DELAY)
     {
             temp = i2c_write(slave_command)
             if (temp)
             {     //move on to other i2c commands to read data from slave                   //16F.
             }                               
     }
}

What's this "i2c_stop();" line?
I don't see how this can work with a stop between sending slave address and command.

Matro.
davefromnj



Joined: 03 May 2007
Posts: 42

View user's profile Send private message

Re: Thanks
PostPosted: Mon Apr 07, 2008 3:28 pm     Reply with quote

davefromnj wrote:
PCM programmer wrote:
Quote:

#USE i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3, force_hw)

As part of the trouble-shooting, you can try it with a software i2c master.
Just delete the 'force_hw' parameter. This will test if there is some
problem with the MSSP module in the master PIC.


This is a good idea. I will try this now.


--Dave



PCM_PROGRAMMER YOU ARE THE MAN!!!

I changed:

Code:
#USE i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3, force_hw)


to

Code:
#USE i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3)


and it worked!!

I then switched the master 18F clock to 16MHz with the 4x PLL, still worked.

I then switched the rest of the 18F's code on, before I was only executing the I2C routine, and it still worked.

I then switched the slave board's 3.3Vrail back to 5V, and it still worked!!!

Thanks again!


To verify, i also switched back to the force_hw, and the program locked up again, changed it after that to remove the force_hw and it worked again.

I don't need the force_hw on the master board, because it seems that the i2c_write() function has clock stretching enabled by default, so it will wait for a response forever. Only the slave board needs the SSP_ISR, and it has the force_hw and works properly.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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