News:

Let's find out together what makes a PIC Tick!

Main Menu

usart5 not supported on 18f27Q83

Started by Sommi, Apr 22, 2025, 06:42 PM

Previous topic - Next topic

Sommi

Hi!

I tried to get usart 5 running on 18f27Q83 but was informed it is not supported yet. Any workarounds?

Kind regards Sommi
KISS - keep it simple and stupid

Sommi

Instead of using HRSOUT5 should i just declare putchar for usart5 and then send my message?


' Send a character to the USART transmitter
Proc PutChar()
    If PIR1.4 = 0 Then PutChar      ' Wait for transmit register empty
    TXREG = B1                      ' Send character to transmit register
EndProc
KISS - keep it simple and stupid

Sommi

Receive will be done in ISR anyway
KISS - keep it simple and stupid

trastikata

Quote from: Sommi on Apr 22, 2025, 06:42 PMAny workarounds?

I generally prefer to have full control over USART peripheral therefore I set the registers manually, then read and write to the USART using the the buffer registers.

Besides it is easy to set a hardware interrupt for the USART RX which allows the whole process of receiving longer data strings to share CPU cycles with other routines and not get stuck in a loop.

My point, use the USART registers to set-up, read and write.

Sommi

Thanks trastikata

the only thing I use is hrsout, all the other stuff I do manually.

Would this be the way to send single characters?

Proc PutChar5(tx_char)
    while u5errirbits_txmtif = 0 : wend     ' Wait for transmit register empty
    u5txb = tx_char                      ' Send character to transmit register
EndProc

how would a procedure look to send a string like hrsout?
KISS - keep it simple and stupid

trastikata

#5
Quote from: Sommi on Apr 22, 2025, 07:22 PMhow would a procedure look to send a string like hrsout?

Hi Sommi,

This is a basic example what it could look like, however I did not have time to test it in the simulation and I omitted the USART set-up. There should be working examples in the boards too, I think Les posted TX-RX example couple of times.

Device 18F25K20
Declare Xtal = 4

Symbol TXIF = PIR1.4
Symbol TXIE = PIE1.4
Symbol TXEN = TXSTA.5

Dim TxString As String * 64 'TX string
Dim pTxBusy As Bit          'TX busy flag
Dim bTxLength As Byte       'String length to send
Dim bTxCounter As Byte      'TX counter

On_Hardware_Interrupt GoTo Isr
GoTo Main

Isr:
    Context Save
        If TXIF = 1 And TXEN = 1 Then                   'Is it a valid TX Interrupt?
            If bTxCounter = (Bound(TxString) + 1) Then  'Reached end of TX string?
                TXIE = 0 : TXEN = 0                     'Yes, then stop and clear flags
                pTxBusy = 0
            Else                                        'No, then continue       
                If bTxLength = 0 Then                   'Is it actual string length to send
                    If TxString[bTxCounter] <> 0 Then   'Yes, then is it a null character?
                        TXREG = TxString[bTxCounter]    'No, then send it.
                        Inc bTxCounter                  'Increment TX counter
                    Else                                'Yes, then stop and clear flags
                        TXIE = 0 : TXEN = 0               
                        pTxBusy = 0
                    EndIf
                Else                                    'Then we send predetermined number of characters
                    If bTxCounter = bTxLength Then      'Did we send the predetermined number of characters?
                        TXIE = 0 : TXEN = 0             'Yes, then stop and clear flags 
                        pTxBusy = 0
                    Else
                        TXREG = TxString[bTxCounter]    'No, then send it.
                        Inc bTxCounter                  'Increment TX counter
                    EndIf
                EndIf
            EndIf
        EndIf   
    Context Restore

Main:
    If pTxBusy = 0 Then TxUsart("Test",0)
    End

'TxString  = String to send
'bTxLength = if <> 0 then number of characters to send
'            else send actual string length
Proc TxUsart(TxString As TxString, bTxLength As bTxLength)
    If bTxLength = 0 And TxString[0] <> 0 Or bTxLength > 0 Then 'Is there something to send?
        TXREG = TxString[0]                                     'Load first string character to TX buffer
        bTxCounter = 1                                          'Set TX counter
        pTxBusy = 1                                             'Set Tx busy flag
        TXEN = 1 : TXIE = 1                                     'Enable USART TX and TX Interrupt
    Else
        Return                                                  'Do nothing 
    EndIf
EndProc   

Sommi

any news about support of HRSOUT5?
KISS - keep it simple and stupid

top204

I'll see what I can come up with in the next upgrade of the compiler.

However, you can easily create procedures that will perform the same tasks, and you will have more control over them.

Regards
Les