Menu

USART - adding USART 3, 4 and 5 for PIC & a major update to the library

Anobium
2022-10-14
2022-10-14
  • Anobium

    Anobium - 2022-10-14

    in build 1176 or greater there is support for PIC usart3,4 and 5 for PIC.

    Bill and I have also taken the opportunity to improve the library as follows:

    • revised send routines by Bill Roth
    • revised receive routines by Evan Venn
    • rationalisation of Usart selection using Case-Select
    • change/added comments to use //~ to remove redundant comments from ASM
    • Rationalisation of initusart to minimise ASM generated
    • Improved USART usage to create STRICT use of baud rates to ensure specific USART capability exists
    • Improved initusart for K40 type uC
    • Added RAISECOMPILERERROR where appropiate
    • Improved handling of variable comport and Defaultusartreturnvalue variable to only set when more than one USART to minimise ASM generated

    USART constants

    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_BLOCKING          'waits for byte to be received and transmitted
    #DEFINE USART_TX_BLOCKING       'waits for empty Tx input buffer/register so the previous activity has been completed.
    #DEFINE USART2_BAUD_RATE 9600
    #DEFINE USART2_BLOCKING         'Usart 2 waits for byte to be received
    #DEFINE USART2_TX_BLOCKING      'Usart 2 waits for empty Tx input buffer/register so the previous activity has been completed.
    #DEFINE USART3_BAUD_RATE 9600
    #DEFINE USART3_BLOCKING         'Usart 3 waits for byte to be received
    #DEFINE USART3_TX_BLOCKING      'Usart 3 waits for empty Tx input buffer/register so the previous activity has been completed.
    #DEFINE USART4_BAUD_RATE 9600
    #DEFINE USART4_BLOCKING         'Usart 4 waits for byte to be received
    #DEFINE USART4_TX_BLOCKING      'Usart 4 waits for empty Tx input buffer/register so the previous activity has been completed.
    #DEFINE USART5_BAUD_RATE 9600
    #DEFINE USART5_BLOCKING         'Usart 5 waits for byte to be received
    #DEFINE USART5_TX_BLOCKING      'Usart 5 waits for empty Tx input buffer/register so the previous activity has been completed.
    
    #DEFINE DEFAULTUSARTRETURNVALUE 'The byte value returned from USART receive when USARTx_BLOCKING is NOT used.
    
    #DEFINE SerPrintCR  'prints a CR at the end of every print Sub
    #DEFINE SerPrintLF  'prints a LF at the end of every print Sub
    

    Remember also to set the appropriate Comport Pins for direction In and Out - the may be implied by the uC default condition but good practice is to set the DIR for the USART port.pin

    Note that the HSerReceive routine is implemented differently. In this library, it is a subroutine, as with SerReceive in rs232.h. This is purely a design decision, and has been made to keep included routines consistent with each other.

    To show USART1 (only USART1) calculations in terms of actual BPS and % error. Use the following constants to control the checking and warning messages

    #DEFINE CHECK_USART_BAUD_RATE                   'Show baud rate errors above 2% during compiling 
    #DEFINE ISSUE_CHECK_USART_BAUD_RATE_WARNING     'Show actual baud rate during compiling
    

    Enjoy

     

    Last edit: Anobium 2022-10-14

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.