Search code examples
verilogintel-fpga

Error: object on left-hand side of assignment must have a net type


I am new to working with Verilog, and I was given some code that implements uart. I think it might be missing something since I am getting the compiling error shown below:

Error (10219): Verilog HDL Continuous Assignment error at Uart8Transmitter.v(26): object "idx" on left-hand side of assignment must have a net type

The code is shown below:

module Uart8Transmitter (
    input  wire       clk,   // baud rate
    input  wire       en,
    input  wire       start, // start of transaction
    input  wire [7:0] in,    // data to transmit
    output reg        out,   // tx
    output reg        done,  // end on transaction
    output reg        busy   // transaction is in process
);
    reg [2:0] state  = `RESET;
    reg [7:0] data   = 8'b0; // to store a copy of input data
    reg [2:0] bitIdx = 3'b0; // for 8-bit data
    //reg [2:0] idx;
     //wire idx; //added
     reg [2:0] idx;
     
    assign idx = bitIdx;

    always @(posedge clk) begin
        case (state)
            default     : begin
                state   <= `IDLE;
            end
            `IDLE       : begin
                out     <= 1'b1; // drive line high for idle
                done    <= 1'b0;
                busy    <= 1'b0;
                bitIdx  <= 3'b0;
                data    <= 8'b0;
                if (start & en) begin
                    data    <= in; // save a copy of input data
                    state   <= `START_BIT;
                end
            end
            `START_BIT  : begin
                out     <= 1'b0; // send start bit (low)
                busy    <= 1'b1;
                state   <= `DATA_BITS;
            end
            `DATA_BITS  : begin // Wait 8 clock cycles for data bits to be sent
                out     <= data[idx];
                if (&bitIdx) begin
                    bitIdx  <= 3'b0;
                    state   <= `STOP_BIT;
                end else begin
                    bitIdx  <= bitIdx + 1'b1;
                end
            end
            `STOP_BIT   : begin // Send out Stop bit (high)
                done    <= 1'b1;
                data    <= 8'b0;
                state   <= `IDLE;
            end
        endcase
    end

endmodule

Can anyone help me resolve this?


Solution

  • Verilog assign assigns to wires not to reg's/variables.
    The code uses idx as a variable in other places, therefore it's needed as a variable rather than a wire.

    Model the logic this way:

    //assign idx = bitIdx;
    always @*
      idx = bitIdx;