Home
Prox / RFID
Verichips
Ladder Logic
[interfacing] †
Tube Joints
Key Code From Photo
SolveSpace (3d CAD)
SketchFlat (2d CAD)
Photographs
Miscellany
Resume / Consulting
Contact Me

LDmicro Forum - About I2C in ldmicro

(you are viewing a thread; or go back to list of threads)

About I2C in ldmicro (by José)
I have received this notification from biatel1,via Github:

I found little bit more general problem.
Up to version 5.3.1.0 I2C works on ATMega 328, Atmega 8 etc. with small issue that it works on 28-pin, and not on 32-pin.
But starting from version 5.4.0.3 up to the newest 5.4.1.1 it stopped and claims there is no SDA/SCL pin in these AVR.
Looking at source --> folder LDmicro-5.4.1.1\ldmicro\Tests --> example "test-i2c-lcd16x2.ld" opens correctly with version 5.3.1.0 but not any above this version.
So something bad happened above 5.3.1.0 that small AVRs lost I2C capability.

I have warned yet about some untested modifications in earlier versions of ldmicro that have broken I2C...
May Ihor have a look at it ?

BR
Mon May 31 2021, 13:55:41
(no subject) (by Toni)
The same thing happens to me.

Greetings.
Tue Jun 1 2021, 01:48:53
(no subject) (by Paulino)
Probar con la versión de fransua, 32-5.a
esta adjunta en RAR
Tue Jun 1 2021, 10:04:09, download attachment @LdMicro32-5.4a.zip
(no subject) (by Toni)
Thanks Paulino
Tue Jun 1 2021, 10:36:01
(no subject) (by José)
Yes,

if you improve problems with I2C in ldmicro you can use my fork version ldmicro32 available on github and kindly provided by Paulino.
If nothing is done about it in the official branch, I will probably have to create a new release of ldmicro32 in a near future.

BR
José
Tue Jun 1 2021, 15:42:29
To José (by Angelo)
Hi José:

I really like working with PIC16F887 and version (build_5411) works pretty well with IC2.

Anyway there are few things I hope you can help me out.

1.- I would like to use PORTB6 and PORTB7 as INPUTS. Every time I program any of those pins as inputs the program does not work at all.


2.- I would like to write and read registers larger than 255 to an I2C memory.

Greetings
Thu Jun 24 2021, 19:23:33
To José (by Angelo)
Another problem is that PORTB.0, PORTB.1, PORTB.2, PORTB.3, PORTB.4 and PORTB.5 have a high level (3-4 DCV) when they are not used in the program.

If you have any rung that includes them then they go low (0 DCV) WHEN CONFIGURED AS OUTPUTS.
Thu Jun 24 2021, 21:44:48
(no subject) (by José)
Hi Angelo

PB6 and PB7 (alias ICSPDAT / ICSPCLK) may be used by your programmer to upload the program in the PIC's memory ?
That's probably why you can't use those pins ?

PB0 to PB5 are at high level by default because of internal pull-up resistors when configured as inputs.
Just modify Settings->Pull up resistors: Port-RB= 0 to disable all the pull-ups on PB.

José
Fri Jun 25 2021, 02:03:47
To José (by Angelo)
When programming without using the I2C function PORTB.6 and PORTB.7 perform correctly as inputs.

Also it would be very useful if there is a way to write and read registers larger than 255 to an I2C memory (24C16B).

I used to code in PBP (PicBasicPro) it has a function that allows to read-write these memories, maybe this information could help.

Please have a nice weekend!
Fri Jun 25 2021, 18:28:45
(no subject) (by José)
OK

About RB6 and RB7 and don't know why it interferes with I2C. I don't see anything about it in I2C Library...

I'll try to have a look at I2C devices with large address spaces.

BR
José
Sat Jun 26 2021, 03:34:39
(no subject) (by OnosTech)
I have also observed that the I2C instruction seems to interfere with the timers and the UART.

It will be nice to have a function like the Formatted String Over UART for I2C. This will make it more flexible to write to I2C LCD like it is done for the serial LCD.

Best Regards
Onos
Sat Jun 26 2021, 07:31:22
(no subject) (by Alex)
I think it would be great too, hope it is possible
Sun Jun 27 2021, 16:07:28
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Hi Jose:

I tried I2C but this instruction is not recognized when I tried with PIC18F4520-I/P

I tried build5411 and build5405.

Attached I send you some pictures
I hope you can help me.

Truly yours:
Angelo.
Wed Jun 30 2021, 22:05:07, download attachment jose.rar
(no subject) (by José)
Hi Angelo

I strangely can't open your rar file with my winrar ; can you please send me in zip format, so that I can have a look at the pb ?

José
Thu Jul 1 2021, 02:14:13
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Hi Jose:

I tried I2C but this instruction is not recognized when I tried with PIC18F4520-I/P

I tried build5411 and build5405.

Attached I send you some pictures
I hope you can help me.

Truly yours:
Angelo.
Thu Jul 1 2021, 17:52:02, download attachment Jose.zip
(no subject) (by José)
OK

There's a bug in last releases of ldmicro concerning I2C names
(between I2C and I2C1 when there's only one I2C bus) but the mains developpers don't seem to care about it.

The only known solution is to download my own build ldmicro32 on github ; I2C bus normally works, named "I2C" as in the attached example, designed and tested for PIC18F4520:

https://github.com/joegil95/LdMicro32
Fri Jul 2 2021, 14:45:14, download attachment test_i2c.ld
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Thank you very much José.
I will try.
Fri Jul 2 2021, 22:17:08
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Now I can edit PIC18F4520 programs without any errors at all.

I just need your help in figuring out what I need to do in order to compile correctly and create .hex files.

Thank you very much in advance!



I am trying to write and/or read to an I2C lcd (PCF8574) a RTC (DS3231) and a 24C16B I2C memory.
Mon Jul 5 2021, 22:03:27
(no subject) (by José)
Hi Angelo.

To build your hex file for PIC18F4520, you need to configure buildPic18.bat for ldmicro32.

Before you must install picc18 compiler ; you can download it from my website:
http://hpvexin.free.fr/script/temp/Compiler-HTC-Pic18_9.80.exe

You'll also need external libraries (LIBRARIES_FOR) for PIC18, as explained in HowTo-PIC18.txt file.

Have a look at attached file.
It also contains an example for DS1307 I2C RTC, and one for I2CLCD tested on PIC18F4520.

According to I2C memory beware that we can only use 8 bit addresses in I2C for the time being...

José
Tue Jul 6 2021, 02:49:24, download attachment HowTo.zip
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Thank you very much José.

I will try everything you told me!!!
Wed Jul 7 2021, 11:00:56
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Hi José:

When I just use the I2C instruction it is possible to compile and generate de .hex file. That is the case of I2C_MEM_PIC18F4520.ld file.

But when I try to use the UART instruction and I2C instruction the .hex file is not generated. That is the case of I2C_MEM_UART_PIC18F4520.ld file.

Attached I send you both files and some pictures of errors reported in the case of I2C_MEM_UART_PIC18F4520.ld file.

I am using LdMicro32-5.5a-en.exe version.

Best Regards
Sat Jul 10 2021, 16:45:40, download attachment JOSE_PIC18F4520_REPORT_10jul21.zip
(no subject) (by José)
Dear Angelo

You're right, there's a pb with UART libraries for PIC18 (wrong files).

Please copy Uartlib.c and .h from LIBRARIES_FOR\PIC16 to LIBRARIES_FOR_PIC18 and replace old ones.

Then your project should be built OK (with some warnings but no error) ; I have tested it.

But I haven't tested if the resulting hex file works fine for lack of time ; let us know about it...

BR
José
Sat Jul 10 2021, 17:31:03
(no subject) (by José)
PS:
Your configuration word is not good.

You must just set in ldmicro the first Config word (0x0200 in my own tests) ; other config words are fixed in C program (have a look at the top of generated C file):

__PROG_CONFIG(1, 0x0200);
__CONFIG(2, WDTDIS & PWRTEN & BORDIS);
__CONFIG(3, MCLREN & PBDIGITAL);
__CONFIG(4, DEBUGDIS & XINSTDIS & LVPDIS & STVREN);
Sun Jul 11 2021, 03:27:37
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Hi José:

I copied Uartlib.c and .h from LIBRARIES_FOR\PIC16 to LIBRARIES_FOR_PIC18 and replaced old ones. But still no working.

I even tried with Uartlib.c and .h from Build5411 (LIBRARIES_FOR\PIC16 and LIBRARIES_FOR\PIC18). And still not working. The .hex file is not generated.

I tried the 0x200 configuration but is not working.

Greetings!
Tue Jul 13 2021, 20:59:33
(no subject) (by José)
If no hex is generated, it means that there remains compiling errors.
Please post your compiling output to understand, as previouly done.
Wed Jul 14 2021, 05:20:24
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Hi José:

Attached I send you a zip file.

I really appreciate your help.
Wed Jul 14 2021, 22:20:48, download attachment JOSE_PIC18F4520_REPORT_14jul21.zip
(no subject) (by José)
Ok Angelo

There remains errors in your compiling output ; some warnings too but its less important.

1) error in config words: it's possible that ldmicro doesn't handle well this field for PIC18 ; so, open the ld file with a text editor and replace the wrong value with 0x0200 ; then save the file and reopen it with ldmicro.

2) error in UART_Init() call : you have probably replaced the Uart libraries in LIBRARIES_FOR as said above, but you must also replace them in the subfolder HTC\lib of your ld project location, since the project has been created before changes ; then this error should desappear.

Makes those changes and let me know ; post your output if some pbs still occur...

BR
José
Thu Jul 15 2021, 09:51:57
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Hi José:

I am reporting to you about PIC18F4520.

Now the UART instruction is working o.k. Also when I include the I2C memory sequence works o.k.

But I tried including ONOS program (this one includes a DS3231 and a LCD-PCF8574). Unfortunately it does not work at all.

The .hex file is generated but does not work (ONOS program works o.k. with a PIC16F887)

Attached I send you some pics about this.
I2C_ONE.ld DOES NOT WORK AT ALL.
I2C_ONE_MEM.ld Works partially, just the I2C memory routine works.

Truly yours
Angelo
Mon Jul 19 2021, 13:48:23, download attachment I2C_report_jose_18jul21.zip
(no subject) (by José)
Hi Angelo

I'm on holidays and I'll have a look at the pb tomorrow...
I can't before.


José
Wed Jul 21 2021, 03:44:08
Happy Holidays!!! (by Angelo)
O.K. No problem!!!

Please enjoy your holidays!!!
Thu Jul 22 2021, 11:49:12
(no subject) (by José)
OK
Thanks Angelo !

I've been working on your pbs this morning.
I have noticed a pb in my UART libs for PIC18 that I have corrected ; but there remains a pb with I2C ; I'll work on it soon and let you know...

BR
José
Fri Jul 23 2021, 07:40:20
(no subject) (by José)
Hi Angelo

Here's what I can say:

- There was still a pb with my UART libraries ; pick the files in attached zip and copy them to your LIBRARIES_FOR\PIC18 and to your HTC\lib folders to replace old existing ones.
Those are temporary files working only at 9600 bauds ; I'll have to modify the code generated by ldmicro32 in next release to make something reliable.
I have tested it in a simulator (for lack of hardware on holidays) and it has worked.

- When developping the PIC18F4520 libraries I had tested I2C libraries with my DS1307 and it worked fine ; DS3231 is almost the same and should work too.

- I have verified the datasheet of your I2C memory and your operations seem to be OK

- I can't test I2C-lcd in simulation because, if I remember well, it doesn't work...

- theres's a warning in your pickit programmer about some unset config bits (config 5+6+7); the values it proposes are default ones and seem to be OK ; that's why we don't care about them.

In my ds1307 ladder I used cfg bits= 0x847406F700000200
You can test it.

To conclude, replace UART libs, and recompile + rebuild the ladder to hex file.
I'll try to make so that there are less warnings in the future, but normally it's not important.

There are now 2 cases:

1) it works fine => ok !!!

2) it still doesn't work (probably)

In this case you'll have to split your ladder into several parts to test separately DS3231 (just read seconds for instance) ; I2C memory ; I2C lcd
Then we may add UART to send debug messages...
Attached zip file also contains my I2C test programs for I2C with PIC18F4520.

I can't debug such a big program and easily know where the pb lies. And it seems that few people have tested this new target PIC18F4520, which is very interesting because pin compatible with PIC16F877.

To be continued (if you want...)
José
Sat Jul 24 2021, 06:10:48, download attachment Uartlib.zip
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Hi José:

Maybe you are already on vacations, if so continue enjoying.

I just want to report to you that unfortunately it is case 2, i.e. It still doesn't work.

The main problem is the I2C communication.

UART communication works ok., so far.

I tried copying and pasting next instructions in LIBRARIES_FOR\PIC18 I2cLib.h
And I tried the same with HTC\lib

#ifndef LCD_I2C_ADR
#define LCD_I2C_ADR 0x27 // a adapter selon afficheur (si utile)
#endif
#defi

Truly yours
Angelo
Tue Jul 27 2021, 18:36:13
(no subject) (by José)
Dear Angelo

I'm now back home and I have made some test with my PIC18s...
And nothing works as it ought to !

I have identified the pb:
Another developper as made some changes in the source code of ldmicro (on which ldmicro32 was based) without taking any care of my developments for PIC18s or ARMs. Thus, the code to manage the main timer 0 for PIC18s is broken ans nothing can work.

As it's not the first time, it's one of the main reasons why I'll now develop ldmicro32 in an independant way.

Waiting for this new independant version, I'll tell you within a few days what to do to solve your pb. I need to test again some things that worked before...

////////////////////////////////////////////////////////////
For the time being you mays solve it by changing your ld configuration from timer 0 to timer 1, which doesn't seem to have been affected by the changes (at first glance) !!!
////////////////////////////////////////////////////////////

In computer science, when a pb is understood, it's almost solved !

BR
José
Thu Jul 29 2021, 15:26:35
PIC18F4520-I/P I2C PROBLEM (by Angelo)
Thank you very much José.
Right now there is no need to rush so I will wait for the new development.

I will be checking the Forum on a regular basis.

Truly Yours
Angelo.
Fri Jul 30 2021, 16:52:39
Improvement suggested to the I2C (by Angelo)
Hi José:

Improvement suggested to the I2C.

I have noticed that when the I2C is interrupted by any broken wire (by mistake or in purpose) to restore the communication it is necessary to reboot the PIC.

So maybe it could be possible to improve the I2C by avoiding this situation.

This situation does not happen with the UART communication. If for any reason the UART communication cable is disconnected, as soon as you connect it back again, the communication is restored with no need to reboot the PIC.
Sat Jul 31 2021, 13:24:56
(no subject) (by Paulino)
Si Si, Arregla esto para estos chicos del foro, saludos Jose

Yes Yes, fix this for these guys from the forum, greetings Jose

Oui Oui, corrigez ça pour ces gars du forum, salut José
Sun Aug 1 2021, 06:17:43
(no subject) (by José)
Hi Angelo and Paulino

I'm working on Pic18 and other targets that have been affected by the said changes...

Concerning I2C, its normal that any broken wire may lock the µC because I2C bus requires acknowledgments ; and the µC or the device can miss an ack and then wait for it forever !
There's nothing to do against it.

It doesn't occur with UART or SPI because there's no ack in those (more simple) protocols.

BR
José
Sun Aug 1 2021, 16:15:09
(no subject) (by José)
I have relesed a new version of ldmicro32 to correct some problems seen above ; have a look at the forum !
Tue Aug 10 2021, 07:28:34
Post a reply to this comment:
Your Name:
Your Email:
Subject:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):