News:

;) This forum is the property of Proton software developers

Main Menu

What I missing about serial declares?

Started by Maxi, Aug 03, 2022, 07:34 AM

Previous topic - Next topic

Maxi

'---------------------------------------------------
'8mhz, 57600
Declare Hserial2_Baud=57600
Declare Hserial2_RCSTA=$90
Declare Hserial2_TXSTA=$24
Declare Hserial2_SPBRG=34
Declare Hserial2_Clear=On
SPBRGH2 = 0
BAUDCON2.3 = 1
'---------------------------------------------------

hi everybody
I use this serial config (pic18F25K22) last many years.

but now, its not work with "nextion basic series"
working with others! (nextion enhanged, intelligent etc)

if I compile it old proton 3.7.5.5 working well with basic series too!

note:
sending pic to lcd data working good.
(I can send data to lcd)

received lcds data don`t
(I don`t received data from lcd)


top204

#1
You cannot mix the HSerial2_Baud and the RCSTA and TXSTA declares, and the setting up of USART2 manually with SFRs. The compiler takes care of all that for you when you simply place the Declare HSerial2_Baud. Mixing them will overwrite what the compiler has set up. You will notice that the RCSTA and TXSTA declares are no longer in the compiler's manual, because not all devices have those SFRs, and that would confuse users with those types of devices. The compiler now takes care of everything for the user, regardless of the device type.

Just use something like:

'
'   /\\\\\\\\\
'  /\\\///////\\\
'  \/\\\     \/\\\                                                 /\\\          /\\\
'   \/\\\\\\\\\\\/        /\\\\\     /\\\\\\\\\\     /\\\\\\\\   /\\\\\\\\\\\  /\\\\\\\\\\\  /\\\\\\\\\
'    \/\\\//////\\\      /\\\///\\\  \/\\\//////    /\\\/////\\\ \////\\\////  \////\\\////  \////////\\\
'     \/\\\    \//\\\    /\\\  \//\\\ \/\\\\\\\\\\  /\\\\\\\\\\\     \/\\\         \/\\\        /\\\\\\\\\\
'      \/\\\     \//\\\  \//\\\  /\\\  \////////\\\ \//\\///////      \/\\\ /\\     \/\\\ /\\   /\\\/////\\\
'       \/\\\      \//\\\  \///\\\\\/    /\\\\\\\\\\  \//\\\\\\\\\\    \//\\\\\      \//\\\\\   \//\\\\\\\\/\\
'        \///        \///     \/////     \//////////    \//////////      \/////        \/////     \////////\//
'                                  Let's find out together what makes a PIC Tick!
'
' Test the compiler setting the Baud rate for USART2
' Written for the Positron BASIC compiler by Les Johnson
'
    Device = 18F25K22                   ' Tell the compiler what device to compile for
    Declare Xtal = 8                    ' Tell the compiler what frequency the device is operating at (in MHz)
'
' Setup USART2
'
    Declare Hserial2_Baud = 57600       ' Setup the Baud rate of USART2
    Declare HRSOut2_Pin   = PORTB.6     ' Tell the compiler what pin is used for USART2 TX
    Declare HRSIn2_Pin    = PORTB.7     ' Tell the compiler what pin is used for USART2 RX
'
' Create a variable for the test
'
    Dim wCounter As Word
   
'------------------------------------------------------------------
' The main program starts here
'
Main:    
    Do
        HRSOut2Ln "wCounter is ", Dec wCounter
        Inc wCounter
        DelayMS 100
    Loop

And within the assembler code, the compiler will setup the USART chosen with the best Baud rate it can for the frequency the device is operating at, and the type of Baud rate generator the device contains, before the user's program starts. As shown below for the program listing above:

; UART2_ACTUALBAUD = 55555.55
; UART2_BAUDERROR = 03.55
    bsf BAUD2CON,PP_BRG16
    movlw 0x08
    movwf SP2BRG
    clrf SP2BRGH
    movlw 0x20
    movwf TX2STA
    movlw 0x90
    movwf RC2STA

If the SFRs for a USART need changing manually, do not use the declares in the program, unless using a device with PPS (Peripheral Pin Select). Then the TX and RX pin declares setup the PPS peripherals for the pins chosen.

Also make sure you are running the latest compiler update from here: Positron Corrections Update 4.0.2.1 - 1.1.0.9

Below is a screenshot of the above program listing operating in a simulator:
USART2 tester.jpg