Menu

Error in HserSend: usart.h (0.9 12/8/2009)

Santiago
2009-08-16
2013-05-30
  • Santiago

    Santiago - 2009-08-16

    Now is:

    sub HSerSend(In SerData)

        #ifdef PIC

            #ifdef USART_BLOCKING

                Wait While TXIF = On '...................HERE
            #endif

            TXREG = SerData

        #endif

    it should be:

    sub HSerSend(In SerData)

        #ifdef PIC

            #ifdef USART_BLOCKING

                Wait While TXIF = Off

            #endif

            TXREG = SerData

        #endif

    And... Just an optimisation in InitUsart. This save two unneeded banksels:

    Sub InitUSART

        #ifdef PIC

            'Set baud rate

            SPBRG = SPBRGL_TEMP

            #ifdef Bit(BRG16)

                SPBRGH = SPBRGH_TEMP

                BRG16 = BRG16_TEMP

            #endif

            BRGH = BRGH_TEMP

           

            'Enable async mode

            Set SYNC Off

            'Enable TX and RX
            Set TXEN On

            Set CREN On

            'Enable Serial Port

            Set SPEN On

        #endif

    Just first set all bits in bank1 registers , then the bank0 ones.

     
    • Santiago

      Santiago - 2009-08-18

      There is also a problem at high baudrates, because the SPBRG calculation takes just the integer part of the result, and it should be rounded to +1 when the decimal > 0.5.

      For example at 115200 teoretical SPBRG should be 9.85, but 9 is parsed, then it does not work, but with SPBRG=10 it works ok. For lower speeds the error is small enought to not create problems.

      This works for me (usart.h):

      SPBRG_TEMP = ChipMHz / USART_BAUD_RATE / 16 * 1000000
      if int(SPBRG_TEMP + 0.5) = int(SPBRG_TEMP) then SPBRG_TEMP -= 1

       

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.