View previous topic :: View next topic |
Author |
Message |
severo
Joined: 01 Feb 2013 Posts: 3
|
PIC18F46J11 I2C and RS232 problem |
Posted: Fri Feb 01, 2013 11:37 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
dorinm
Joined: 07 Jan 2006 Posts: 38
|
|
Posted: Fri Feb 01, 2013 12:13 pm |
|
|
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 ;) ) |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Feb 01, 2013 2:11 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
bkamen
Joined: 07 Jan 2004 Posts: 1611 Location: Central Illinois, USA
|
|
Posted: Fri Feb 01, 2013 8:15 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
|