8051 Core Smart Switches, Ethernet Controlled, Part 1

Good day, dear Khabrovites!
The device under development is somewhat repeating IRemo: Tap , as well as some other analogs, which were already written about on Habrahabr. My option will be simpler and cheaper. For communications, I chose the usual twisted pair, and for control the device will have its own web page.
This article describes the first stage, the creation of "brains" for a future project.


So stage number zero


It is always easier to break the development of complex things into simple “bricks”. This is called the scientific principle of modularity. So for a start, let’s think and break our idea into blocks. Globally throughout the device I have identified 3 main modules: control unit, switching unit and power supply.

This article will focus on the control unit, which will operate as a web server, as well as accept and process web forms with requests. And now we sit down and draw a block diagram of the module under development over a cup of cola: The

notation is decrypted as follows:
  • Power supply unit,
  • Control unit,
  • Kn nth switching unit (our device implements only turning off and turning on the light).


The first brick.


First stage.

We begin the development of the first brick by choosing the element base. After familiarizing myself with the microcircuits available in Ukraine, I selected MK C8051F340-GQR (64kb flash, 4kb RAM, 10-bit ADC, crossbar that allows you to configure UART, ADC and SPI to any processor ports, USB, 48 MHz clock frequency from the built-in source, temperature sensor) as the "brains" of the project and the CP2200-GQR chip as an Ethernet controller, which will provide us with a speed of up to 10 Mbps (which is enough for us). Both chips exist in TQFP-48 chassis for surface mounting. More detailed specifications in datasheets C8051F340 and CP2200 .

Of the remaining components, in the first stage we need an Ethernet connector with a 1: 1 transformer, preferably integrated into the connector itself. I chose HR911105A.

Second phase.

The microcircuits are excellent (I had to run for the controller, there is an analogue of CP2201 but it is in the QFN-28 package, and soldering it is a little difficult). At this stage, we will create a circuit diagram.
Here's what I got (image clickable): Now some clarifications:



  1. Let's start by connecting the uk and CP2200. The situation is greatly simplified due to the presence on board of the EMIF (External Memory Interface) interface on both chips, because in fact the CP2200 has a tricked out memory. The address is transmitted by byte P3, byte P4-data, also the bit P1.7 \ not WR when set to 0, the chip understands that we are writing to it at the specified address, and when the bit P1.6 \ not RD is set, reading is performed accordingly. The connection is taken from the datasheet, also R1-8 low-watt resistors have a nominal value of 1 KOhm, and pull them to the pins to the value of the logical unit. Their presence is not necessary.
    Other pins:
    • P0.2 \ INT clock signal, after setting to 1, the microcircuit will begin to process our request
    • P0.0 \ RES-reset signal
    • P0.1 \ CS-choice of microcircuits, as it turned out later, it was also possible not to breed.
  2. Also pay attention to the Q2 quartz resonator; it has a nominal value of 20,000 MHz; its presence is mandatory (Q1 can be omitted).
  3. There are no difficulties with connecting an ethernet connector either; the entire connection is also taken from the datasheet. R14, R14, C16, C17 low-pass filter (ratings are given at the bottom of the article).
  4. Also, I did not forget about yusb. By shorting X1.1 and X1.2 you can get power from the USB using the internal voltage regulator μ, but alas, you will not provide the CP2200 chip with power (output current μ to 100mA, CP2200 requirements to 122mA during transmission).
  5. An LED is connected to X6, which simply glows and signals the presence of power, a transistor key based on the BC847 transistor, control pin P2.7 is output to X8, you can connect an LED here. It helped a lot when debugging the firmware.
  6. X4 is powered by 3.3V. On X2, you can also apply 5V to power various flash drives and other USB devices in the mode when the mic is the master. X3 ports of the C2 programmer. The remaining pins are output to connector X5.

The third stage.

Created a schematic bred. There should be no problems. Since I printed the boards at the factory ( DNVP Electronmash ), I selected the circuit from 2 sides (the upper right corner remained empty, because I drilled holes there, I got a sort of piece of a breadboard). Well, then we export everything to the Gerber format (board image, each side in its file), the holes are saved in the NC drill format. If you do not have a licensed Altium, do not forget to remove all links to the software from the gerbera files, otherwise you will be bred for a fine (there were precedents). If possible, use licensed software. We get the boards, collect: Top: Bottom:








The abundance of wires is due to the fact that I did not know which programmer would be used, it was supposed to initially supply power and data from the programmer, but alas, I made a couple of mistakes when wiring the programmer and it did not work. Therefore, it was brought to the connector used (at the same time, the mock-up part came in handy).

The fourth stage.

Without a description of all the parts, I will not give the firmware code yet, but we will sew a standard example from Silabs there. There is only one problem, all the examples are sharpened under the Silabovsky debugging module, with the prefix CP2200DK. The differences here are only in the control pins, therefore we open the main.c file
We are looking for the function void PORT_Init (void) we change its code to:
void PORT_Init (void) 
{
   IT01CF = 0x02;                      // Enable Interrupt 0 on P0.3
   TCON &= ~0x01;                      // Make /INT0 level triggered
   XBR1    = 0x40;                     // Enable crossbar and enable
                                       // weak pull-ups
   P0MDOUT |= 0x10 | 0x1F;                    // enable UTX as push-pull output
   P1MDOUT |= 0xD8 | 0xFF;                    // /WR and /RD are push-pull
   P2MDOUT |= 0xFF;
   P3MDOUT |= 0xFF;
   P4MDOUT |= 0xFF;
}

We find the void ether_reset_low () function and change it to:
void ether_reset_low()
{
   P0 &= ~0x01;               // Pull reset low
}

We also do it with void ether_reset_high ():
void ether_reset_high (void)
{
   P0 |= 0x01;               // Allow /RST to rise
   while(!(P0 & 0x01));      // Wait for /RST to go high
}

Open mn_userconst.h,
set the ip address:
#define IP_SRC_ADDR  { 192, 168, 0, 6 }

in void main ()
after port_init ();
add
P0 &= ~0x02;//Cs=0

Next, go to VFILE_DIR,
edit index.html,
execute update.bat.
Thus, a standard array of hexadecimal values ​​is made from index.html.
Compile, collect in a hex file, assign an IP address to the computer on the same network and flash it.
Pingem:

Well, we go and look at the result:

If we don’t ping, we check the cable, the program code, and if it’s really bad, we go to friends, we take an oscilloscope and debase.

References:

  1. Reworked example, as well as drawings of the board in altium format (10th version) and a list of elements in pdf format:
  2. Datashits (technical documentation):

Continued in the following articles.

I thank my friends for their help in creating the device and the article.

Also popular now: