Sunday, December 20, 2009

New WiZnet's software-Virtual Serial Port

In order to support the customer's development,reduce the development difficulty,WIZnet is going to promote the Vitual Serial Port Programme.Virtual Serial Port has totally 2 advantages.
1. Reduce the development difficulty when the customer want to upgrade their system.It upgrades from the serial to the ethernet,WIZnet can convert the serial to the ethernet and vice versa.2. Expand the number of unit PCs Virtual Serial Port,it is supposed to support 255 Virtual Serial Ports and the distant serial throught the internet communication.
The comparison figure:

Translated from Johnny Yan,''WIZnet即将推出虚拟串口(Virtual Serial Port)''

Source:http://blog.sina.com.cn/s/blog_61b952280100gcrn.html

Friday, December 18, 2009

Common Register Part 1

Hi All,

Last week, I have briefly go through the types of registers within our chipset. This week we will go through the common registers. So the figures below shows an overview of our common registers.


The Mode Register: This is used for soft reset, enabling indirect bus mode, and other modes

Gateway Address Register: This is where the gateway IP address is stored

Subnet Mask Register: This is where the subnet mask is tored

MAC Address Regiter: This register is for storing the MAC address of the device. Notice that the first byte must be a even number. You should register your own MAC address with IEEE before using a MAC address to prevent collision.

Server IP Register: This is where the IP address of the device is stored.

Interrupt Register: This is for checking which interrupt is occuring

Interrupt Mask Register: This is used for enabling various interrupts

Retry Time Register: This sets the number of 100us before our chipset attempts to resend. Besure to set this value to longer if your network is slow to avoid any packets duplication.


Retry Count Register: This sets the number of tries before the connection times out.

We will go through part two of the common registers next week!

See you :)

Friday, December 11, 2009

Registers within our Chip

Hi all,

I just wanted to clarify about the registers within our chipset.
There are two types of registers within our chip. One type is the Common register which stores source IP address, gateway address, Subnet Mask Address, and the MAC address. Because all sockets uses the same common source IP address that is the reason why these registers are called common registers. The second type of registers is the Socket Register. They are specifically used for storing socket information such as source port, destination IP address, destination port and so forth. Notice that W3150A+ and W5100 have 4 hardware sockets so there are 4 sets of socket registers. The same is true for the W5300 with 8 sockets. There will be 8 sets of socket registers inside the chip.

In the case of W5100, the common registers' address starts from 0x0000 to 0x3FF. The 4 sets of socket registers are located from 0x0400 to 0x04FF,0x0500 to 0x05FF,0x0600 to 0x06FF,0x0700 to 0x07FF.

For my next post, I will get into the details of each registers. Be sure to check it out! :)

Thank you

WIZnet HK

Friday, December 4, 2009

LED Status

Our chip provides six different network statues. Here are the six different LEDS:

1) LINKLED: Link LED / Active low in link state indicates a good status for 10/100M. It is always ON when the link is OK and it flashes while in a TX or RX state


2) SPDLED: Link speed LED / Active low indicates the link speed is 100Mbps


3) FDXLED: Full duplex LED / Active low indicates the status of full-duplex mode.


4) COLLED: Collision LED / Active low indicates the presence of collision activity.


5) RXLED: Receive activity LED / Active low indicates the presence of receiving activity.


6) TXLED: Transmit Activity LED/ Active low indicates the presence of transmitting activity.

Generally the yellow and green LEDs in the RJ45 jack are connected to the Full Duplex LED signal, and the Link LED signal respectively. During receive and transfer, the LINK LED blinks. If you want to separate the LINK LED signal from the transfer and receive LED, the following circuit should be implemented.

I hope you enjoy Thanks!



Thursday, November 26, 2009

Hybrid Mode

What is Hybrid Mode? Hybrid mode is used when both hardware and software TCP/IP processing are required. So what is the advantage of using this kind of system? As you may know, for the hardware TCP/IP stacks, there is a limited number of sockets available. If the user wants to use more sockets than our chip can provide, he can take advantage of the Hybrid mode because the software TCP/IP stack offers unlimited sockets. With the hybrid mode, the user can create unlimited number of sockets since hardware and software TCP/IP stack are running at the same time. In order to use the hybrid mode, MAC raw mode should be setup for the hardware socket 0. The socket 0 will be used as a tunnel to send and receive Ethernet frame for the software stack. While socket 0 is used for the tunneling, the remaining sockets can be used with the hardware stack. Notice that using this hybrid mode, the user is required to port the software stack into the MCU.

I hope you enjoyed. Thank you!

Monday, November 9, 2009

WIZnet Chipset Modes

In this entry, I will explain about the different modes within our chip set. This concept might be hard to understand without a reference model to refer to. That is why I show you this picture
the Bottom Network layers.


Our chipset offers 3 different modes: TCP/UDP Mode, IP Raw Mode, and MAC Raw Mode. Each of these modes represents the different network layer. In MAC RAW mode, the entire Ethernet frame is provided to the MCU without any processing. In IP Raw Mode, the IP datagram is extracted from the Ethernet Frame. In this case, the IP datagram along with the IP header is provided to the MCU. Lastly, in TCP/UDP mode, all the networking headers are removed. You might have expected that TCP/UDP headers are included in the TCP/UDP mode, but actually only the encapsulated data within TCP packets /UDP datagram are provided to the MCU. Most applications use the TCP/UDP mode.

That's it for today. I hope you enjoyed it! Thanks! :)

Tuesday, October 6, 2009

HTTP Client Concept

Recently, I have been working on a HTTP client. This HTTP client is for connecting to the Internet and retrieve any types of files. I am working on a platform which uses an Atmega128 with 128KByte of Flash. As you can see, this platform has limited resource. For example, if I download a 1 Mbyte picture. It is impossible to store all the data into the flash. Even if I am able to store all the data, there is no LCD monitor to display the picture.

To overcome this limitation, I have thought of outputting all the received data in HEX via SERIAL. Then I use my computer's terminal program to capture all of the HEX received by the COM port. With this method, I can download any files regardless of the file size.

Now the question is I have a bunch of HEX which resemble the actual file, but how do I open this file? Now the HEX editor comes into play. You first use your favorite HEX editor and open a new file. Then Import all the HEX values into the HEX editor. Once this step is done, you should save this file as the file type which you have downloaded (e.g. .jpg, .bmp, .mp3)

Tuesday, September 29, 2009

W5100 simple UDP protocol development and code analysis (Transalated Version)

Here is my W5100 simple UDP protocol code analysis,using W5100 development board (atmega128)

We can see, UDP and TCP protocols, respectively, in fact, very easy to use, as long as you can call the different functions.

Note the code is as follows:


#include
#include
#include
#include
#include
#include "../header/types.h"
#include "../header/serial.h"
#include "../header/socket.h"
#include "../header/w5100.h"
#define MAX_SIZE 2048
#define RX_BUF 0x1100
#define TX_BUF 0x1900
void main()
{
cli(); // disable interrupt
EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;
EIFR=0x00;
MCUCR = 0x80; // enable external ram
XMCRA=0x40; //define lower sector of memory for EXternal ram and upper sector for W5100C and others
sei(); // enable interrupts
uart_init(0,7);
lcd_init();
uint8 destip[4];
uint8 addr[6];
iinchip_init();
sysinit(0x55,0x55); //
addr[0] = 192; addr[1] = 168; addr[2] = 1; addr[3] = 20;
setSIPR(addr);
addr[0] = 192; addr[1] = 168; addr[2] = 1; addr[3] = 1;
setGAR(addr);
addr[0] = 255; addr[1] = 255; addr[2] = 255; addr[3] = 0;
setSUBR(addr);
memcpy(addr, "\x00\x08\xDC\x00\x00\x00",6);
setSHAR(addr);
uint8 lcd[50];
sprintf(lcd,"IP: %d.%d.%d.%d",IINCHIP_READ(SIPR0),IINCHIP_READ(SIPR0+1),IINCHIP_READ(SIPR0+2),IINCHIP_READ(SIPR0+3));
lcd_puts(lcd); //print LCD string into LCD

uint8 len;
// set UDP mode
socket(0, Sn_MR_UDP, 5000, 0);
// listen(0); //UDP no need to listen
if( getSn_SR(0) == SOCK_UDP)
{
printf("UDP Mode"); // Check socket status register, it is in UDP status
}
while(getSn_RX_RSR(0) ==0 ); // if got data, RX buffer over 0, while loop will end
printf("got data \r\n");
len = getSn_RX_RSR(0); // get length of data received
uint8 * TX_BUFFER = (uint8 *) TX_BUF;
uint8 * RX_BUFFER = (uint8 *) RX_BUF; // make transmit and receive buffer
if( len > MAX_SIZE)
len = MAX_SIZE; // limit the length of data to be copy into TX/RX buffer as MAX
//extern uint16 send(SOCKET s, const uint8 * buf, uint16 len); // Send data (TCP)
//extern uint16 recv(SOCKET s, uint8 * buf, uint16 len); // Receive data (TCP)
//extern uint16 sendto(SOCKET s, const uint8 * buf, uint16 len, uint8 * addr, uint16 port); // Send data (UDP/IP RAW)
//extern uint16 recvfrom(SOCKET s, uint8 * buf, uint16 len, uint8 * addr, uint16 *port); // Receive data (UDP/IP RAW)
//sendto and recvfrom are used for UDP, in contrast, TCP uses send and recv function
// because TCP is connection oriented, once connection is established, no need to assign send to which or receive from which client
len = recvfrom(0,RX_BUFFER,len, destip, 5000); //receive into RX buffer
printf("the size is %u \r\n",len);


printf("%s",RX_BUFFER);
// printf("%02x",*(RX_BUFFER + 1));
// printf("%02x",*(RX_BUFFER +2) );
// in case of more than one character, print 0, 1, 2 address
sendto(0,RX_BUFFER,len,destip, 5000); //send RX buffer to client
}


Translated from Johnny Yan,posted on 28/09/2009
The direct link (Chinese Version): http://blog.sina.com.cn/s/blog_61b952280100f8qj.html

Thursday, September 24, 2009

Internet Radio (iRadio) Application Profile

Internet Radio (iRadio) is an R n D case from our partners, he used a low-end MCU to handle audio decoding, using W5100 to deal with network and network audio streaming data acceptance. The main chip is a ATMEL AVR32, the server uses the open DLNA server program. At last, the network audio are streaming playback.

The schematic and main configurations are as follows.

Main hardware configurations:
Hardware Specifications:

- AVR32 for MP3 and WMA decoding
- W5100 10/100Mbps Ethernet Controller with Network Protocols
- 1MByte SDRAM for audio buffering
- 2.4” color TFT (320x240)
- DC 5V input for core, DC12 input for Audio Amplifier
BOM List:
- W5100 + RJ45
- AVR32 or similar
- SDRAM 1MByte
- 2.4” TFT (2.2”)
- Power and Misc
- Audio Amplifier (about 20W)
Features:
- Local playback on SD Card (pending, waiting for Atmel)
- Internet Radio with MP3 (working now) and WMA format (debugging)
- Download Station lists from Portal in XML format
- DLNA Renderer to play audio streamed from DLNA server
Server format:

• HTTP: working now
• MMS: implementing
• RTSP: planned
Applications:
- Internet Radio, with DLNA Renderer
- Embedded with other AV system, (no need to count TFT), such as Boom box, Photo frame,
DVB, DVD…even we could share the SoC in the system, for example, in DVD; we just need to add W5100 + RJ45 to have same functions.

Translated from Johnny Yan on 20/09/2009
Direct link (Chinese version): http://blog.sina.com.cn/s/blog_61b952280100f4ox.html


W5100 simple TCP communication protocol development and firmware update

Here is my W5100's TCP protocol with a simple firmware notes, we use the W5100 development board (W5100E01-ARV), the development and updating is very simple, AVR Studio using schematic at the end.

This socket program to achieve a simple build, Ethernet sends and receives data procedure.
You can call the device terminal to test. (In WIZnet the home page you can search for this small software, can easily exchange data in serial and Ethernet)

Procedures are as follows:


#include # include
#include # include
#include # include
#include # include
#include # include
#include "../header/types.h" # include ".. / header / types.h"
#include "../header/serial.h" # include ".. / header / serial.h"
#include "../header/socket.h" # include ".. / header / socket.h"
#include "../header/w5100.h" # include "../header/w5100.h"
#define MAX_SIZE 2048 # define MAX_SIZE 2048
#define RX_BUF 0x1100 # define RX_BUF 0x1100
#define TX_BUF 0x1900 # define TX_BUF 0x1900
void main() void main ()
{ (
//initialize / / initialize
cli(); // disable interrupt cli (); / / disable interrupt
EICRA=0x00; EICRA = 0x00;
EICRB=0x00; EICRB = 0x00;
EIMSK=0x00; EIMSK = 0x00;
EIFR=0x00; EIFR = 0x00;
MCUCR = 0x80; MCUCR = 0x80; // enable external ram / / Enable external ram
XMCRA=0x40; //define lower sector of memory for EXternal ram and upper sector for W5100C and others XMCRA = 0x40; / / define lower sector of memory for EXternal ram and upper sector for W5100C and others
sei(); sei (); // enable interrupts / / Enable interrupts
uart_init(0,7); uart_init (0,7);
lcd_init(); lcd_init ();
//set IP address / / set IP address
uint8 addr[6]; uint8 addr [6];
iinchip_init(); iinchip_init ();
sysinit(0x55,0x55); // sysinit (0x55, 0x55); / /
addr[0] = 192; addr[1] = 168; addr[2] = 1; addr[3] = 20; addr [0] = 192; addr [1] = 168; addr [2] = 1; addr [3] = 20;
setSIPR(addr); setSIPR (addr);
addr[0] = 192; addr[1] = 168; addr[2] = 1; addr[3] = 1; addr [0] = 192; addr [1] = 168; addr [2] = 1; addr [3] = 1;
setGAR(addr); setGAR (addr);
addr[0] = 255; addr[1] = 255; addr[2] = 255; addr[3] = 0; addr [0] = 255; addr [1] = 255; addr [2] = 255; addr [3] = 0;
setSUBR(addr); setSUBR (addr);
memcpy(addr, "\x00\x08\xDC\x00\x00\x00",6); memcpy (addr, "\ x00 \ x08 \ xDC \ x00 \ x00 \ x00", 6);
setSHAR(addr); setSHAR (addr);
uint8 lcd[50]; uint8 lcd [50];
// IINCHIP_READ / / IINCHIP_READ get register value from SIPR(Source IP register) get register value from SIPR (Source IP register)
sprintf(lcd,"IP: %d.%d.%d.%d",IINCHIP_READ(SIPR0),IINCHIP_READ(SIPR0+1),IINCHIP_READ(SIPR0+2),IINCHIP_READ(SIPR0+3)); sprintf (lcd, "IP:% d.% d.% d.% d", IINCHIP_READ (SIPR0), IINCHIP_READ (SIPR0 +1), IINCHIP_READ (SIPR0 +2), IINCHIP_READ (SIPR0 +3));
lcd_puts(lcd); lcd_puts (lcd); //print LCD string into LCD / / print LCD string into LCD
uint8 len; uint8 len;
//Create socket 0 for TCP mode / / Create socket 0 for TCP mode at port 5000 at port 5000
//#define Sn_MR_TCP / / # define Sn_MR_TCP 0x01 0x01
socket(0, Sn_MR_TCP, 5000, 0); socket (0, Sn_MR_TCP, 5000, 0);
//extern uint8 socket(SOCKET s, uint8 protocol, uint16 port, uint8 flag); / / extern uint8 socket (SOCKET s, uint8 protocol, uint16 port, uint8 flag);
//listen the socket 0 / / listen the socket 0
listen(0); listen (0);
//check the status of Listen status (if entered), print to serial / / check the status of Listen status (if entered), print to serial
if( getSn_SR(0) == SOCK_LISTEN) if (getSn_SR (0) == SOCK_LISTEN)
{ (
printf("Listen Mode"); printf ( "Listen Mode");
} )
// if data is received / / If data is received
// extern uint16 getSn_RX_RSR(SOCKET s); // get socket RX recv buf size / / Extern uint16 getSn_RX_RSR (SOCKET s); / / get socket RX recv buf size
while(getSn_RX_RSR(0) ==0 ); while (getSn_RX_RSR (0) == 0);
printf("got data \r\n"); printf ( "got data \ r \ n");
//print data length / / print data length
len = getSn_RX_RSR(0); len = getSn_RX_RSR (0);
printf("the size is %u \r\n",len); printf ( "the size is% u \ r \ n", len);
//set Send(TX) and Receive(RX) buffer pointer / / set Send (TX) and Receive (RX) buffer pointer
uint8 * TX_BUFFER = (uint8 *) TX_BUF; uint8 * TX_BUFFER = (uint8 *) TX_BUF;
uint8 * RX_BUFFER = uint8 * RX_BUFFER = (uint8 *) RX_BUF; (uint8 *) RX_BUF;
if( len > MAX_SIZE) if (len> MAX_SIZE)
len = MAX_SIZE; len = MAX_SIZE;
//put the received data into RX buffer, save length to len / / put the received data into RX buffer, save length to len
len = recv(0,RX_BUFFER,len); len = recv (0, RX_BUFFER, len);
//send data from RX Buffer to socket 0 / / send data from RX Buffer to socket 0
send(0,RX_BUFFER,len); send (0, RX_BUFFER, len);
} )

Compiled using AVR STUDIO, generate hex file, and then burn to the MCU chip (Atmega128)
Images are as follows:

http://photo.blog.sina.com.cn/blogpic/61b952280100f4ou/61b95228g740500163fad

In the next blog, we will try to introduce how to use the UDP protocol.
I hope you can enjoy it!

Johnny



The blog was translated from Johnny Yan on 20/09/2009

Direct link(In Chinese Version): http://blog.sina.com.cn/s/blog_61b952280100f4ou.html

Wednesday, September 23, 2009

Full hardware Ethernet + W7100 single-chip microcontroller program

W7100 in a chip set and the 8051 standard full hardware decoding of microcontroller and TCP / IP Ethernet protocol stack.It is WIZnet traditional full-extension hardware, networking chip functionality to give users a single-chip Ethernet + master-chip choices.

See the following diagram:
http://photo.blog.sina.com.cn/blogpic/61b952280100f1si/61b95228gc82b5a862d05

Its basic features include:
· Single-chip embedded network program
· Built 8051
· Full hardware TCP / IP network protocol stack
· 10/100 Ethernet
· 64K Byte e-Flash Memory
· 64K Bytes SRAM memory





It is an extension of traditional products W5100 features and upgrades. For some users, if the processing capacity of 8051 has been adequate to meet the application requirements, then the W7100 can easily add Ethernet capabilities for these applications at the same time to replace the main chip. Both of them get the advantages in terms of price and performance.


More information can visit the product home page at:http://www.wiznet.co.kr/en/pro02.php?&ss [2] = 1 & page = 1 & num = 211


Translated from Johnny Yan on 13/09/2009
The Link: http://blog.sina.com.cn/s/blog_61b952280100f1si.html

W7100 Study Notes-W7100 parts of the firmware (firmware) parsing

With the launch of our new W7100 chipset, the firmware development is constantly updated and improved to meet the needs of different customers

The Hong Kong Branch of WIZnet Ltd. is now designing customized firmware to accommodate different applications.

Typically, users can easily use our hardware tcp/ip stack without in-depth knowledge of TCP/IP.
As the network protocol is fully processed by hardware, the user simply uses the driver which we provide, and calls different functions to complete various network tasks.
For example, if the user would like to connect by using TCP, the connect function should be called.

The user simply uses socket programming to control our chipset while leaving out the complicated details for our hardware TCP/IP core to process.
Here is my W7100 firmware for the connect function. As you can see, the internal operation of the function is not very difficult. The user can easily change the function to accommodate his/her needs.
int8 connect(SOCKET s, uint8 * addr, uint16 port)
{
uint8 xdata ret;

if
(
((addr[0] == 0xFF) && (addr[1] == 0xFF) && (addr[2] == 0xFF) && (addr[3] == 0xFF))
((addr[0] == 0x00) && (addr[1] == 0x00) && (addr[2] == 0x00) && (addr[3] == 0x00))
(port == 0x00)
)
Check if the IP address and Port number is coorect (IP cannot be 255.255.255.255, or 0.0.0.0, port cannot be 0
{
ret = 0;
}
else
{
If IP and Port both no problem, continue
ret = 1;
// set destination IP
IINCHIP_WRITE(Sn_DIPR0(s),addr[0]); set Dest IP first byte
IINCHIP_WRITE((Sn_DIPR0(s) + 1),addr[1]);
IINCHIP_WRITE((Sn_DIPR0(s) + 2),addr[2]);
IINCHIP_WRITE((Sn_DIPR0(s) + 3),addr[3]);
IINCHIP_WRITE(Sn_DPORT0(s),(uint8)((port & 0xff00) >> 8)); dest Port lower byte
IINCHIP_WRITE((Sn_DPORT0(s) + 1),(uint8)(port & 0x00ff)); dest Port higher byte
IINCHIP_WRITE(Sn_CR(s),Sn_CR_CONNECT); exe the command of tcp connect
while ( IINCHIP_READ(Sn_CR(s)) ) ; // wait for completion CR
}

return ret;
}

Johnny

Translated from Johnny Yan 0n 13/09/2009
Direct link: http://blog.sina.com.cn/s/blog_61b952280100f1sl.html

FAE Basic Training

This week, we will have our first Basic FAE training.

Time: September 24, 2009 (2:30pm Hong Kong Time (GMT+8))
Method: Webex
Language: English

Please download the training material from the link below:

Please rate my training by registering to our forum. We welcome you post anything related to our products and questions as well.

Here is the link to register

After registering, you can vote and post comments in my thread
http://www.wizwiki.net/forum/viewtopic.php?f=13&t=62

Welcome to our WIZwiki forum. I look forward to seeing you all in our forum.

Thank you very much!

Tuesday, September 22, 2009

W5100 simple and compact network news display

Network News display


The following video is one of the designs from our past contest.We have held a design contest in 2007. Here is the second prize winner.


For more details please refer to the U.S. magazines: and our Wiz WiKi. website





I would like to briefly explain the functionality of this device:
Basically, the W5100 receives the news from a News website. Once the W5100 remove all the TCP/IP headers, the news data is parsed out from the packet and stored in the MCU’s memory. Finally, the News is displayed onto the LED display.
The schematic and video are shown below:





A video could be viewed through the link
http://blog.sina.com.cn/s/blog_61b952280100eyxd.html


The blog was translated from Mr. Johnny Yan on 07/09/2009



Wifi Alternative

So recently, I have been talking to some customers about products with WIFI.

Here are a list of problems which they have encountered

1) The cost is high
2) Setup is complicated for End Customer
3) Power consumption is high

So what do we do if we dont use wifi? Is there any other altenatives? Of course there is! The answer is RF transceiver! They are relatively cheap when compared with WIFI solutions. Since there are no specific protocol to follow in the RF solution , it is very easy to setup. Most of all, the power consumption is low! So you can use it for mobile devices. :)

With these advantages, the RF solution is a good replacement for WiFi, but what if you want to use RF with Internet capabilities? Then you should consider using a Ethernet to RF gateway. This is a good solution since you don’t have to spend a lot of money on the hardware and also the user can sync the receiver and transmitter by just clicking a button.

Below shows the Ethernet to RF gateway. This is for connecting to the router.








The module below is the receiver which is the mobile device



Basically, the RF transceivers act as a wireless link for the internet connection.


This concludes our article for today. Thank you!

SPI Guide Part 2

In this session, we will talk about the SPI write and read process. Currently, our chipset W3150A+ and W5100 supports SPI mode 0. It's important to know which mode your SPI uses. Or else it wont work at all. Please make sure that your MCU supports SPI mode 0.

Anyway it is very basic to use the SPI interface. Basically you just have to follow the format below:





For the write operation, you should write the OP-code 0xF0 (11110000) follow by the 2 bytes address and finally the 1 byte of data which you wanted to write.


For the read operation, you should write the OP-code 0x0F (00001111) follow by the 2 bytes address. Then, our chip will send you the 1 byte of data by the MISO line.

The SPI follows the timing diagram below:





Notice in the timing diagrm:
When sending the OP-CODE, the MISO line is 0x00.
When sending the address, the MISO line is 0x01 follow by 0x02
When the data is written, the MISO line is 0x03.
When the data is read, the MISO line is the requested data.

I hope you enjoy my article Thanks!

Sunday, September 13, 2009

W5100 PCB design Considerations


The other day I was visiting my customer in China. I actually visited a few customers. Actually, you do get a lot more information from the customer when you talk to them face to face instead of email. I guess some customers won't tell you their problem until you meet them in person.
Anyway, this customer I visited has designed their own board and PCB. Upon looking at their PCB, I noticed that the MAG JACK's ground is not isolated. This might cause EMI and EMC interference. It is a better pratice to seperate the ground planes especially the RJ45 is very likely to sustain noise from the Ethernet cable. In this article, we will go through a few design considerations for the PCB design.

1) Isolate the ground plane of RJ45 from the main ground plane. Connect these two ground plane by ferrite bead. Be sure there is no ground plane under the isolated area

2) Place circuitry A and B as highlighted in the picture as close to the magnetic as close as possible

3) The crystal should not be placed close to I/O port, edge of PCB board or the magnetic devices














I hope this helps you design your PCB board :) Thanks!



Serial to Ethernet Part 3

In part three of serial to Ethernet, we will go over the data receiving process from the Ethernet. Because we are not using any interrupt for Ethernet data, we are basically checking if there are any Ethernet data stored in the RX buffer. If there are data in the RX buffer, we will print out the data from the Ethernet. The first step is to check for the number of data inside the RX buffer by using the getSn_RX_RSR function. This function returns the number of bytes in the RX buffer. If this value is greater than 0, this means that you can use the recv function to get the data.

void lan_to_rs232()
{
uint16 xdata chk_length; // length checker
uint16 xdata rcv_length; // length of data received
uint16 xdata idx; // for loop index

chk_length = getSn_RX_RSR(0); // get length of data in lan receive buffer
if(chk_length > 0) // check if there is data in lan receive buffer
{
if(chk_length > MAX_BUF_SIZE) chk_length = MAX_BUF_SIZE;

//check if length of lan received buffer is more than LAN_RX_BUF

rcv_length = recv(0,LAN_RX_BUF,chk_length); //receive data

for(idx = 0; idx <>

Sunday, September 6, 2009

SPI Guide

SPI is one of the popular interfaces for embedded systems. Since SPI supports full duplex mode as oppose to I2C , it is a very attractive interface. Also, this interface uses four wires only (MOSI, MISO, Chip select and a reference clock) Because SPI doesn't need any special protocol to use it, it's actually a very simple interface and easy to use.

Currently, only our W3150A+ and W5100 support the SPI interface. Our chipsets run in SPI slave mode 0.

In order to use our chip via SPI, you should connect our chip by using the following schematic.

Be sure that the SEN pin is connected to the source. If you are using multiple SPI peripherals, you should use an inverter to invert the /SCS signal. Then, the inverted signal should be feed to the SEN pin to avoid any problems with other SPI devices. The following schematic is for multiple SPI peripherals.

This is the basic connection for the SPI interface. I hope you enjoy! Thank you



Friday, September 4, 2009

Serial to Ethernet Gateway Part 2

In this article, we will continue where we left off last week. After talking about the concept of ring buffer, how do we get the Serial data ? I have used serial interrupt to get data from the serial buffer. So whenever I get Serial data, the interrupt flag will be triggered. At this time, I have made the program to run an interrupt subroutine which gets data from the Serial Buffer and copy these data to anther designated buffer.

One question is what happens if the serial data buffer is full? In my design, whenever the serial buffer is full, we would send out all the data in the current serial buffer all at once. This ensures that none of the incoming serial data gets dropped due to the buffer is full.

Below is the code I have made. The first function is the interrupt subroutine, and the second function is to prepare the serial buffer for the LAN transfer buffer to send.



void ISR() interrupt 4 //ISR for UART
{
ES = 0; //Disable UART interrupt

if(RI) //Check for Receive Interrupt flag
{
RS232_RX_BUF[rs232_rx_write_idx] = SBUF; //write data from Serial buffer to uart rx buffer
rs232_rx_write_idx++; // increment write pointer
if(rs232_rx_write_idx >= MAX_RS232_BUF_SIZE) // check if write pointer is bigger than Maximum size of RS232_RX_BUF
{
rs232_rx_write_idx = 0; // reset write pointer to zero
}

if (rs232_rx_write_idx == rs232_rx_read_idx ) isfull = 1; // buffer is full, ignore new serial data
else
{
if (rs232_rx_write_idx == rs232_rx_read_idx ) isfull = 1; //buffer is full
}
RI = 0; // Disable Receive Interrupt flag
}
ES =1; //Enable UART Interrupt
}

uint16 rs232_to_lan()
{
uint16 xdata safe_read; // local read pointer
uint16 xdata safe_write; // local write pointer
uint16 xdata length; // length of data to be read
uint16 xdata count; // for loop counter

EA = 0; //disable all interrupt
safe_read = rs232_rx_read_idx; // get current value of read pointer
safe_write = rs232_rx_write_idx; // get current value of write pointer
EA = 1; //enable all interrupt

if(safe_write > safe_read)
{
length = safe_write - safe_read; // calculte the number of data to be read
}

else if(isfull == 1)
{
length = MAX_RS232_BUF_SIZE;
}
else
{
length = (MAX_RS232_BUF_SIZE - safe_read) + safe_write; // calculate the number of data to be read
}

for(count = 0; count <>
{
LAN_TX_BUF[lan_tx_write_idx] = RS232_RX_BUF[safe_read]; //write data from RS232 RX buffer to LAN TX buffer
safe_read++; //increase read pointer
if (safe_read >= MAX_RS232_BUF_SIZE) safe_read = 0; //RS232 RX buffer boundary check
lan_tx_write_idx++; //incread write pointer
if (lan_tx_write_idx >= MAX_BUF_SIZE) lan_tx_write_idx = 0; //LAN TX buffer boudary check
}

EA = 0; //disable all interrupt
rs232_rx_read_idx = safe_read; //return local readpointer to rs232 read pointer
EA = 1; //enable all interrupt
return length; //return length of data read
}

Thank you. I hope you enjoy my article. :)

Friday, August 28, 2009

Serial To Ethernet Gateway Part 1

In this article, I will talk about the design considerations for making serial to ethernet gateway.
One might think it is very easy to implement such a device. If you have both the Ethernet and Serial Input/Output (I/O) , you just have to connect the serial output to the ethernet input or vice versa to do the conversion. There you have it!! Finished! That is actually a very ideal case.

In real life, data doesn't just come in and out at a constant flow. Sometimes there are a lot of data to process, but sometimes there are none. This is similar to a highway. During the morning traffic, there are tons of people driving to work, but during the off hours, there are none.

So how do we design a system so that we can accommodate all the data coming in from serial and convert them into Ethernet data?
Well the answer is ring buffer.

A Ring buffer is type of data structure which returns to the starting point whenever the maximum is reached. In this case, the older data get written over by the new data. When using a ring buffer you need to have a write pointer and read pointer so that you can keep track of your data.

There are four cases to consider
(Notice that orange box indicates new data is written into the buffer)

1) Empty Buffer (Write pointer = Read pointer)


2) New data is written into buffer (Write pointer > Read pointer)


3) New data is written into buffer and the write pointer loops back to the beginning
(Read Pointer > Write Pointer)


4) Buffer is full (Write pointer = Read Pointer)
If your buffer is large enough, the likelihood of case 4 is very slim. However, you should still put case 4 into your consideration when designing the ring buffer.

After observing the behavior of these cases, it is important that you implement every possible cases to ensure that your system is stable. Next time, I will go through the source code for this project. Thanks for viewing

Enjoy!








Thursday, August 27, 2009

UDP Programming


User Datagram Protocol is an alternative way of sending/receive data through the internet without establishing a connection. Unlike TCP, UDP is unreliable because the receiver is not guaranteed to get the data. In addition, out of order packets may occur in the receiver's side.

As a result, UDP is mostly used in video and audio streaming because delayed packets effect the playback quality( i.e. lagging) while dropped packets do not effect the playback quality as much as delayed packets. Another unique UDP's characteristic is the ability to broadcast and multicast to different users.

The Other Day I wrote a program for testing our new W7100 in UDP mode. This program basically sends out a reply message whenever the W7100 receives a UDP message from a UDP client.

There are some considerations when writing this program:

1) How long does the Ethernet negotiation take place?
Currently, I have delayed the program to start after 7 seconds has elapsed
Without this delay, the program will go wild!

2) How much buffer is needed when receiving ?
The buffer string size is the same size as the RX buffer in the W7100 socket.

I hope you enjoyed my article. Enjoy Programming!

Below is the code which I have used to perform this test.

#define MAX_BUF_SIZE 2048 // define maximum buffer size

uint8 xdata pDestaddr[4]; //xdata using external ram

uint16 xdata pPort; // destination port

uint8 xdata rcvLen; // length of data received

uint16 xdata length; // the length of data received

uint8 xdata RXdata[MAX_BUF_SIZE]; // RX data received

uint8 xdata TXData[MAX_BUF_SIZE]; // TX data send

uint16 xdata sentLen; // length of data sent

uint16 xdata TXSize; // size of string sent

Init_iMCU(); // Initialize iMCUW7100

Init_Network(); // Initialize Network Configuration

//Delay for link

wait_1ms(7000);

// 1. create socket for udp

if(socket(0, Sn_MR_UDP,5000, 0) == 1) // create socket with UDP port 5000

{

PutString("\r\n opened socket");

// 2. receive data

while(getSn_RX_RSR(0) == 0) ; // check if there is data in socket

PutString("\r\n got data");

rcvLen = getSn_RX_RSR(0);

if(rcvLen > MAX_BUF_SIZE) // check if data received is bigger than size of buffer string

rcvLen = MAX_BUF_SIZE; // assign max buffer size to the received length

PutString("\r\n RX data size is "); PutITOA(rcvLen); PutString(" Bytes.");

length = recvfrom(0, RXdata, rcvLen, pDestaddr, &pPort); // receive data

PutString("\r\n Received Data");

RXdata[length] = 0; // indicate the end of string

PutString("\r\n RX data : ");

PutString(RXdata); // print received data

// 3. trasnmit data

//set Dest. IP address & Port

pDestaddr[0]= 192;

pDestaddr[1]= 168;

pDestaddr[2]= 1;

pDestaddr[3]= 3;

pPort = 5000;

// Send reply string 'HELLO'

PutString("\r\n TX data size is ");PutITOA(TXSize);

sentLen = sendto(0, TXData, TXSize, pDestaddr, pPort); // transfer data

if (sentLen == TXSize)

PutString("\r\n success to transmit");

else

PutString("\r\n Failed to transmit");

close(0); // close the socket

}

else // if socket is fail

PutString("\r\n Failed to open socket");

while(1);