PDA

View Full Version : [SOLVED !] Serial communications questions...



new_user
9th August 2005, 15:26
I have a couple of questions regarding serial communications with your compiler.

Is it possible to support serial comm settings other then 7E1 and 8N1? For example odd or mark parity and also parity (E, O or M) on 8 data bits?

I need the ability to alter these settings at run time so hard coding the changes won't work for my application.

Thanks!

Mohammed Tayem
9th August 2005, 16:41
You can do it using SERIN/SEROUT, have a look at these commands in the manual or help file.

Regards
Mohammed

new_user
9th August 2005, 18:11
Thanks, I have read the manual though and I am still not sure if this can be done, hence the question.

The run time Baudmode parameter of SERIN/SEROUT can only handle 7E1 or 8N1 per the manual.

There looks to be DECLARE statements to change this but based on how the manual describes 'DECLARE' to be used to "adjust certain aspects of the produced code" it appears DECLARE is a compile time statement. That doesn't work for me, I need to be able to switch these sorts of things at run time based on user input. Or am I mistaken and that DECLARE can be used at run time (in IFs and such) to adjust these parameters on the fly?

Thanks!

Mohammed Tayem
10th August 2005, 09:05
You are right, the Declare statements used by the compiler at compilation time, and canít be used in runtime. You know that PIC USART donít support parity by hardware, and any implementation for it should be by software.

SERIN/SEOUT is a software implementation for serial communication, supports parity for 7 and 8 data bits, but not all modes can be configured on the fly.

As you said , 7E1 or 8N1 can be set on runtime, if you are interested on Odd parity you can Declare it for Odd parity and then 7O1 and 8N1 can be set on runtime.

If the other connected system has a full serial configuration options, let it cope with your system ( PC can), if not and you are forced to introduce all possible serial configurations, then you should use the USART, by accessing its registers and implement your own software parity support.

Hope it helps

Regards
Mohammed

new_user
10th August 2005, 13:59
"You know that PIC USART dont support parity by hardware, and any implementation for it should be by software."

I haven't looked into that very much but I thought it supported 9 bit of transmission (8 data bits plus a parity bit), just that it wouldn't calculate parity automatically. The software has to calculate parity but then the hardware could send it.

"if you are interested on Odd parity you can Declare it for Odd parity and then 7O1 and 8N1 can be set on runtime"

That doesn't work, I need more flexibility then that at run time.

"If the other connected system has a full serial configuration options, let it cope with your system ( PC can),"

This would be connecting to various pieces of equipment that has its serial configurations fixed, that is why the software would need to be configurable to work with the various equipment.

"then you should use the USART, by accessing its registers and implement your own software parity support."

Can you do that through Basic or do you have to drop down to assembler to do that? If I change the USART registers will Basic just go and change them back when I make a SERIN/SEROUT call to match however they are configured?

Thanks!