PIC 16 UART2 baudrate

Please note that this toolsuite is not part of the official Firewing release but we will try and help where we can...

PIC 16 UART2 baudrate

Postby jamesbarry2 » Thu Mar 16, 2017 9:31 pm

How does one set the baudrate for MIDI, 31250 baud on firewing 16 using UART2?
jamesbarry2
 
Posts: 6
Joined: Wed Mar 15, 2017 8:31 pm

Re: PIC 16 UART2 baudrate

Postby Jerry Messina » Sat Mar 18, 2017 10:42 am

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)
Jerry Messina
 
Posts: 256
Joined: Thu Feb 14, 2013 10:16 am

Re: PIC 16 UART2 baudrate

Postby jamesbarry2 » Sun Mar 19, 2017 11:41 am

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.
jamesbarry2
 
Posts: 6
Joined: Wed Mar 15, 2017 8:31 pm

Re: PIC 16 UART2 baudrate

Postby Jerry Messina » Sun Mar 19, 2017 2:44 pm

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.
Jerry Messina
 
Posts: 256
Joined: Thu Feb 14, 2013 10:16 am

Re: PIC 16 UART2 baudrate

Postby jamesbarry2 » Sun Mar 19, 2017 4:46 pm

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.
jamesbarry2
 
Posts: 6
Joined: Wed Mar 15, 2017 8:31 pm


Return to Microchip 16

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x