Page 1 of 1

PIC 16 UART2 baudrate

PostPosted: Thu Mar 16, 2017 9:31 pm
by jamesbarry2
How does one set the baudrate for MIDI, 31250 baud on firewing 16 using UART2?

Re: PIC 16 UART2 baudrate

PostPosted: Sat Mar 18, 2017 10:42 am
by Jerry Messina
The easiest way is to add a new baudrate value to the list of enums in uart2.bas
Code: Select all
   Is31250 = ((_clock * 1000000 / 2) / _multiplier / 31250) - 1


Edit the file Library\MCU16\UART\uart2.bas
Add the above line so that the enum Baudrate declaration looks like:
Code: Select all
' baudrate enumerations...
public enum Baudrate as ushort
   Is300 = ((_clock * 1000000 / 2) / _multiplier / 300) - 1
   Is600 = ((_clock * 1000000 / 2) / _multiplier / 600) - 1
   Is1200 = ((_clock * 1000000 / 2) / _multiplier / 1200) - 1
   Is2400 = ((_clock * 1000000 / 2) / _multiplier / 2400) - 1
   Is4800 = ((_clock * 1000000 / 2) / _multiplier / 4800) - 1
   Is9600 = ((_clock * 1000000 / 2) / _multiplier / 9600) - 1
   Is19200 = ((_clock * 1000000 / 2) / _multiplier / 19200) - 1
   Is31250 = ((_clock * 1000000 / 2) / _multiplier / 31250) - 1
   Is38400 = ((_clock * 1000000 / 2) / _multiplier / 38400) - 1
   Is57600 = ((_clock * 1000000 / 2) / _multiplier / 57600) - 1
   Is115200 = ((_clock * 1000000 / 2) / _multiplier / 115200) - 1
end enum


You can then use Uart2.SetBaudrate(Baudrate.Is31250)

Re: PIC 16 UART2 baudrate

PostPosted: Sun Mar 19, 2017 11:41 am
by jamesbarry2
Thanks for that Jerry, I didn't realize one could edit these files, as they were said to be read only. I took that to mean they were pre-compiled.

Re: PIC 16 UART2 baudrate

PostPosted: Sun Mar 19, 2017 2:44 pm
by Jerry Messina
That's one of the nice features... all libraries are in source code. The IDE calls them "read-only" only so that you don't change them by accident.

If you want you can leave the original file in place, copy it to your "UserLibrary" folder and edit the copy. That way the original will always be there and your changes should be intact if the library code changes.

Re: PIC 16 UART2 baudrate

PostPosted: Sun Mar 19, 2017 4:46 pm
by jamesbarry2
Thanks again Jerry, sounds good to me.... I've only used 8-bit PICs to date, using Proton basic, & although Proton will generate 16-bit code & drive the Firewing loader O/k, I'm now jumping in the deep end with Firewing 16-bit, to drive a MIDI shield I've made.