RS232 not working in software mode

Moderator: Benj

Post Reply
medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

RS232 not working in software mode

Post 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
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 not working in software mode

Post 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

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 not working in software mode

Post by Benj »

Thinking about it does your HiTech still have optimisations enabled. Could be something to do with this.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 not working in software mode

Post 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
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 not working in software mode

Post 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
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 not working in software mode

Post 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.

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 not working in software mode

Post 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
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: RS232 not working in software mode

Post 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
Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: RS232 not working in software mode

Post 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.

Post Reply