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

LDmicro Forum - A SPI available for AVRs in ldmicro

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

A SPI available for AVRs in ldmicro (by José GILLES)

As previously said, I've been working last weeks on SPI under ldmicro, a peripheral which seems to interest several users.

After implementing it for my STM32, I have made an effort to adapt it to AVRs, especially ATmegas (8, 16 and 328).

Using simple C external libraries, it now possible to use all standard contacts + UART, ADCs, PWMs and SPI on these targets via C compiling.
The automatized process delivers you a ready made hex file to flash your target using Compile AVRGCC + FlashMCU.
By using AvrDude you can even do all the job without exiting ldmicro.

If you're interested in testing it, download attached zip file and follow HowTo instructions.

Note that SPI works only as master with standard config. It is available in menus with 2 functions to read/write bytes or send strings. Theres' also a SPI simulator similar to Uart's one.

Let me know about your trials...
It's of course a beta testing version !

Best regards
Mon Dec 24 2018, 04:43:42, download attachment LdMicro32.zip
(no subject) (by Alex)
i´m trying to interface 74hc595 for lcd
Mon Dec 24 2018, 12:06:11
(no subject) (by José GILLES)
OK !
It should work because I have tried a true CD4094 which seemed to work with a display
Let me know...
Mon Dec 24 2018, 12:19:59
(no subject) (by Alex)
i press compile but i days it doesn´t support
Mon Dec 24 2018, 15:11:31, download attachment can´t compile spi.jpg
(no subject) (by Alex)
it was with avr studio
Mon Dec 24 2018, 15:23:31
(no subject) (by José GILLES)
Did you use the right compile option ?

It is "Compile Atmel AVR GCC" in the english version.

I've just tried it without problem...
But all others produce the message you had.

You must also follow the HowTo file explainations
to achieve next steps.

Here are generated C files.
Tue Dec 25 2018, 03:13:43, download attachment test-spi.zip
(no subject) (by Alex)
thanks for your reply , i am not the best at c code, i´m seeking for information about programming 74hc595 in c code,i know i am doing something wrong using 74hc595, maybe i have to add something for 74hc595, i follow your "HOW TO" ,
Tue Dec 25 2018, 08:14:27, download attachment spi test arduino uno.pdf
(no subject) (by Alex)
avr studio build
Tue Dec 25 2018, 08:14:48, download attachment avr studio build.pdf
(no subject) (by José GILLES)
Hi Alex

I suppose that compiling finally worked ?

If I understand well your images, you're trying to test SPI on Arduino (via AvrStudio + Proteus simulation) using a 74HC shift register and a standard 16x2 LCD display.

It makes me wonder about several points:

- What is your ladder ? My example test-spi.ld is not a all convenient ; it's a simple file just showing available SPI functions, tested with a SPI slave on another board...

- You don't need to run AvrStudio if you configure flashMCU.bat as explained in HowTo ; but you can use it if you want.

- Your 74HC seems to be well wired to SPI, but I don't think it's possible to have a 2x16 display work like that because you mix command signal on RS+RW+E with data signals on D4-D7 ? Unless you have done it yet ?

- The idea is rather to use a 7-segment common cathode or anode display plugged to pins Q0-Q7, and to send via SPI 7-segment codes using ldmicro converter.

To be continued...
Tue Dec 25 2018, 11:35:18
(no subject) (by José GILLES)
Here are attached a .ld file and a .dsn file for Prot. 7.6 which show that SPI works as intended:
when you press the button, digits increment from 0 to 9 !

Try it one your own and let me know ?
Tue Dec 25 2018, 13:29:45, download attachment Spi+7Seg.zip
(no subject) (by Alex)
i followed some steps wich i consider with my ldmicro and few c code knowledge that i am doing kind ofok, i really need to read more about spi, here is a video about wht i did, watch please

Tue Dec 25 2018, 16:48:30
(no subject) (by José GILLES)
Hi Alex

Your way of doing is almost right...
Except that you donc respect file hierarchy (see HowTo):
Files test-spi.c/.h and ladder must be in the main directory
(OK) but libs should be in a subdirectory called "lib" (NO)
to run my flashMCU.bat

Else, directive #include "..\ladder.h" in spilib.c can't work.
Your project shoudn't compile like that ; but I suppose you load another ladder.h - not mine - from the directory above or from a default include directory.
And of course it can't work !

The simplest way to solve your problem is to modify this include directive in spilib.c: remove "..\" to just have:
#include "ladder.h"

It ought to solve the problem.

PS: Can you tell me the soft you use to make videos ?
I tried VLC but videos are ugly !
Wed Dec 26 2018, 03:57:55
(no subject) (by Alex)
thanks for your reply ill keep trying, my software for recording videos is "HyperCam 4"
Wed Dec 26 2018, 06:28:29
(no subject) (by José GILLES)
To Alex:
Does it work for you ?
Thu Dec 27 2018, 03:13:02
(no subject) (by Alex)
i read again the HOW TO steps as you said and i think i finally made it, i hope i did well, it is the first time i press that flashMCU button in ldmicro, watch video please:


PS: Out of curiosity, for example if i use a 1 second TON timer in my ladder and i compile it with ldmicro and flashMCU (avr studio) , will time accuracy be the same in both options? i mean in the past i tested time accuracy with ldmicro and ansi c ldmicro compiled with PIC C COMPILER, hex generated with ldmicro had timers with good accuracy unlike PIC C COMPILER, flash is just for SPI right? or entire ladder?(timers, uart, etc)
Thu Dec 27 2018, 16:34:11
(no subject) (by José GILLES)
That's perfect !
And it works fine doesn't it ?

FlashMCU does exactly the same job as when you build in AvrStudio. If you had a true board, you may also program the target with it using some command line programmer (ie Avrdude for AVRs).

Concerning timers, I haven't changed anything about it.
My improvements are ADC, PWM, UART and SPI in C mode, lang tables and terminate bug.

Fri Dec 28 2018, 03:48:39
(no subject) (by Alex)
yes, actually, now that i know how to use flash MCU, it looks easy, like if everything is done with ldmicro, thanks a lot José GUILLES
Fri Dec 28 2018, 10:36:14
Post a reply to this comment:
Your Name:
Your Email:
(no HTML tags; use plain text, and hit Enter for a line break)
Attached file (if you want, 5 MB max):