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

No activity on I2C Bus with PIC18F4550

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



Joined: 15 Jun 2008
Posts: 2

View user's profile Send private message

No activity on I2C Bus with PIC18F4550
PostPosted: Sun Jun 15, 2008 4:58 pm     Reply with quote

Hello all! This is my first post and I am admittedly a novice with the PIC series of microcontrollers. I am more familiar with Altera FPGAs and Atmel Microcontrollers... I am trying to broaden my embedded systems knowledge.

As for my question(s)...
I have been trying for quite a while to get some sort of activity from my PIC's I2C interface.

Here are the various I2C init calls I have tried...
#use i2c(Master,Slow,sda=PIN_B0,scl=PIN_B1)
#use i2c(Master,Slow,sda=PIN_B0,scl=PIN_B1, force_hw)
#use i2c(Master,Slow,sda=PIN_C0,scl=PIN_C1)
#use i2c(Master,Slow,sda=PIN_D0,scl=PIN_D1)
and...
i2c_start();
i2c_write(0xAA); //just to wiggle the pins
i2c_write(0xAA); //just to wiggle the pins
i2c_write(0xAA); //just to wiggle the pins
i2c_stop();

Using an oscilloscope, I see no activity on the pins I bind to the I2C bus. I have pull up resistors on both I2C lines on my breadboard.

I have verified that the chip works by blinking some LEDs.

I am using v4.014 of the CCS C Compiler.

How do I need to set up my pins when I start a project and how would I change them after a project has been made? I believe I made B0 an input/output and B1 just an output.

What am I missing?

Thanks in advance!

-Jason
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 15, 2008 6:54 pm     Reply with quote

Do you have pull-up resistors on the SDA and SCL lines ?
You can use 2.2K to 4.7K resistors.

If you have the pull-ups, you will definitly see activity on SDA and SCL
with the following program. I tested it with vs. 4.014.
Code:
#fuses XT, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_B0, scl=PIN_B1)

//==========================
void main()
{

while(1)
  {
   i2c_write(0x55);
   delay_us(500);
  }

}
Guest








PostPosted: Sun Jun 15, 2008 7:03 pm     Reply with quote

Yes... I was am using two (one for SDA and one for SCL) 10k-ohm resistors pulled up to 3.3V. The PIC is running at 3.3V as well.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 15, 2008 7:21 pm     Reply with quote

Did you try the exact program that I posted ? If you changed it, then
post the modified program. What is your crystal frequency ?
I tested the program on a PicDem2-Plus board running at 5v.
Using the BROWNOUT fuse should not be a problem, because according
to the .LST file, the compiler defaults to BORV20 (2 volts brownout).

You said you're new to PICs. Do you have all the simple things, such
as a pullup on the MCLR pin ?
jpduell



Joined: 15 Jun 2008
Posts: 2

View user's profile Send private message

PostPosted: Sun Jun 15, 2008 8:52 pm     Reply with quote

I just tried the program you supplied. I made no changes at first.

I did not have a 4MHz oscillator readily available, so I used a signal generator producing a 4MHz square wave as a clock source.

I still had no activity on SDA or SCL.

I have had the nReset pulled high throughout all my attempts.

I made a few changes and still no luck. I tried using the internal RC oscillator just in case the signal generator route wouldn't work.

Code:

#include <18F4550.h>
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#fuses NOWDT, PUT, BROWNOUT, NOLVP //XT,
#use delay(clock=4000000)
#use i2c(Master, sda=PIN_B0, scl=PIN_B1)

//==========================
void main()
{
 setup_oscillator(OSC_4MHZ|OSC_INTRC|OSC_31250|OSC_PLL_OFF);
 while(1)
  {
   i2c_write(0x55);
   delay_us(500);
  }
}


As a side note... A couple years back I did design and prototype a 2-channel Air/Fuel ratio gauge making use of the PIC18F4550's onboard A/D converter, a UART output, and lots of I/O for the dual LED bargraphs... and I do not remember having this much trouble. I wonder what I'm doing wrong.

Thanks for you patience!
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 15, 2008 11:58 pm     Reply with quote

I think you should check the hardware again. I've done about all I
can do.
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