Page 1 of 1
RS232 not working in software mode
Posted: Mon Apr 02, 2012 4:50 pm
by medelec35
With osc set to 8MHz and baud set to 2400bps (software mode ), then with Hitec compiler baud = 758bps an error of 68%
Unable to set custom to adjust for error as this is not supported with V5.
Is there anything I could try please?
Martin
Re: RS232 not working in software mode
Posted: Mon Apr 02, 2012 4:57 pm
by Benj
Hi Martin,
Sorry to hear this isn't working, I tried very hard to get this code bulletproof but it seems you may have found a hole.
Right the file you are looking for is as follows.
"C:\Program Files\Flowcode\v5\CAL\PIC\PIC_CAL_UART.c"
Near the top of the file you will see the definitions that regulate the software UART baud rate.
What version of HiTech are you using as I tested the HiTech define and it seems to work ok for me. Maybe I didn't take the baud as low as 2400 on the HiTech tests. I do know BoostC was tested a lot more thoroughly.
There should be a constant defined for HiTech which I used for testing. Try editing this constant until the bps error is as low as possible.
Code: Select all
#ifdef _BOOSTC
#define INST_COUNT 45 //65 for lower speeds or 40 for higher speeds.
#endif
#ifdef HI_TECH_C
#define INST_COUNT 315
#endif
Re: RS232 not working in software mode
Posted: Mon Apr 02, 2012 5:04 pm
by Benj
Thinking about it does your HiTech still have optimisations enabled. Could be something to do with this.
Re: RS232 not working in software mode
Posted: Mon Apr 02, 2012 5:14 pm
by medelec35
Benj wrote:Thinking about it does your HiTech still have optimisations enabled. Could be something to do with this.
yes, new pc with new Microchip mplab installed so optimisations is enabled.
I will try your suggestion, and will let you know how it goes.
Hitec version is 9.81
Thanks for a very fast response Ben.
Martin
Re: RS232 not working in software mode
Posted: Mon Apr 02, 2012 6:07 pm
by medelec35
Now sorted. With Hitec version is 9.81 setting for 2400 has to be 672 to give a baud rate of 2400
Can the custom for software baud be re-enabled for V5?
That would be handy especially if there is a variance between Hitec versions.
Thanks again.
Martin
Re: RS232 not working in software mode
Posted: Tue Apr 03, 2012 10:08 am
by Benj
Great glad you got it working Martin,
I will see if I can move these constants back into the C code component files so the values are customisable.
Re: RS232 not working in software mode
Posted: Tue Apr 03, 2012 1:37 pm
by medelec35
Benj wrote:
I will see if I can move these constants back into the C code component files so the values are customisable.
That would be great!
Thanks Ben
Re: RS232 not working in software mode
Posted: Wed Apr 04, 2012 12:26 pm
by medelec35
Hi Ben, I have made the following change to PIC_CAL_UART.c
which allows a software custom setting for RS232.
It does work and appears to be the easiest way I can think of.
Code: Select all
//#ifndef MX_SOFT_BAUD_1
//#error "UART Baud Rate not supported in Software Mode"
//#endif
//#else
#define MX_SOFT_BAUD_1 (((MX_CLK_SPEED / MX_UART_BAUD_1) - 16) / 16)
Do you see any issues with this?
Martin
Re: RS232 not working in software mode
Posted: Wed Apr 04, 2012 4:10 pm
by Benj
Hi Martin,
Ah I see what your doing there, good thinking. Yes that sounds good to me and glad it is working well as its certainly an elegant solution. Maybe a little difficult to explain to a user but I guess most won't be using the HiTech compiler and therefore need the workaround anyway.
Thanks for letting me know.