Search code examples
serializationserial-portpicmicrochipmplab-x-5.50

How often should you send the bits of a serial dataframe so that it is recognised as such by RCREG SFR in MPLABX?


I am attempting to simulate the PIC18F458 receiving a byte (i.e., ASCII 'Z', 0x5A) through the RX pin, using a SCL file (see below) in MPLAB X v.5.05.

testbench for "pic18f458" is
begin
    process is
        begin
            loop
                RX <= '0';
                wait for 104 us;
                RX <= '0';
                wait for 104 us;
                RX <= '1';
                wait for 104 us;
                RX <= '0';
                wait for 1042 us;
                RX <= '1';
                wait for 104 us;
                RX <= '1';
                wait for 104 us;
                RX <= '0';
                wait for 104 us;
                RX <= '1';
                wait for 104 us;
                RX <= '0';
                wait for 104 us;
                RX <= '1';
                wait for 104 us;            
            end loop;
        wait;
    end process;
end testbench;

Although, I can see that the data is being injected onto the pin, I do not see it being captured within the RCREG register. (Please see images of RX pin waveform and RCREG output below).

RX Pin Waveform

RX Pin Waveform output

RCREG SFR

RCREG SFR

The code is written so that the bits are transferred at 9600 bps and assumes that XTAL = 10 MHz (see code below).

        ORG     0000H           ; burn into ROM starting at 0

        MOVLW   B'10010000'     ; load wreg with 0x90
        MOVWF   RCSTA           ; enable receive and serial port itself
        MOVLW   D'15'           ; load wreg 0xF
        MOVWF   SPBRG           ; 9600 bps (Fosc / (64 * S[peed) - 1)
        BSF     TRISC, RX       ; make RX pin of PORTC an input pin
        CLRF    TRISB           ; make PORTB an output port
; get a byte from the serial port and place it on PORTB
R1      BTFSS   PIR1, RCIF      ; check for ready
        BRA     R1              ; stay in loop
        MOVFF   RCREG, PORTB    ; send value to PORTB
        BRA     R1              ; keep doing that

        END

Therefore, I was wondering at what intervals should I send the bits within the SCL file, so that it can be recognised as a dataframe of bits transmitted at 9600 bps.

My current assumption is that each bit of the frame consisting of a start bit, 8-bit data and a stop bit, should be transmitted every 104us.

However, this is not providing the desired effect, in terms of the RCREG registering the data on the RX pin.

Therefore, I would appreciate any insight that anyone can provide with regards to the correct value(s) to use, as this is my first time trying to do this.


Solution

  • The Microchip MPLAB simulation tool is an incomplete representation of the controller functionality. The available models of functional blocks like the UART do not seem to sample the simulated input pin states as described in the data sheet.

    The UART simulation model supports a "register injection" method to change the internal state of the model to receive data on a byte by byte basis.

    You could open a support case with Microchip and ask if your approach is even possible.