fpga4fun.comwhere FPGAs are fun

Serial interface 5 - How to use the RS-232 transmitter and receiver

This design allows controlling a few FPGA pins from your PC (through your PC's serial port).

  1. It create 8 outputs on the FPGA (port named "GPout"). GPout is updated by any character that the FPGA receives.
  2. Also 8 inputs on the FPGA (port named "GPin"). GPin is transmitted every time the FPGA receives a character.

The GP outputs can be used to control anything remotely from your PC, might be LEDs or a coffee machine...

module serialGPIO(
    input clk,
    input RxD,
    output TxD,

    output reg [7:0] GPout,  // general purpose outputs
    input [7:0] GPin  // general purpose inputs

wire RxD_data_ready;
wire [7:0] RxD_data;
async_receiver RX(.clk(clk), .RxD(RxD), .RxD_data_ready(RxD_data_ready), .RxD_data(RxD_data));
always @(posedge clk) if(RxD_data_ready) GPout <= RxD_data;

async_transmitter TX(.clk(clk), .TxD(TxD), .TxD_start(RxD_data_ready), .TxD_data(GPin));

Remember to grab the async_receiver and async_transmitter modules here, and to update the clock frequency values inside.

That's all folks!