FYI: Software I2C gotcha -- at least for the 24F08KL302!

General discussion on mikroC PRO for dsPIC30/33 and PIC24.
Post Reply
Author
Message
steve42lawson
Posts: 183
Joined: 06 Mar 2008 17:35
Location: St. George, UT
Contact:

FYI: Software I2C gotcha -- at least for the 24F08KL302!

#1 Post by steve42lawson » 22 Oct 2020 00:50

I was trying to get the MikroC Software I2C working on a 24F08KL302 and NO GO. The Start would happen, but the Address wouldn't send! -- scratched my head for hours!! Then I took another look at the Example Code in the Help Document, and re-noticed the line where Analog is config'ed to all Digital. The 24F08KL302 has no Analog ports!!!

But, just out of curiosity, and to heed Arthur Conan Doyle, I checked the P24F08KL302.c DEF file, and son-of-a-gun, ANSELA and ANSELB are defined?!?!

So I added the following to my code, and Yhoo Hoo! Off it went!!!

Code: Select all

    ANSELA = 0;
    ANSELB = 0;
:!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!:
Humility is the lack of the desire to impress, not the lack of being impressive.

Cobalt
Posts: 87
Joined: 17 Oct 2013 01:18

Re: FYI: Software I2C gotcha -- at least for the 24F08KL302!

#2 Post by Cobalt » 22 Oct 2020 16:11

The 24F08KL302 doesn't have Analog-to-Digital converters enabled, although they are still physically on the chip.
It also has two analog comparator modules on board.

Always check the datasheets. Even though it says that the 24F08KL302 has no analog functionality, the ANSEL registers and associated hardware is still on the chip and you need to handle them accordingly.

steve42lawson
Posts: 183
Joined: 06 Mar 2008 17:35
Location: St. George, UT
Contact:

Re: FYI: Software I2C gotcha -- at least for the 24F08KL302!

#3 Post by steve42lawson » 31 Oct 2020 18:35

Cobalt wrote:
22 Oct 2020 16:11
Always check the datasheets. Even though it says that the 24F08KL302 has no analog functionality, the ANSEL registers and associated hardware is still on the chip and you need to handle them accordingly.
From the 24F16KL402 Family Datasheet [of which 24F08KL302 is included]:
11.2.1 ANALOG SELECTION REGISTER
...If a particular pin does not have an analog
function, that bit is unimplemented.
I must have stopped reading there. But, it goes on to say:
On devices that do not have an A/D Converter, it is still
necessary to configure the ANSx registers in order to
enable digital input buffers. Any I/O pins with an ANx
function listed in red in the device Pin Diagrams will
default to have the digital input buffer disabled.
Dang! I never noticed that. I just assumed the lack of Analog functionality exempted any need to bother with the ANSEL register!

So, thanks!
Humility is the lack of the desire to impress, not the lack of being impressive.

Post Reply

Return to “mikroC PRO for dsPIC30/33 and PIC24 General”