News:

PROTON pic BASIC Compilers for PIC, PIC24, dsPIC33

Main Menu

Buffered USART with the 18F27K series

Started by JohnB, Jul 03, 2022, 11:04 AM

Previous topic - Next topic

JohnB

I cannot get the buffered serial to return data correctly. 

I am using the USART1_Buffer_K42.inc from Les together with the Positron Int Manager.inc.
I have amended the USART1_Buffer_K42 to USART2 but otherwise it is identical to the original.
Below is the interrupt handler.  (I have added an echo to USART1 so I can see whet is being placed in the buffer.

    If USART2_RX_Flag() = True Then                     ' Was it a USART1 byte receive that triggered the interrupt?
        USART2_bRXByte = U2RXB                          ' Yes. So place the byte received into USART2_bRXByte
        U1TXB = USART2_bRXByte                          ' Echo the byte to USART1 TX
        Inc USART2_bIndexIn                             ' Move up the buffer
        If USART2_bIndexIn >= _cUSART2_BufferSize Then  ' End of buffer reached?
            USART2_bIndexIn = 0                         ' Yes. So reset USART2_bIndexIn
        EndIf
        USART2_wFSR1 = AddressOf(USART2_bRingBuffer)    ' Point FSR1L\H to USART1_bRingBuffer
        USART2_wFSR1 = USART2_wFSR1 + USART2_bIndexIn   ' Add the buffer position to FSR1L\H
        INDF1 = USART2_bRXByte                          ' Place the received byte into the buffer
        Global_tByteInBuffer2 = True                    ' Indicate that there is a byte in the buffer
    EndIf

I can see on USART1 that the data being echoed back is correct but when I try and read it back out I just get $CC.
This is the result from USART1
AA AA AA 03 0C 39 00 FF FF FF CC
So the message has gone in to the buffer and only CC has come out

I have included  my project files in the hope that others might see where I am going wrong...

JohnB

Pepe

You have modified the library like this

JohnB

@Pepe  - Thank you that did it.  I had been staring at for ages but still didn't spot it.
Its now more or less working as I expected.  Its just down to my processing of the message now.
JohnB