- Configuring LinuxCNC
- Advanced Configuration
- EtherCAT
- Ethercat compatible Encoder board tentative STM32F4 + LAN9252
Ethercat compatible Encoder board tentative STM32F4 + LAN9252
- vibram
- Away
- Senior Member
-
Less
More
- Posts: 66
- Thank you received: 1
10 Dec 2025 15:29 - 10 Dec 2025 16:03 #339947
by vibram
Ethercat compatible Encoder board tentative STM32F4 + LAN9252 was created by vibram
Hello,
With the help of @Hakan, I will try to make a SinCos encoder input ethercat compatible board.
I'm a beginner so please don't give credit to my post, this is a learning project.
chip used: STM32F407VE and LAN9252
Here is the git project:
github.com/paulsvc/Firmware
Done:
Step 1: Quadrature Encoder input
Ongoing:
Step 2: Ethernet layer
@Hakan, I struggle to setup the ethernet part. I use the following pins:
SPI2_MISO: PC2
SPI2_MOSI: PC3
SPI_IRQ: PA8
SPI2_SCK: PB10
SPI_NSS: PB8
SYNC0:PC6
SYNC1: PB15
I went through the EASERCAT7000 project but I'm not sure when do you setup these previous pins
Thank you in advance for your help
With the help of @Hakan, I will try to make a SinCos encoder input ethercat compatible board.
I'm a beginner so please don't give credit to my post, this is a learning project.
chip used: STM32F407VE and LAN9252
Here is the git project:
github.com/paulsvc/Firmware
Done:
Step 1: Quadrature Encoder input
Ongoing:
Step 2: Ethernet layer
@Hakan, I struggle to setup the ethernet part. I use the following pins:
SPI2_MISO: PC2
SPI2_MOSI: PC3
SPI_IRQ: PA8
SPI2_SCK: PB10
SPI_NSS: PB8
SYNC0:PC6
SYNC1: PB15
I went through the EASERCAT7000 project but I'm not sure when do you setup these previous pins
Thank you in advance for your help
Last edit: 10 Dec 2025 16:03 by vibram.
Please Log in or Create an account to join the conversation.
- Hakan
- Away
- Platinum Member
-
Less
More
- Posts: 1092
- Thank you received: 379
10 Dec 2025 21:04 #339954
by Hakan
Replied by Hakan on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
I am away from the code for at least one more day. I'll give you some clues for now and give a more precise answer when I am back.
You *must* set up spi. The other pins are set up as needed. Use free-run mode and you don't need them.
Spi is setup using stm32duino standard spi functions.
Somewhere in lib/soes c or h file (also check subdirectories to lib/soes) there is a call to
spi_begin(). Find that . Check there for pins, speed, and Chip Select. And set them to match your dev board.
Use slow speed to start with. Increase as it starts to work. I have on max now (80 MHz?), was on some kHz when troubleshooting.
Actually #if 0 all ethercat code and use the normal arduino setup(), loop() for encoder testing.
If you use serial port output it must be explicitly opened or something, check code.
You should be able to come a long way and then I'm back.
You *must* set up spi. The other pins are set up as needed. Use free-run mode and you don't need them.
Spi is setup using stm32duino standard spi functions.
Somewhere in lib/soes c or h file (also check subdirectories to lib/soes) there is a call to
spi_begin(). Find that . Check there for pins, speed, and Chip Select. And set them to match your dev board.
Use slow speed to start with. Increase as it starts to work. I have on max now (80 MHz?), was on some kHz when troubleshooting.
Actually #if 0 all ethercat code and use the normal arduino setup(), loop() for encoder testing.
If you use serial port output it must be explicitly opened or something, check code.
You should be able to come a long way and then I'm back.
The following user(s) said Thank You: vibram
Please Log in or Create an account to join the conversation.
- Hakan
- Away
- Platinum Member
-
Less
More
- Posts: 1092
- Thank you received: 379
12 Dec 2025 09:52 #339996
by Hakan
Replied by Hakan on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
I am looking at the code now.
Encoder code from E3000 and E2000, are the only ones that have encoder input code.
I see that I treated it is a 16-bit counter even if TIM2 is a 32-bit counter.
I didn't research all registers, I found the encoder code here github.com/goktugh/EncoderStm32F4/
and was so happy when I found something that worked albeit 16-bit.
I think you need all files with encoder in the name
The initialization codeThere is code to handle an index pulse, you may remove that if it isn't relevant for you.
You get the current position from, it counts by itself. Just to read a register.
From that you can expand to velocity and possible other things, if that is interesting.
When you are confident that the encoder counter is rock solid it's time for spi and ethercat.
Settings are here github.com/MetalMusings/MyOwnEtherCATDev...uino-lan9252/spi.hpp The E7000 code is a good place to start for ethercat with LAN9252.
Verification of SPI is done by following the code to, from there to. SPI works when you successfully can read the test register, and the execution continues.
For the EEPROM, sdos and pdos and all that there is a utility in Utils/EEPROM_generator. Bring up a file manager view and double-click the index.html to open it in a browser. Here you enter SDOs and PDOs. Save all and unzip all files into lib/soes-esi and it will be picked up be the code if you used the stanza I have. I think you can program the new eeprom with "ethercat sii_write eeprom.bin". I usually copied the esi file to Twincat and programmed it there, but lately I have used siitool with the -m flag, so siitool -m < xml-file > eeprom2.bin and the ethercat sii_write eeprom2.bin and that have work.
Long post. Take it step by step. Make sure the encoder is rock solid. The ethercat part is pretty flexible once getting to know it.
Encoder code from E3000 and E2000, are the only ones that have encoder input code.
I see that I treated it is a 16-bit counter even if TIM2 is a 32-bit counter.
I didn't research all registers, I found the encoder code here github.com/goktugh/EncoderStm32F4/
and was so happy when I found something that worked albeit 16-bit.
I think you need all files with encoder in the name
The initialization code
///////// Spindle Encoder
#include "MyEncoder.h"
volatile uint16_t encCnt = 0;
void indexPulseEncoderCB1(void);
MyEncoder Encoder1(TIM2, PA3, indexPulseEncoderCB1);
void indexPulseEncoderCB1(void) {
encCnt++;
Encoder1.indexPulse();
}You get the current position from
Encoder1.currentPos();From that you can expand to velocity and possible other things, if that is interesting.
When you are confident that the encoder counter is rock solid it's time for spi and ethercat.
Settings are here github.com/MetalMusings/MyOwnEtherCATDev...uino-lan9252/spi.hpp The E7000 code is a good place to start for ethercat with LAN9252.
Verification of SPI is done by following the code to
ecat_slave_init(&config):ESC_init();For the EEPROM, sdos and pdos and all that there is a utility in Utils/EEPROM_generator. Bring up a file manager view and double-click the index.html to open it in a browser. Here you enter SDOs and PDOs. Save all and unzip all files into lib/soes-esi and it will be picked up be the code if you used the stanza I have. I think you can program the new eeprom with "ethercat sii_write eeprom.bin". I usually copied the esi file to Twincat and programmed it there, but lately I have used siitool with the -m flag, so siitool -m < xml-file > eeprom2.bin and the ethercat sii_write eeprom2.bin and that have work.
Long post. Take it step by step. Make sure the encoder is rock solid. The ethercat part is pretty flexible once getting to know it.
The following user(s) said Thank You: vibram
Please Log in or Create an account to join the conversation.
- vibram
- Away
- Senior Member
-
Less
More
- Posts: 66
- Thank you received: 1
12 Dec 2025 14:20 - 12 Dec 2025 15:01 #339998
by vibram
Replied by vibram on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
Hello and thank you for your reply.
My encoder seems good and with the help of AI I modified the SPI to match my setup. I started from your E7000 version and made some cleaning of the main.cpp.
I went too fast and test in Twincat, I can see the device but its stuck in INIT mode yet. not surprising. I think the old eeprom is still there because in twincat, in the device I can see 8 inputs and 8 outputs, what I had on the original board.
I think I need to build the eeprom stuff correctly but I have absolutely no clue how to do it.
My github is up to date.
Do you have more information regading SDos and PDOs ? How to know what to write?
Thank you
My encoder seems good and with the help of AI I modified the SPI to match my setup. I started from your E7000 version and made some cleaning of the main.cpp.
I went too fast and test in Twincat, I can see the device but its stuck in INIT mode yet. not surprising. I think the old eeprom is still there because in twincat, in the device I can see 8 inputs and 8 outputs, what I had on the original board.
I think I need to build the eeprom stuff correctly but I have absolutely no clue how to do it.
My github is up to date.
Do you have more information regading SDos and PDOs ? How to know what to write?
Thank you
Last edit: 12 Dec 2025 15:01 by vibram.
Please Log in or Create an account to join the conversation.
- Hakan
- Away
- Platinum Member
-
Less
More
- Posts: 1092
- Thank you received: 379
12 Dec 2025 15:26 - 12 Dec 2025 15:32 #340000
by Hakan
Replied by Hakan on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
You decide yourself which SDOs and PDOs you need and want to have.
I propose to have zero SDOs to start with and only one PDO which is the hardware counter number.
You see at ther bottom in the figure, the save/restore button. Download all files, it will create a zip file with al you need.
Unpack those seven? files in lib/soes-esi and rebuild the code. Take the xml file to TwinCat and program the eeprom there.
You decide yourself which Vendor Id. Product code, etc etc you want to have.
Some sizes you should not change, it tells you in the mouse-over comment.
The config struct can look like this
And the loop()
A lot of clean-up yes.
I propose to have zero SDOs to start with and only one PDO which is the hardware counter number.
You see at ther bottom in the figure, the save/restore button. Download all files, it will create a zip file with al you need.
Unpack those seven? files in lib/soes-esi and rebuild the code. Take the xml file to TwinCat and program the eeprom there.
You decide yourself which Vendor Id. Product code, etc etc you want to have.
Some sizes you should not change, it tells you in the mouse-over comment.
The config struct can look like this
And the loop()
A lot of clean-up yes.
Attachments:
Last edit: 12 Dec 2025 15:32 by Hakan. Reason: not!
Please Log in or Create an account to join the conversation.
- Hakan
- Away
- Platinum Member
-
Less
More
- Posts: 1092
- Thank you received: 379
12 Dec 2025 15:49 #340001
by Hakan
Replied by Hakan on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
Attachments:
The following user(s) said Thank You: vibram
Please Log in or Create an account to join the conversation.
- vibram
- Away
- Senior Member
-
Less
More
- Posts: 66
- Thank you received: 1
12 Dec 2025 20:29 #340016
by vibram
Replied by vibram on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
Thank you,
some little progress made, everything compile, run LED is blinking in the LAN9252 board, but I-m not in OP mode yet:
What worries me is that I can still see the original configuration with available switches in Twincat
This means the EEPROM is not flashed correctly I guess?
some little progress made, everything compile, run LED is blinking in the LAN9252 board, but I-m not in OP mode yet:
What worries me is that I can still see the original configuration with available switches in Twincat
This means the EEPROM is not flashed correctly I guess?
Please Log in or Create an account to join the conversation.
- Hakan
- Away
- Platinum Member
-
Less
More
- Posts: 1092
- Thank you received: 379
12 Dec 2025 23:03 - 13 Dec 2025 09:48 #340023
by Hakan
Replied by Hakan on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
Indeed, the old config.
You remember there is a procedure around that.
Copy xml file to config\io\ethercat somewhere (similar)
restart twincat to have it read in new config, scan for devices,
free run mode on, program eeprom, remove device, scan for devices
and with some luck the new config is there. Something like that.
I had it in one if my first youtube videos about ethercat.
Edit.
Upload xml file to C:\TwinCAT\3.1\Config\Io\EtherCAT and restart TwinCAT
Jump to 10:04 and follow the steps
You remember there is a procedure around that.
Copy xml file to config\io\ethercat somewhere (similar)
restart twincat to have it read in new config, scan for devices,
free run mode on, program eeprom, remove device, scan for devices
and with some luck the new config is there. Something like that.
I had it in one if my first youtube videos about ethercat.
Edit.
Upload xml file to C:\TwinCAT\3.1\Config\Io\EtherCAT and restart TwinCAT
Jump to 10:04 and follow the steps
Attachments:
Last edit: 13 Dec 2025 09:48 by Hakan.
The following user(s) said Thank You: vibram
Please Log in or Create an account to join the conversation.
- vibram
- Away
- Senior Member
-
Less
More
- Posts: 66
- Thank you received: 1
13 Dec 2025 12:53 - 13 Dec 2025 13:06 #340047
by vibram
Replied by vibram on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
OK thank you i wil ltry
Last edit: 13 Dec 2025 13:06 by vibram.
Please Log in or Create an account to join the conversation.
- vibram
- Away
- Senior Member
-
Less
More
- Posts: 66
- Thank you received: 1
13 Dec 2025 13:54 #340048
by vibram
Replied by vibram on topic Ethercat compatible Encoder board tentative STM32F4 + LAN9252
some little progress made, I managed to flash the EEPROM, the name of the device changed and I don't see the input/output anymore.
However, I m not able to pass the INIT step
However, I m not able to pass the INIT step
Please Log in or Create an account to join the conversation.
- Configuring LinuxCNC
- Advanced Configuration
- EtherCAT
- Ethercat compatible Encoder board tentative STM32F4 + LAN9252
Time to create page: 0.253 seconds