View previous topic :: View next topic |
Author |
Message |
prwatCCS
Joined: 10 Dec 2003 Posts: 70 Location: West Sussex, UK
|
18F25K22 and I2C |
Posted: Tue Oct 12, 2010 9:04 am |
|
|
Has anyone successfully used the I2C functions on the 18F25K22 ?
I am using compiler v4.112, and my simple test code works when compiled for an 18F252, but not when compiled for the 18F25K22.
I don't even see the start bit generation on the call i2c_start().
And then the call to i2c_write() hangs.
I have tried two different 18F25K22 parts. _________________ Peter Willis
Development Director
Howard Eaton Lighting Ltd UK |
|
|
prwatCCS
Joined: 10 Dec 2003 Posts: 70 Location: West Sussex, UK
|
|
Posted: Tue Oct 12, 2010 10:47 am |
|
|
I am pleased to report that I can now answer my own question!
YES.
The gotcha is as follows : On the 18F25K223 part, many of the port A, B and C inputs default to being ANALOG, not digital. See data sheet p153.
The CCS compiler does NOT take this into consideration, and thus the PORTC input pins for the I2C module are acting as analog in, which seems to prevent the MSSPx module from working.
I added
Code: |
#byte ADSELA=0xF38
#byte ADSELB=0xF39
#byte ADSELC=0xF3A
ADSELA=0x00;
ADSELB=0x00;
ADSELC=0x00;
|
to my hardware initialisation code, and now I see some activity on the I2C SCL/SDA lines. Result. _________________ Peter Willis
Development Director
Howard Eaton Lighting Ltd UK |
|
|
languer
Joined: 09 Jan 2004 Posts: 144 Location: USA
|
|
Posted: Tue Oct 12, 2010 1:24 pm |
|
|
Very good find.
Perhaps it is not well explained in the CCS manual, but in all Microchip datasheets you can find a familiar comment next to the analog inputs: "On a Power-on Reset, Rxx are configured as analog inputs and read as ‘0’.". As far as I know this is true for all the PICs I've used.
CCS lets the user handle this individually. You can use the following command to make all the analog inputs digital: setup_adc_ports(NO_ANALOGS)
In your case, it happened that on the 18F252 the MSSP pins are all digital functions; but on the newer 18F25K223 they are shared with analog functions. And in the analog/digital world, analog trumps digital
Simple case of reading the datasheet and understanding the hardware you are working with. |
|
|
|