pigtwo
Member level 4
Hello all,
I'm working on a project where I need to send data from my computer to an FPGA. I'm using a FTDI chip(FT232RL-REEL) to convert USB to RS232. Sending data from my computer to the FPGA works fine but I'm having some problems with sending data from the FPGA through the FTDI chip to the computer. I can send one byte of data easily with no problems as long I don't send it very frequently. If I start sending data quickly it doesn't work and on my computer I get an error that says "A device attached to the system is not functioning.". The code that generated this error is shown below. I have to disconnect and reconnect the USB cable to get it back into an ok state. I'm thinking maybe there is some sort of control packet it or something I need to give the FTDI chip and maybe it just times out if I don't send the next packet soon enough.
Below is my Verilog for sending RS232 packets:
Here is the code that drives that module to send data quickly:
Here is the code that reads the data on the computer. I'm not a very good programmer and I don't almost anything about USB so this is just copied from the documentation:
Does anyone have experience with this and know what might be causing this? Any help or advice is greatly appreciated!
Thank you!
I'm working on a project where I need to send data from my computer to an FPGA. I'm using a FTDI chip(FT232RL-REEL) to convert USB to RS232. Sending data from my computer to the FPGA works fine but I'm having some problems with sending data from the FPGA through the FTDI chip to the computer. I can send one byte of data easily with no problems as long I don't send it very frequently. If I start sending data quickly it doesn't work and on my computer I get an error that says "A device attached to the system is not functioning.". The code that generated this error is shown below. I have to disconnect and reconnect the USB cable to get it back into an ok state. I'm thinking maybe there is some sort of control packet it or something I need to give the FTDI chip and maybe it just times out if I don't send the next packet soon enough.
Below is my Verilog for sending RS232 packets:
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 `timescale 1ns / 1ps `default_nettype none module RS232_SENDER( // Basic signals input wire clock_50, input wire reset, // Data and control signals input wire[7:0] data_in, input wire execute, output reg ready, // RS232 signals output reg rs232_tx ); // Internal registers reg start_counter; reg[7:0] counter; reg[9:0] data_send; // Define sequential logic always @(posedge clock_50) begin if(!reset) begin rs232_tx <= 1; ready <= 0; data_send <= 8'b11111111; counter <= 0; start_counter <= 0; end else begin if(!ready && !start_counter) begin // This should handle the start up/reset condition ready <= 1; end if(ready && execute) begin // Detect execute signal(only when ready is high) ready <= 0; start_counter <= 1; data_send <= {1'b1, data_in, 1'b0}; // Read data and include start and stop bits end else if(counter == 156) begin // All data sent, go back to ready ready <= 1; start_counter <= 0; end if(start_counter) begin counter <= counter + 1; // Count when ready not high end else begin counter <= 0; end // Write out data at approrate times if( counter == 1 || counter == 24 || counter == 40 || counter == 56 || counter == 72 || counter == 88 || counter == 104 || counter == 120 || counter == 136 || counter == 155) begin rs232_tx <= data_send[0]; data_send <= {1'b0, data_send[9:1]}; end else if(counter == 0) begin rs232_tx <= 1'b1; end else begin rs232_tx <= rs232_tx; end end end endmodule
Here is the code that drives that module to send data quickly:
Code Verilog - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 `timescale 1ns / 1ps `default_nettype none module RS232_SENDER_TEST( input wire clock_50, input wire reset, output wire tx, output wire[1:0] testpoint, input wire rx ); // Define internal signals wire ready; reg execute, execute_next; reg[7:0] data_in, data_in_next, state, state_next; reg rx_sync; // Define local params localparam[7:0] start = 0, send = 1, delay = 2, done = 3; assign testpoint[0] = tx; assign testpoint[1] = rx_sync; // Create instance RS232_SENDER TX1( .clock_50(clock_50), .reset(reset), .data_in(data_in), .execute(execute), .ready(ready), .rs232_tx(tx) ); // Define sequential logic always @(posedge clock_50) begin if(!reset) begin execute <= 0; data_in <= 0; rx_sync <= 0; state <= start; end else begin rx_sync <= rx; execute <= execute_next; data_in <= data_in_next; state <= state_next; end end // Define combination logic always@* begin execute_next = execute; data_in_next = data_in; state_next = state; case(state) start: begin execute_next = 0; data_in_next = 0; state_next = send; end send: begin if(ready) begin execute_next = 1; data_in_next = 121; state_next = delay; end end delay: begin if(!ready) begin execute_next = 0; state_next = start; end end done: begin state_next = done; end default: state_next = start; endcase end endmodule
Here is the code that reads the data on the computer. I'm not a very good programmer and I don't almost anything about USB so this is just copied from the documentation:
Code Python - [expand] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 import usb.core import usb.util import time import random # find our device dev = usb.core.find(idVendor=0x0403, idProduct=0x6001) # was it found? if dev is None: raise ValueError('Device not found') # set the active configuration. With no arguments, the first # configuration will be the active one dev.set_configuration() # get an endpoint instance cfg = dev.get_active_configuration() intf = cfg[(0,0)] ep = usb.util.find_descriptor( intf, # match the first OUT endpoint custom_match = \ lambda e: \ usb.util.endpoint_direction(e.bEndpointAddress) == \ usb.util.ENDPOINT_OUT) assert ep is not None #ret = ep.read(1,2) #print(ret) ret = dev.read(0x81,8,1000) print(ret)
Does anyone have experience with this and know what might be causing this? Any help or advice is greatly appreciated!
Thank you!