CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Using software simulated UART

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Javed Shafi



Joined: 15 Mar 2004
Posts: 6

View user's profile Send private message Send e-mail

Using software simulated UART
PostPosted: Thu Dec 01, 2005 9:25 am     Reply with quote

Just a question regarding the use of directive
#use rs232(baud=100, xmit=PIN_C6, rcv=PIN_C7)

I have successfully used this directive before for PIC16LF877 and PIC16LF872 using port C pins 6 and 7. These PICS have inbuild UARTS.

I have inherited a project which uses a PIC16C505 and I note I can still use the #use rs232 even though this device does not have a UART.

Anybody have any experience or issues of using software simulated UARTs that I should be aware of as I never done this before.

Any help on this greatly appreciated.

Best regards

Javed
_________________
Javed Shafi

email: JShafi@aberdeen.oilfield.slb.com
Ttelmah
Guest







PostPosted: Thu Dec 01, 2005 11:20 am     Reply with quote

There are a lot of differences.
The first, is that there is no buffering, so characters wil only be received, if the code is sitting 'waiting' for them to arrive.
The second, is that operation is 'half duplex' at best. You cannot both receive and send at the same time.
The worst one though, is that because all the timings are in software, the processor, can only do the serial transmit/receive, when nothing else is happening. If you have interrupt driven events for anything else, these will interfere with the timings. At low baud rates, it is possible to 'get away' with this, but at higher baud rates, it implies all interrupts must be disabled for the duration of a character being sent/received. I have in the past, posted a way of 'encapsulating' the transmission, so that this is automatically done on a 'per character' basis.

Best Wishes
Javed Shafi



Joined: 15 Mar 2004
Posts: 6

View user's profile Send private message Send e-mail

PostPosted: Thu Dec 01, 2005 11:50 am     Reply with quote

Hi Ttelmah,

Many thanks for your reply.

You mention that

"I have in the past, posted a way of 'encapsulating' the transmission, so that this is automatically done on a 'per character' basis"

Could you tell me where I can find this link for more info.

Best regards

Javed
_________________
Javed Shafi

email: JShafi@aberdeen.oilfield.slb.com
Ttelmah
Guest







PostPosted: Thu Dec 01, 2005 3:29 pm     Reply with quote

I'll repeat it, because it is easy to do.
Basically, assuming you are using 'putc' for output, then write:
Code:

void intoff_putc(int val) {
    disable_interrupts(global);
    putc(val);
    enable_interrupts(global);
}


Then for printf, use:

printf(intoff_putc,"What you want to send");

or for putc itself, use:

intoff_putc('c');

If you remember that individual interrupt flags will still get set when the global interrupts are disabled, you can send a string of text, and the transmission will send a single character, then check interrupts, then send the next character etc..
Provided no interrupt event 'cares' if it's handler is delayed for up to one character time, things still work OK.
For low baud rates like yours, you may well be OK with interrupts running.
You can also generate an interrupt based receive, by connecting the serial receive line an interrupt input (interrupt on the signal going low), then as soon as the handler is called, execute the 'getc' function, and save the data received.

Best Wishes
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group