Atmega328p + ENC28J60 = bridge between UART and Ethernet
By creating various electronics and programming AVR, STM, etc. the question always arises of how to connect it to other peripherals to control and transmit information, for example, to a computer.
There are many different solutions: COM, RS482, WiFi, Zigbee, ZWave, Ethernet, etc. Of all the options I tried WiFi, Zigbee, Ethernet, everything else is extremely inconvenient or outdated.
I want to tell and share how you can use the ENC28J60 chip from Microchip and Atmega328p to create a “bridge” (hereinafter) between UART and Ethernet.
There are ready-made motherboards from China with a chip, but this is only a chip without TCP / IP implementation and is large in size.
Therefore, I had to create not only the firmware, but also the printed circuit board itself.
The board is small.
Many people write that the chip is buggy, there are fakes, but I did not manage to meet this in my practice. There are many projects and sources on the Internet for working with this chip, but I have not been able to meet working projects. As a rule, these projects "died" or were not brought to the end by the author. My project is fully working, it can be safely used. So I wanted to share. To date, I no longer use ENC28J60 because he was replaced by the WiFi module ESP8266. I will also write an article later on how to assemble AT, MicroPython, NodeMCU, Esp-Bridge, etc. under ESP8266 But maybe someone else needs a wired Ethernet connection with his devices or a lack of confidence in wireless technology. In any case, each situation has its own decision. There is no universal solution!
All diagrams and explanations at the end of the article. And of course I will answer the questions.
I had the task of connecting remotely to my device on the AVR via the Internet.
The transmission is completely end-to-end and two-way.
That's about this scheme
. Atmega doesn’t have much memory, then I implemented only the most necessary:
For the settings, the Web interface on port 80 is used
- IP address
- Mask
- Gateway
- UARTa speed selection
In my final device there were two boards, the main one with all the logic and separate as a "bridge".
The “bridge” itself was implemented on a separate board, which was already inserted into the main one.
There was an RJ45 connector on the main board (it was convenient for me). You could always remove the "bridge" if the customer did not require this.
Type of model (Altium)
Ready-made circuit board:
In my device:
Key features
- The bridge always listens on port 23 and waits for a connection.
- Only one connection is possible at a time.
- There is ping support
- Fully implemented TCP / IP
- Port speed from 2400 ... 115200
- There is support for RTS / CTS
- 3.3V power
The source code for Atmeg328
Scheme (PDF) and photos of the
Scheme and PCB itself were drawn in Altium`e, if necessary, write send.
In general, I hope this helps someone to implement an external connection to their devices using Ethernet (TCP / IP).