Solution for serial communication of data between FPGA and single chip microcomputer

Abstract: In view of the weak data processing capability of high-speed data acquisition system composed of FPGA, this paper proposes a solution for serial communication between FPGA and single-chip microcomputer. Full compliance with the RS232 protocol in the communication process, with strong versatility and promotion value.

1 Introduction

Field programmable logic devices (FPGAs) are becoming more and more widely used in high-speed acquisition systems. Because FPGAs have relatively poor processing power for acquired data, it is necessary to send the collected data to other CPU systems to implement data. Processing functions, which make the data communication between the FPGA system and other CPU systems on the agenda, get people's urgent attention. This paper introduces the use of VHDL language to realize the serial communication asynchronous circuit between FPGA and MCU.

The whole design adopts modular design idea and can be divided into four modules: FPGA data transmission module, FPGA baud rate generation control module, FPGA overall interface module and single-chip data receiving module. This article focuses on the implementation of the FPGA data transmission module.

2 FPGA data transmission module design

According to the frame format of RS232 asynchronous serial communication, the format of each frame used in the FPGA transmitting module is: 1 bit start bit + 8 bit data bit +1 bit odd parity bit +1 bit stop bit, baud rate 2400. The system is designed to package a 16-bit data into two frames of high-order frame and low-order frame for transmission, first send low-order frame, then send high-order frame, when transmitting data, plus file header and data length, file header 555555 to indicate that only when the MCU receives 555555, it will receive the data length and data bits transmitted below, and check the odd parity bit. The data will be stored and processed correctly. The data length can be as needed. Change arbitrarily. The frequency division coefficient can be calculated from the set baud rate. The specific algorithm is the frequency division coefficient X=CLK/(BOUND*2). The desired baud rate can be calculated from this equation. Below is the VHDL source program that implements the above functions.

Library ieee;

Use ieee.std_logic_1164.all;

Use ieee.std_logic_arith.all;

Use ieee.std_logic_unsigned.all;

enTIty atel2_bin is

Port( txclk: in std_logic; --2400Hz baud rate clock

Reset: in std_logic; -- reset signal

Din: in std_logic_vector(15 downto 0); --Data sent

Start: in std_logic; --Allows the transmission of signals

Sout: out std_logic -- serial output port

);

End atel2_bin;

Architecture behav of atel2_bin is

Signal thr,len: std_logic_vector(15 downto 0);

Signal txcnt_r: std_logic_vector(2 downto 0);

Signal sout1: std_logic;

Signal cou: integer:=0;

Signal oddb:std_logic;

Type s is(start1, start2, shift1, shift2, odd1, odd2, stop1, stop2);

Signal state:s:=start1;

Begin

Process(txclk)

Begin

If rising_edge(txclk) then

If cou<3 then thr<="0000000001010101"; -- sent header

Elsif cou=3 then

Thr<<00000000000000000010"; -- length of file sent

Elsif (cou>3 and state=stop2) then thr<=din;--sent data

End if;

End if;

End process;

Process(reset,txclk)

Variable tsr, tsr1, oddb1, oddb2: std_logic_vector(7 downto 0);

Begin

If reset='1' then

Txcnt_r<=(others=>'0');

Sout1<='1';

State<=start1;

Cou<=0;

Elsif txclk'event and txclk='1' then

Case state is

When start1=>

If start='1' then

If cou=3 then

Len<=thr;

End if;

Tsr:=thr(7 downto 0);

Oddb1:=thr(7 downto 0);

Sout1<='0'; --start bit

Txcnt_r<=(others=>'0');

State<=shift1;

Else full text view

State<=start1;

End if;

When shift1=>

Oddb<=oddb1(7) xor oddb1(6) xor oddb1(5) xor oddb1(4) xor oddb1(3) xor oddb1(2) xor oddb1(1) xor oddb1(0);

Sout1<=tsr(0); --data bit

Tsr(6 downto 0):=tsr(7 downto 1);

Tsr(7):='0';

Txcnt_r<=txcnt_r+1;

If (txcnt_r=7) then

State<=odd1;cou<=cou+1;

End if;

When odd1=> -- odd parity bit

If oddb='1' then

Sout1<='0';state<=stop1;

Else

Sout1<='1';state<=stop1;

End if;

When stop1=>

Sout1<='1'; -- stop bit

If cou<4 then

State<=start1;

Else

State<=start2;

End if;

When start2=>

Tsr1:=thr(15 downto 8);

Oddb2:=thr(15 downto 8);

Sout1<='0'; --start bit

Txcnt_r<=(others=>'0');

State<=shift2;

When shift2=>

Oddb<=oddb2(7) xor oddb2(6) xor oddb2(5) xor oddb2(4) xor oddb2(3) xor oddb2(2) xor oddb2(1) xor oddb2(0);

Sout1<=tsr1(0);--data bit

Tsr1(6 downto 0):=tsr1(7 downto 1);

Tsr1(7):='0';

Txcnt_r<=txcnt_r+1;

If (txcnt_r=7) then

State<=odd2;

End if; full view

When odd2=> -- odd parity bit

Power Meter Backlit

WARNING!

Do not plug two or more meters together!

IMPORTANT

Don't plug in an appliance where the load exceeds 16 Amp. Always ensure the plug of any appliance is fully inserted into the meter outlet. If cleaning of the meter is required, remove from mains power and wipe meter with a dry cloth.

KEYBOARD DEFINITION

1). SET: Set price with button UP.

2). MODE: Exchange display state.

3). UP: Set price combined with button SET.

GENERAL FEATURES

1).Display line power.

2).Display and memory accumulative total power quantity.

3).Display and memory total power charge of price.

THE DATA DISPLAY

Press MODE button the data displays as follows:

W →KWh →PRICE →COST/KWH

↑_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _↓

1). Plug in socket and power on, the meter will display real power.

2). Press MODE button once again and release, the meter will display accumulative KWh.

3). Press MODE button once again and release, the meter will display total power charge.

4). Press MODE button once again and release, the meter will display COST/KWH.

SETTING PRICE OF COST/KWH

1). Press SET button during display COST/KWH,the first digital COST/KWH flash, press UP button to set it.

2). Press SET button once again and release, the second digital COST/KWH flash, press UP button to set it.

3). Press SET button once again and release, the third COST/KWH flash, press UP button to set it.

4). Press SET button once again and release, the fourth COST/KWH flash, press UP button to set it.

5). Press SET button once again and release, the radix point COST/KWH flash, press UP button to set it.

DATA CLEAR

Press and hold MODE button for 5 seconds will clear KWH,PRICE and COST/KWH data.

Power Backlit, Backlit socket, power meter Backlit, energy meter Backlit, backlit adaptor, backlit plug socket

NINGBO COWELL ELECTRONICS & TECHNOLOGY CO., LTD , https://www.cowellsocket.com