0
\$\begingroup\$

I am trying to make Ethernet communication with MCU. To make this happen, I need MCU(in this case AT89C2051), Ethernet Controller ( ENC28J60), and a RJ45. However the microcontroller that I selected doesnt have SPI, hence I need to bit-bang it to act as substitute for dedicated hardware SPI. This was intended to be implement within a specific device so that i can create a master/slave connection.

So here is my question:

  1. Does my concept to create a master/slave connection correct?
  2. Is it possible to write bit-bang code in C language/ Assembly language?
  3. If i intend to create a software that interacts with the Master device and control all the slave device, does it mean that I need to use socket programming ?
\$\endgroup\$
7
  • 3
    \$\begingroup\$ You're going to have to be a bit more specific about what you mean by "read IP address". It's own? It has to know that via fixed assignment or something like DHCP. Other peoples? If the packets get to you, the IP addresses will be in the packet headers. Perhaps you need to clarify the requirement from the person who assigned it, spend some time reading about IP networking (maybe play in the context of your PC and wireshark) and look at some examples of embedded code specific to your chip. \$\endgroup\$ Dec 2 '20 at 3:05
  • \$\begingroup\$ IP address is just a small part of a typical network stack; for context see en.wikipedia.org/wiki/OSI_model -- putting a complete TCP/IP network stack on an embedded microcontroller such as AT89C2051 (2kbyte 20-pin 8051 clone) is a really big job. A search for "enc28j60 ethernet library" turns up github.com/njh/EtherCard and forum.arduino.cc/index.php?topic=410502.0 which target Arduino C++ rather than 8051 specifically... Also requires more than just the AT89C2051 and ENC28J60 to test, needs a whole network. Got an Rpi perhaps? \$\endgroup\$
    – MarkU
    Dec 2 '20 at 3:23
  • 1
    \$\begingroup\$ Since you mention you're new to microcontrollers, and this is a very ambitious project, it's very important to break the problem down into much smaller, testable units: (1) blink an LED, to test the compiler/linker/loader works; (2) use AT89C2051 SPI to drive something simple like a 74HC595 shift register; (3) study existing ENC28J60 library code and see how they approached it; (4) try network ping between two PCs and appreciate how TCP/IP and UDP/IP work; finally (5) try network ping from PC to your embedded AT89C2051/ENC28J60 system. \$\endgroup\$
    – MarkU
    Dec 2 '20 at 3:58
  • \$\begingroup\$ Read about TCP/IP protocol. \$\endgroup\$
    – Mitu Raj
    Dec 2 '20 at 16:56
  • 1
    \$\begingroup\$ Don't try to do this from scratch. Find examples. Seriously consider changing to a more suitable MCU. \$\endgroup\$ Dec 10 '20 at 4:21
0
\$\begingroup\$

AT89C2051 doesn't have SPI peripheral to communicate with the enc28j60. You would have to bit bang SPI (software SPI).

The enc28j60 doesn't handle the TCP/IP stack, so the MCU must handle it, but the AT89C2051 has only 2kB of memory.

The 8 kB enc28j60 internal memory can be used to store network packages, but to handle this over bit banged SPI really doesn't make much sense.

\$\endgroup\$
4
  • \$\begingroup\$ Thank you so much, after taking nearly one week to conduct research about SPI and bit bang. I finally get what you mean. I am gonna label this as accepted answer, so that in the future if there is anyone who try to form connection between MCU and Ethernet controller have a basic concept on the requirement to make it happen. \$\endgroup\$
    – Gizzle30
    Dec 10 '20 at 3:21
  • \$\begingroup\$ And for the storing of network packages, do you think by adding a micro sd slot(so the network storage can be stored within it), will it be a good solution? \$\endgroup\$
    – Gizzle30
    Dec 10 '20 at 3:24
  • \$\begingroup\$ No, because you need another SPI connection and more memory to interface with an SD card. \$\endgroup\$
    – Ron Beyer
    Dec 10 '20 at 4:29
  • \$\begingroup\$ the storing of packages in ENC means they are not transferred over SPI, but only copied with DMA functions of the ENC from location where the ENC has the RX queue to a free location in the same memory \$\endgroup\$
    – Juraj
    Dec 10 '20 at 6:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.