usart SetBaudrate issue

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Jerry Messina
Swordfish Developer
Posts: 1469
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

usart SetBaudrate issue

Post by Jerry Messina » Mon Feb 09, 2009 9:58 am

There appears to be a problem with the usart baud rate routine when using
the 16-bit BRG. The module assumes that the SPBRG/SPBRGH registers
are adjacent in the memory map, and there are a number of devices where
this isn't the case (such as the 18F6680 which I just tried!)

For me, changing the code from

Code: Select all

Public Sub SetBaudrate(pSPBRG As SPBRGRegister = br19200)
   RCStatus = $90         // serial port enable, continuous receive
to

Code: Select all

public sub SetBaudrate(pSPBRG as word = br19200)
    SPBRG = pSPBRG.byte0
    SPBRGH = pSPBRG.byte1
    RCStatus = $90         // serial port enable, continuous receive
cleared things up.

Jerry

User avatar
madinventions
Posts: 11
Joined: Tue Jan 06, 2009 9:13 pm
Location: Suffolk, England

Post by madinventions » Tue Mar 17, 2009 12:46 pm

The same is true for the 18F8722... this code fixed it though.

Thanks Jerry.

:? :arrow: :x :arrow: :cry: :arrow: :D

User avatar
RadioT
Registered User
Registered User
Posts: 157
Joined: Tue Nov 27, 2007 12:50 pm
Location: Winnipeg, Canada

Post by RadioT » Sun Nov 17, 2013 2:46 am

Four years after this post....I just found the same thing on the 18F87J11.

I had been setting SPBRGH1 and SPBRG1 separately, and just lately tried using the SetBaudrate in the USART1 module. It wouldn't work until I tried Jerry's fix.


-Tom

Post Reply