Menu

RS232 Receive problem

Help
2023-10-03
2023-10-04
  • Donald Vivian Dold

    Hi
    I have a problem using RS232 in that some of the received character is displayed double. It look like the receive buffer is not cleared after receiving a byte.
    If I disable the receiver and use dummy bytes to display, all is fine, enable the RX port, the problem is there. The TX side is workinf as the radio respond with the right data.

    'Get Radio Frequency

    'Send Command through USART to Radio
    do
    for i = 1 to 5
    HSerSend Get_Freq(i)
    'Short delay for receiver to process message
    Wait 10 ms 'probably not necessary with blocking statement
    Next

    'Get serial Data and save the value in Rad_Display(i)
    for i = 1 to 5
    HSerReceive Rad_Display(i) 'Receive Radio Data from RS232
    wait 10 ms
    next

    The display should be 145.350.00 NFM
    What do I do wrong?

     
  • Anobium

    Anobium - 2023-10-03

    Hi Donald,

    The issue here is the you are checking the receive buffer without checking whether new data has been received.

    There is a missing piece of the puzzle with USART handling in the Help but you can find in the demo extensively. This needs to be sorted.

    If USARTHasData Then
      HSerReceive(InData)
    

    If USARTHasData ( or USARTnHasData where is a number greater than 1 ) will test the interrupt flag. If the USART has data then the IF statement would proceed to read the incoming buffer.

    That said... I would need to see you setup of the USART to see if you have USART_BLOCKING constant defined. This would actually sort of do the same but it would block the program until you have recieved USART data... so, if you want a non-blocking operating you would need #define USART_BLOCKING and the 'if USARTDATA then as shown above.

    Hope this helps.

     
  • Donald Vivian Dold

    Hi Anobium. Tks, I see I have missed that command. Here is my uart setup. I have tried the USART_BLOCKING but without result.

    'USART settings
    #define USART_BAUD_RATE 9600 'Initializes USART port with 9600 baud
    '#define USART_TX_BLOCKING ' wait for tx register to be empty
    #define USART_STOPBITS 2
    #define USART_DATABIT 8
    '#define USART_BLOCKING

    'Set USART transmit pin to output
    Dir PORTC.6 Out

    // Radio commands

     
  • Donald Vivian Dold

    Tks Anobium, that solved the problem. I don't know how I missed it as I was looking for something that would clear the buffers.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.