Page 1 of 1

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

Posted: 22 Oct 2020 00:50
by steve42lawson
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;
:!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!: :!:

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

Posted: 22 Oct 2020 16:11
by Cobalt
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.

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

Posted: 31 Oct 2020 18:35
by steve42lawson
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!