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 - New I2C functions in ldmicro for ARMs and AVRs

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

New I2C functions in ldmicro for ARMs and AVRs (by José GILLES)
Here's a new version of my ldmicro, which supports I2C via C programming for ARMs and AVR targets (ATMegas).

There are two new I2C functions, to read or write one byte in an I2C peripheral register. Peripheral can be selected by its I2C address.

For the time being I have just had time to test it with a true DS1307 I2C real time clock, and it worked... but it needs to be tested further more.

The principle is the same as for previous versions (see HowTo in zip file), with external I2C libraries.

Be aware that I2C peripherals (ie DS1307) can be very slow even at high speed (100 KHz), and have a look at cycle timing !!!

Try and let me know about your experience.

JG
Sat Dec 29 2018, 17:49:32, download attachment LdMicro32.zip
(no subject) (by John)
Hi, you could put a simple example hello world in 12C.

Thank you great job.

Regards
Sun Dec 30 2018, 04:22:30
(no subject) (by José GILLES)
Yes, but I2C is not really made to communicate with displays ; rather with sensors, expanders...
Sun Dec 30 2018, 12:15:20
(no subject) (by John)
OK thanks.
You know how I could connectSerial I2C 1602 16×2 Character LCD Module
Sun Dec 30 2018, 12:41:00, download attachment 1.jpg
(no subject) (by José GILLES)

I suppose you want to connect this display to an arduino board ?

Theoritically, it shoudn't be very difficult because:

- 16x2 LCD displays are well known and many libraries are available to make them work
- PCF8574 is just an 8-bit I2C IO expander connected to pins
E, RW, RS (command lines) and D4-D7 (data lines in 4-bit mode)
of the display
- I2C wiring is available on the Net

But I think itsn't worth trying to do it because these displays are very slow (all the more in 4-bit mode), and I2C interface will make it slower, so that it won't work in ldmicro, unless you have a huge cycle time !

JG
Sun Dec 30 2018, 16:15:07
(no subject) (by John)
OK thanks.
Sun Dec 30 2018, 22:19:39
(no subject) (by Ahmad sakr)
Hi
To jose
Is it possible to make ldmicro work directly with parallel lcd. As I know that ldmicro deal only with serial lcd.
Mon Dec 31 2018, 02:10:14
(no subject) (by José GILLES)
Hi

I guess you can use directly a parallel 16x2 LCD display, but it remains the same pb: it needs wait states between commands and it's very slow.

To avoid it you may have another µC driving the display, to which you send formatted text (from time to time) via Uart, Spi, I2c...
Mon Dec 31 2018, 02:42:08
(no subject) (by Ahmad sakr)
Hi
I am using parallel lcd with ldmicro by compiling the sketch to arduino then in arduino ide I add the message by using arduino instructions and it works good.
What I need and asking for is to make ldmicro deal with parallel lcd like arduino ide without using any other software or microcontroller or shift register.
Thanks for your great work
Mon Dec 31 2018, 11:52:12
(no subject) (by José GILLES)

Yes, its possible, but needs to had new functions for LCD16x2...
in ldmicro => much work

In your case, do you send many messages to your display, or just from time to time ?
And what is your cycle timing ?

JG
Mon Dec 31 2018, 12:09:00
(no subject) (by Tami Duke)
Hi..LDmicro allow you to make your ladder schematic then to generate HEX code which does the ladder logic implementation in program code which you program to your AVR or PIC and got the ladder logic functionality.
Wed Jan 9 2019, 13:22:43
Example I2C (by EDAM)
Hi you could put a simple example to communicate with other arduino in 12C.
Thank you.
Wed Mar 6 2019, 18:32:42
(no subject) (by José GILLES)
I2C under ldmicro works only in master mode.
To communicate, you must have a master and a slave...

It's designed here to drive sensors.

JG
Fri Mar 8 2019, 02:58:49
i2c (by Segar Segar)
HI,Any have example i2c progarmming with 16X2 LCD display

Thank
Tue Apr 23 2019, 02:28:30
i2c (by Segar )
HI,Any one have example i2c progarmming with 16X2 LCD display

Thank you
Tue Apr 23 2019, 02:29:43
(no subject) (by José GILLES)

I'm dealing on another thread with driving 16x2 LCD via I2C.
It works for me on ARM and AVR (AtMega 16, 328) and I'll test on PIC16F as soon as possible.

It requires to compile via C libraries.

I have some examples, but tell me before:

- your MCU target ?
- your LCD-I2C hardware ?

José
Tue Apr 23 2019, 06:13:30
New I2C functions in ldmicro for ARMs and AVRs (by José GILLES) (by Moin ud din)
José GILLES please make a video for installation procedure as you mention in you file i could not understand.
Fri Jul 12 2019, 08:54:53
(no subject) (by José GILLES)
Sorry but I don't have time to make videos now.

First explain your pb:
What do you want to do ? MCU Target ? I2C Hardware ?


JG
Sat Jul 13 2019, 16:18:48
RTC (by Mayo)
HI,Any one have example i2c progarmming with DS1307.
Sat Jul 20 2019, 14:37:16
(no subject) (by José GILLES)

I have some examples working with DS1307 ; but for which kind of target ? ARM, AVR or PIC ?

JG
Sun Jul 21 2019, 02:42:10
RTC (by Mayo)
Thanks to reply
My target Pic ,876,877
Sun Jul 21 2019, 11:28:18
(no subject) (by José GILLES)
OK

Here's an example for Pic16F877 on ldmicro 5.3.1.0
It just reads seconds in register 0 and sends values over UART ;
minutes and seconds can be read in registers 1 and 2 and date in the following ones in the same manner...

Don't use another version, and download corresponding C libraries if you want it to work fine:

https://github.com/LDmicro/LDmicro/releases/tag/5.3.1.0

JG
Sun Jul 21 2019, 12:59:33, download attachment i2c_ds1307.ld
(no subject) (by Magno Medeiros (Brasil))
Hello, I tried using Ldmicro v5.3.1.0. but it does not work. displays an error as per the image.
Please, can anyone help me?
Tue Jul 23 2019, 15:49:54, download attachment Ldmicro erro.jpg
msvcp100.dll (by Ihor Nehrutsa)
to Magno Medeiros (Brasil))
See
https://github.com/LDmicro/LDmicro/issues/174
Tue Jul 23 2019, 17:39:45
(no subject) (by José GILLES)

Yes,

you just need to install a runtime library for VC++ ;
follow one of the links at the end of the link above,
according to your 32 / 64 bits platform

JG
Wed Jul 24 2019, 00:14:39
(no subject) (by Magno Medeiros(Brasil))
OK thank you! worked perfectly.
Wed Jul 24 2019, 09:44:05
Ldmicro 5.3.1.0 // I2C-WR (by Gérard)
Hi all,
Firstly let me said i'm a beginner ....
Try to program Ldmicro 5.3.1.0 and add I2C lcd display.
What is the "send variable" to have the curser on row2 x column1 ?
Build5310/LIBRARIES_FOR/AVR/lcdI2clib.h says : 0x40
but when I simulate I obtain : @ intercaleted with the caracter of the message
Of course 40 is the ASCII of @
And if I try with "send variable" : 0xA0 that I found in the text file called "LcdI2cLib-en" in the folder of Ldmicro 5.3.1.0
I get xA0 intercaled with the caracter.
Where is my mistake ??
Wed Jul 31 2019, 13:28:26, download attachment Capture.pdf
(no subject) (by José)
To Gérard:

Your 0x40 is wrong ; a special I2C command to move the cursor on 16x2 display starts with a first bit at 1 (see txt file in LBRARIES_FOR\target) but 0xA0 should place the cursor at line 2 and column 1 as you said.

It normally works with true hardware (I personaly tested it on 3 kinds of targets) but you can't get it in simulation because the I2C simulator doesn't know what a display is and it can't interpret special commands...

It could be an idea to create an option in I2C simulator to behave like a 16x2 display ; I'll keep it in mind for next release.
Thu Aug 1 2019, 04:53:20
(no subject) (by Gérard)
Hi José
Thank you for your answer.
Sure it works better with a LCD :D
To practice I did a ladder with 5 Xpins to display 2 different messages of 16 caract. each on 1st line and 3 different messages of 16 caract. each on 2nd line and it works great.
For general information :
- I used an Atmega16 40pins with 16MHz crystal and 2 x 22pF.
- Free download AVR-GCC 9.1.0 installed in C:\Program Files (x86)\Atmel\avr_gcc_9_1_0
- One of this cheap chinese clone of USBasp with the free driver ProgIsp 1.7.2. to burn the .hex file in the ATmega.
- In FlashMcu \ AVRGCC I quoted :
SET GCC_PATH=C:\Program Files (x86)\Atmel\avr_gcc_9_1_0
SET AVRDUDE_PATH=C:\Program Files (x86)\Atmel\avr_gcc_9_1_0\bin
REM Transfer of the program with AvrDude
avrdude.exe -p m16 -c avr910 -P usbisp -b 19200 -u -v -F -U flash:w:AVRGCC\bin\"ladder_name".hex

"m16" as the ID of ATmega16 (see avrdude.conf in avr-gcc 9.1.0\bin)
"usbisp" as the portcom, but it works with "usb" too
______________________________________________________
And now a final remark : In LDmicro 5.3.1.0 each time I pulse Instruction/I2C functions/Insert I2C Write ; I get an error window, then I pulse OK, the error window disappears and can write in the I2C window; then have to substitute "I2C1" by "I2C" as I2C Name.
Can I do something to prevent this error window ??
Wed Aug 7 2019, 07:42:17, download attachment Capture1.pdf
(no subject) (by Alex)
That error window is a little anoying
Wed Aug 7 2019, 19:56:45
(no subject) (by José GILLES)
To Gérard and Alex:

Yes, this warning is a bit anoying.
It's due to the fact that on ARMs there are several I2C (or SPI) buses named SPI1,2,3 while on AVRs and PICs there's only one I2C named I2C.
If I remember well, Ihor has solved the pb for future versions by renaming I2C to I2C1 when the only one.

Best regards
José
Thu Aug 8 2019, 14:04:45
(no subject) (by Mayo)

Hi Dear José GILLES


Any one have example i2c progarmming with 24C32 32K

I2C EEPROM Memory.





Thanks
Sat Sep 14 2019, 18:05:35
(no subject) (by José GILLES)
Hi Mayo

I don't know this EEPROM but according to its datasheet and some examples on the net it works like that:

Write sequence: Start_Writing + write(adr1) + write(adr2) + write(byte) + stop

Read sequence: Start_Writing + write(adr1) + write(adr2) + Restart_Reading + read(byte) + stop

It's incompatible for the time being with I2C libraries

We can just do:

Write sequence: Start_Writing + write(adr) + write(byte) + stop

Read sequence: Start_Writing + write(adr) + Restart_Reading + read(byte) + stop

So it would require to modify at least I2C libraries.
It may be kept in mind for a future version.

Sorry !
José
Sun Sep 15 2019, 17:30:47
(no subject) (by Mayo)

Dear José

Hi one example in DS1307 with mints writing I2C ,

target , 16f877




Thanks,
Mayo
Wed Sep 18 2019, 18:08:41
(no subject) (by José GILLES)
To Mayo:

To read time or date in a DS1307 register you must do:
I2C_Read + BCD2BIN on some register 0->6
as in the example given above

To write into a register to modify time or date you must do:
BIN2BCD + I2C_Write on some register

Register in DS1307 are:
0 -> sec (0-59)
1 -> min (0-59)
2 -> hour (0-23)
3 -> day of the week (1-7)
4 -> date (1-31)
5 -> month (1-12)
6 -> year (0-99)

BUT they are store in BCD format and must be converted:
ie date = 25 is store as 0x25 in hexadecimal => 37

JG
Thu Sep 19 2019, 03:35:34
(no subject) (by maurizio)
Hi José,
thanks for your implementation , it's very interesting!
maurizio
Tue Sep 24 2019, 05:54:53
(no subject) (by Mayo)
Hi Dear José GILLES


Any one have example i2c progarmming with MPU6050 (GY521).
Thu Oct 17 2019, 11:59:51
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):