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

Asynchronous UART send

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



Joined: 23 Aug 2008
Posts: 24
Location: Italy

View user's profile Send private message Visit poster's website

Asynchronous UART send
PostPosted: Tue Jan 31, 2012 9:27 am     Reply with quote

Hello,
I am writing a program and I'm quite short of processing time; I need to send a byte on the serial port and then do something else, but from what I understand the putc() function waits for the byte to be completely sent. I need to put the byte in the buffer and go ahead with the rest of the code, quite like when I do a "read_adc(ADC_START_ONLY);".
Is it possible? I tried to search around on the forum, but I don't even know what terms to use to search... The CCS manual doesn't help either! :(
Thank you!
gip_mad



Joined: 23 Aug 2008
Posts: 24
Location: Italy

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 31, 2012 9:43 am     Reply with quote

Nevermind, found it on http://www.ccsinfo.com/forum/viewtopic.php?t=47139&highlight=txreg

Code:

...
#byte TXREG=0x19a
...
TXREG=tx[txcount--];
...


Thank you all!
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Tue Jan 31, 2012 10:22 am     Reply with quote

When you use a hardware UART the standard putc() simply stuffs the byte into the TX register and returns to the program, while the UART does its own thing at its own speed.

Putc() only waits for the byte to be sent when using a software UART.
_________________
The search for better is endless. Instead simply find very good and get the job done.
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Tue Jan 31, 2012 10:39 am     Reply with quote

_Or_ if the hardware register is already full.
Stuffing directly to TXREG, without checking that there is space, risks losing data. Putc checks there is space, and if there is, puts it into the register and returns immediately.
If you need to send more than one byte, look at ex_stisr.c, which shows how to implement an interrupt driven serial transmit using a larger software buffer.

Best Wishes
gip_mad



Joined: 23 Aug 2008
Posts: 24
Location: Italy

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 31, 2012 11:15 am     Reply with quote

Wow, thank you very much! That was very fast and helpful.
I think I will still use the TXREG, because I have to receive a byte at 2400bps from a software UART and then forward it to the HW UART at 57600bps, so I'm sure that the HW UART has sent the byte before I receive another one from the slower UART.

Thank you again!!!
Best regards!
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jan 31, 2012 12:43 pm     Reply with quote

Quote:

software UART


there are a number of 18FxxKxx parts that have DUAL hardware UARTS
the 18f25K22 46K22 for example - which coupled with the use of interrupt service routines - could obviate all your timing issues with receiving on one port at low baud for transmit at higher baud on the second channel

just my two cents

Very Happy
temtronic



Joined: 01 Jul 2010
Posts: 9226
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jan 31, 2012 12:49 pm     Reply with quote

I just got some samples of those 18F46K22s today only to find out my Picstartplus programmer doesn't support them,sigh...after almost 20 years uChip has dropped support for my favorite PC peripheral......
gip_mad



Joined: 23 Aug 2008
Posts: 24
Location: Italy

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 31, 2012 2:14 pm     Reply with quote

Yeah, I know about dual UART port PICs, but I'm stuck with a board with a PIC18F2480, and to be honest I have 2 slow SW UARTs to read from and one fast UART to write to.. Plus CAN bus! Shocked Thanks anyway! Very Happy
bkamen



Joined: 07 Jan 2004
Posts: 1615
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Tue Jan 31, 2012 3:58 pm     Reply with quote

asmboy wrote:
Quote:

software UART


there are a number of 18FxxKxx parts that have DUAL hardware UARTS
the 18f25K22 46K22 for example - which coupled with the use of interrupt service routines - could obviate all your timing issues with receiving on one port at low baud for transmit at higher baud on the second channel

just my two cents

Very Happy



The 18fxxJ11's do too -- but those are 3.3V parts. I've used them in several projects in both the 28pin and 44pin flavors.

-Ben
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jan 31, 2012 5:08 pm     Reply with quote

Quote:

stuck with a board with a PIC18F2480


&&
a locked down bunch of pre-existing support circuitry i'm guessing??
OUCH .....

i vowed some time ago to NEVER use a soft UART - ever -( unless it was TRANSMIT only with NO Interrupts enabled ) && have been lucky enough to be able to enforce that decision 100%

ah how i delight in the luxury of redesigning the whole shebazz ( when i can force the project in that way ) to get the entire design as it COULD be instead of limited by what it IS already

Very Happy
gip_mad



Joined: 23 Aug 2008
Posts: 24
Location: Italy

View user's profile Send private message Visit poster's website

PostPosted: Wed Feb 01, 2012 8:25 am     Reply with quote

Well, I'm not "forced"... It's just that I like that PIC A LOT!!! For one main reason: I work on the automotive industry, and there's this AWESOME product that I found http://www.dealextreme.com/p/obdii-bluetooth-car-diagnostic-cable-black-blue-orange-dc-12v-42825 , you can find it anywhere even on EBAY, and it has a PIC18f2480, an MCP2551 CAN transceiver, 12V supply with 5V and 3.3V regulators, 4 LEDs, integrated Bluetooth, a really nice case and an included OBD2 connector, all that for 21$ shipped!!! This thing is so versatile that I use it in almost every one-off project and patches and improvised tools and prototypes, the only downside is that you have to solder in a programming header and lift the MCLR pin. I order 10 of them every time! I swear, it's not an ad! Smile
It comes with the ELM327 firmware out of the box (I even found an unprotected one and I have the hex if anyone's interested) so it's already useful! Smile

About the sw UARTs, yes, I hate them too, but I have clearly in mind what my code will do and I know that it won't be a problem, so while a bit disgusting, I think it will work good. Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19515

View user's profile Send private message

PostPosted: Wed Feb 01, 2012 9:28 am     Reply with quote

Seriously, since you are talking about 'slow' software use, consider not using the standard library. Some time ago, I published some basic code here for doing doing async using a timer interrupt, and in the past have done both TX and RX this way, it avoids the problems of other interrupts affecting the timing (provided their handlers are reasonably quick), and allows other jobs to be going on while the character is transmitted or 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