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 - Hang on I2C_write()

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



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

I2C - Hang on I2C_write()
PostPosted: Tue Dec 13, 2005 2:35 pm     Reply with quote

Hi!

Since a few days, i have a big problem.
When i process an i2c_write() command on my PIC 16F747 via the hardware I2C - Interface, the �C hangs!

I have no ideas, whats wrong with my controller or my schematic. An interesting fact was, that i had this problem already and i only was able to solve it, by creating a new PCB. And now, i have it again.

Does anybody know about this problem?

Pleas help me, it is really important!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Dec 13, 2005 2:56 pm     Reply with quote

1. Post a very small (but complete) program that shows the problem.
Show all #include, #fuses, and #use statements.

2. Describe your hardware connections. Do you have pull-up
resistors on SDA and SCL ? What are the values of the resistors ?

3. What is your compiler version ?
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

Re: I2C - Hang on I2C_write()
PostPosted: Tue Dec 13, 2005 7:02 pm     Reply with quote

mwildbolz wrote:
Hi!

Since a few days, i have a big problem.
When i process an i2c_write() command on my PIC 16F747 via the hardware I2C - Interface, the �C hangs!

I have no ideas, whats wrong with my controller or my schematic. An interesting fact was, that i had this problem already and i only was able to solve it, by creating a new PCB. And now, i have it again.

Does anybody know about this problem?

Pleas help me, it is really important!


Check your pull up resistors.
_________________
Regards, Andrew

http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!!
kender



Joined: 09 Aug 2004
Posts: 768
Location: Silicon Valley

View user's profile Send private message Send e-mail Visit poster's website Yahoo Messenger

PostPosted: Tue Dec 13, 2005 7:45 pm     Reply with quote

Try adding these lines to you initialization code:

Code:

   output_float(PIN_SCL);
   output_float(PIN_SDA);
mwildbolz



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

PostPosted: Wed Dec 14, 2005 2:58 am     Reply with quote

Hi!

My hardware is OK. I have installed pull up resistors and i have 5 Volts on SDA and SCL when the bus is idle.
The values of the resistors are 4k7

The code from my testing program:
Code:

#include <16F747.h>

//*******Configuration of the �C and the CCS Compiler********
#use delay(clock=12000000)
#fuses HS, PUT, NOPROTECT, NOBROWNOUT, BORV20, MCLR, NOFCMEN, NOIESO, NOBORSEN, NODEBUG

#use I2C(master,sda=PIN_C4,scl=PIN_C3, FORCE_HW, RESTART_WDT)   //Routines for I2C
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)               //Routines for RS232


//****************Global Definitions**************************


#define I2C_enabled True         //Possibility to disable the I2C interface for testing
#define Debug True                 //Display debug messages throug RS232 interface for debugging purposes
#define EEPROM_write_active True   //Disable writing to the EEPROM



//******************Function prototypes**********************


//**********************Includes****************************
#include "EEPROM.h"


//**************************void main***************************
void main()
{

   I2C_Start();
   printf("start fertig");
   i2c_write(0xa0);
   printf("Write fertig");
   i2c_stop();

   while(1)
   {

      
   }   
   
}


The line printf("Write fertig"); is never reached. The �C hangs on the i2c_write(). It doesn't matter, if the adressed device is physically available or not.


Compiler Version: PCWH 3.222


Btw: I wasn't able to try setting the PIN's floating. I can do this not before tomorrow.


greetings, Markus
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Wed Dec 14, 2005 8:52 am     Reply with quote

This compiles on 3.239 and ran to compleation on my hardware. Only a couple of changes. In the comments it says disable writing. Is this getting you hung up?
Code:
#include <18F452.H>
#CASE
#USE DELAY(CLOCK=40000000)
#FUSES H4,NOWDT,NOPROTECT,NOLVP
#DEFINE VER_MAJOR 2
#DEFINE VER_MINOR 01
#USE RS232(BAUD=19200,XMIT=PIN_C0,INVERT,STREAM=DEBUG,DISABLE_INTS) // STDERR(same as DEBUG)
#USE RS232(BAUD=19200,ENABLE=PIN_C5,XMIT=PIN_C6,RCV=PIN_C7,STREAM=RS485)
#use I2C(master,sda=PIN_C4,scl=PIN_C3, FORCE_HW, RESTART_WDT)   //Routines for I2C
#define I2C_enabled True         //Possibility to disable the I2C interface for testing
#define Debug True                 //Display debug messages throug RS232 interface for debugging purposes
#define EEPROM_write_active True   //Disable writing to the EEPROM
void main()
{
   i2c_start();
   fprintf(DEBUG,"Start fertig\n\r");
   i2c_write(0xa0);
   fprintf(DEBUG,"Write fertig\n\r");
   i2c_stop();
   while(1)
   {
   }
}
mwildbolz



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

Protecting circuit for i2c Pins
PostPosted: Fri Dec 16, 2005 7:16 am     Reply with quote

Hi there!

I hadn't tried your code, but i found the problem. It looks like the I2C Port of my �C is broken down.

I am not sure why, but if i take another controller of the same type, with the same program and the same PCB, it works fine.


Now, i am looking for a schematic, which protects my I2C Pins. Do you have any ideas?? Maybe it works with normal diodes (Zener Diodes) or has anyone a better idea for me??


Greetings, Markus
mwildbolz



Joined: 26 Jul 2005
Posts: 16

View user's profile Send private message

PostPosted: Sun Dec 18, 2005 5:42 am     Reply with quote

Has nobody a good idea?? Question
I need some ideas because i have to finish my work on this project Exclamation

Please help me.


Greetings, Markus
Storic



Joined: 03 Dec 2005
Posts: 182
Location: Australia SA

View user's profile Send private message Send e-mail

PostPosted: Sun Dec 18, 2005 7:30 am     Reply with quote

A lot of circuits I have seen and used consists of a Zener, Buffer resistors and even Caps. Confused
try and have a look at http://www.maxim-ic.com/appnotes.cfm/appnote_number/564 it may help. Question

ANdrew
_________________
What has been learnt if you make the same mistake? Wink
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 18, 2005 12:17 pm     Reply with quote

Quote:
Now, i am looking for a schematic, which protects my I2C Pins.

Get the Philips i2c spec, here:
http://www.semiconductors.philips.com/acrobat/literature/9398/39340011.pdf
On page 37 at the bottom right, they suggest using series resistors
to protect the i2c pins. On page 39, there is a schematic.

I haven't used these series resistors but in other circuits that I've seen,
most people seem to use 100 ohms.

After you put in the series resistors, you should look at the i2c pins
with an oscilloscope to make sure that they have the correct logic levels.
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