I finally got a USB Serial port for my laptop. I programmed the demo PROM from Xilinx to the FPGA, to see that both serial ports work. Good. Now let's try to do some serial communication. Basically, to send a character on a 9600 bauds line, with no parity, 1 start bit, 1 stop bit, all I have to do is :

  • lower the level (start bit)
  • send the 8 data bits
  • raise the level (stop bit)

With levels changes occuring every 1/9600s. So I wrote the following code :

signal serial_data : std_logic_vector(9 downto 0) 
:= "1010000010";

-- the clock is generated with a counter on the 50Mhz clock
-- by changing serial_clk value every 50 000 000/(9600*2)
process(serial_clk)
begin
if serial_clk'event and serial_clk = '1' then
 led_cnt <= led_cnt + "00000000000001";
 if led_cnt >= "10010101110111" then -- 9600 - 9
   TXD <= serial_data(to_int(led_cnt - "10010101110111")); 
   if led_cnt = "10010110000000" then -- 9600
     led_cnt <= (others => '0');
     led_val <= not led_val;
     L(0) <= led_val;			
   end if;
 else
   TXD <= '1';
 end if;
end if;
end process; -- SERIAL

It is supposed to blink a led and send a 'A' character to the serial port every second. Guess what ? It works :)

(I'm particulary proud of this one, because I managed to have it work without looking to anyone else's code :) Yes, it's a bit stupid, but well...)