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 support@ccsinfo.com

PIC18F46J11 I2C and RS232 problem

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



Joined: 01 Feb 2013
Posts: 3

View user's profile Send private message

PIC18F46J11 I2C and RS232 problem
PostPosted: Fri Feb 01, 2013 11:37 am     Reply with quote

Good afternoon,

I am developing an ES that consists of a PIC communicating with some peripherals through I2C and RS232.

The RS232 works fine, UNTIL I try to use the I2C functions. If there are any I2C functions in my code (besides i2c_start() and i2c_stop()) the RS232 simply doesn't work anymore (stays at a constant voltage).

My code is the following:

Code:

#include <18F46J11.h>
#use delay(clock=12000000)

/* Configure I2C */
#use i2c(Master,Slow,I2C2)

/* Configure RS232 */
rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1)

void main()
{
   BYTE data=0xCC;

   i2c_start();
   i2c_write(0x3D); //sets reading option
   i2c_write(0x0A); //register address
   data = i2c_read(); //reads the reg
   i2c_stop();

   while(TRUE)
   {
       printf("%x\n\r",data);
       delay_ms(100);
      }
}


Nothing works that way. If I comment out the i2c functions, all of a sudden the RS232 works.

Any clues guys?

Thanks
dorinm



Joined: 07 Jan 2006
Posts: 38

View user's profile Send private message

PostPosted: Fri Feb 01, 2013 12:13 pm     Reply with quote

try to use fast_io, the set your tris manually; you might use as well ERRORS in your rs232 setup (#use ....);

...and, we don't know anything about your i2c device but it seems that you don't read anything (the pic waits for data to be clocked in, so try using first i2c_read(0), so the pic can clock your data in ;) )
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Feb 01, 2013 2:11 pm     Reply with quote

Quote:
If I comment out the i2c functions, all of a sudden the RS232 works.

Do you have pull-up resistors on the SDA and SCL lines ? You need
them. You are probably running the 18F46J11 at +3.3v for Vdd.
In that case, you can use 3.3K resistors for the pull-ups.

After adding the pull-up resistors, use this program to check if your PIC
can see the i2c chip:
http://www.ccsinfo.com/forum/viewtopic.php?t=49713
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Fri Feb 01, 2013 8:15 pm     Reply with quote

Did you check the errata for the PIC18FxxJ11?


I remember using it and running into some I2C problems that had to be resolved.


-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
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