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

SETUP_UART() vs. #use rs232
Goto page 1, 2  Next
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
object01



Joined: 13 May 2004
Posts: 90
Location: Nashville, TN

View user's profile Send private message Send e-mail Visit poster's website

SETUP_UART() vs. #use rs232
PostPosted: Tue Sep 28, 2004 8:34 am     Reply with quote

Other than being able to switch UART settings at run-time, is there any substantial benefit to managing UARTs with SETUP_UART() vs. a #use rs232 directive? Did the former make the latter obsolete?

--
Jeff S.
Guest








PostPosted: Tue Sep 28, 2004 10:59 am     Reply with quote

#use rs232 means a fully static usage of the UART.
If you know the one-and-only baud rate then use it.
But if you want to implement an auto-baudrate mechanism or you have 2 or more devices connected to PIC with different speed then you have to use setup_uart() (e.g. I have 6 RS485 devices @2400Bd and one @19200Bd)
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 28, 2004 11:35 am     Reply with quote

Quote:
Did the former make the latter obsolete ?

No, it did not. The #use rs232() statement must still be used
to define the UART. (ie., the pins, initial baudrate, etc.)

After that's done, then you can use the setup_uart() function
to turn the UART on/off, or change the baud rate. Note that
this applies to the hardware UART only.
Also, if your PIC has an Enhanced UART, then setup_uart()
is used to control its features. For more info, see the latest
Readme.txt file in this folder: c:\Program Files\Picc

Also see the example file, RS485.C, in this folder:
c:\Program Files\Picc\Drivers
Guest








PostPosted: Tue Sep 28, 2004 4:05 pm     Reply with quote

This is not an answer but actually an extension of the question above. How does one change the Parity setting at runtime? I see how setup_uart could be used to change the baudrate at runtime but what about parity and also stop bits?
Guest








PostPosted: Tue Sep 28, 2004 4:06 pm     Reply with quote

This is not an answer but actually an extension of the question above. How does one change the Parity setting at runtime? I see how setup_uart could be used to change the baudrate at runtime but what about parity and also stop bits?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 28, 2004 5:03 pm     Reply with quote

The Readme.txt file doesn't list parity or stop bits as options for the
setup_uart() function. Here are the parameters that can be used:
This is from the Readme.txt file.

For the Enhanced UART only:
UART_AUTODETECT - Waits for a 0x55 character and sets the UART
baud rate to match.

UART_AUTODETECT_NOWAIT - As above however the function
returns before 0x55 is rcvd. KBHIT() will be true when the match is
made. A call to GETC() will clear the character.

UART_WAKEUP_ON_RDA - The UART will wake the PIC up out of sleep
when RCV goes from high to low.
----------
For all (hardware) UARTs:

UART_ADDRESS - UART only accepts data with 9th bit =1

UART_DATA - UART accepts all data

TRUE - Turn on the UART.

FALSE - Turn off the UART.

[Baud Rate] - Changes to the specified baud rate (9600, 4800, etc.)
and turns on the UART.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Tue Sep 28, 2004 5:31 pm     Reply with quote

You have to handle parity via software and the nineth bit if you want 8 data bits. If you want 2 stop bits, then you can also use the nineth bit (9 bit mode) but lose the parity if you still want 8 data bits.
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Sun Aug 01, 2010 9:31 am     Reply with quote

Hi, is this possible to use UART_AUTODETECT with 18F4520 in modbus.c (ccs library) ?

There only the first byte must be 0x55 and the others stay the same as in modbus structure?

For example:
0x55, address, length, ...., crc
right?

And I've tried it as follow:
Code:

#use rs232(baud=UART_AUTODETECT, UART1, parity=N, stream=MODBUS_SERIAL, ERRORS)

but it could not compile. How can be implemented in the code?
Is enough to add setup_uart(UART_AUTODETECT); after the #use rs232 code?

When I read it with getc() what I'll get? 0x55? or the next byte after 0x55?

Thanks
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Mon Aug 02, 2010 2:58 pm     Reply with quote

any answer?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 02, 2010 3:16 pm     Reply with quote

The reason I didn't answer was because so much of it can be looked up
in the manual or the 18F4520 data sheet. I checked both of them.
Quote:

And I've tried it as follow:

#use rs232(baud=UART_AUTODETECT, UART1, parity=N, stream=MODBUS_SERIAL, ERRORS)

but it could not compile.

The CCS manual doesn't say this allowed, so you can't do it.
That's why it doesn't compile.

Quote:
Is enough to add setup_uart(UART_AUTODETECT); after the #use rs232 code?

You should make a test program and experiment. That's how I would
solve the problem.

Quote:
When I read it with getc() what I'll get? 0x55? or the next byte after 0x55?

The answer is given in the PIC data sheet, in this section:
Quote:

18.1.3 AUTO-BAUD RATE DETECT

You should make a very small test program and attempt to solve the
problem. If you can't solve it, then post the test program and your
compiler version.
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Mon Aug 02, 2010 4:38 pm     Reply with quote

Thanks but how can I know how works in CCS built-in function...
ABDEN bit set by user and automatically cleared. How can I know this without asking, does the setup_uart() set it for every received data or only once...
Will I get the 0x55 value for the first time or not? Maybe CCS ignores and does not give this value when it is first byte.

I just asked that to know if there is someone who has experience in this, otherwise everyone knows everything is possible to be learned by testing. OK I'll test it for all here.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 02, 2010 4:59 pm     Reply with quote

Right, but you can find this information with a test program.
Create simple program like this:
Code:

#include <18F4520.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//======================================
void main(void)
{

setup_uart(UART_AUTODETECT);

while(1);
}


Compile it and look at the ASM code produced by the compiler.
It sets the ABDEN bit. That's mentioned in the 18F4520 data sheet.
Then it tests that bit in loop, and waits for it to become 0. Then it
exits the loop. Then it reads the byte from the UART. This is why I
always say to make a little test program and look at the .LST file.
The answer will be there.
Code:

.................... setup_uart(UART_AUTODETECT);
002C:  BSF    BAUDCON.ABDEN  // Set ABDEN = 1
002E:  BTFSC  BAUDCON.ABDEN  // Wait in loop until ABDEN = 0
0030:  BRA    002E
0032:  MOVF   RCREG,W  // Read byte from UART
.................... 
.................... 
.................... while(1); 
0034:  BRA    0034
.................... }
 

This was compiled with compiler vs. 4.109.
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Tue Aug 03, 2010 6:55 am     Reply with quote

My compiler does not shows the names of registers and bits. v4.108

Code:
002C:  BSF    BAUDCON.ABDEN  // Set ABDEN = 1
002E:  BTFSC  BAUDCON.ABDEN  // Wait in loop until ABDEN = 0
0030:  BRA    002E

What I understand from this code is it waits in infinity-loop. That means I can't write this as initial routine. My uart works with interrupt and how will work this I did not understand really. When I add this code it will wait until a byte has coming. If I could understand correct, this option is not usable. I hope there isn't an example code for this feature in CCS directory.

My compiler gives this:
Code:
....................    setup_uart(UART_AUTODETECT);
007A:  BSF    FB8.0
007C:  BTFSC  FB8.0
007E:  BRA    007C
0080:  MOVF   FAE,W
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Aug 03, 2010 12:37 pm     Reply with quote

Quote:

My compiler does not shows the names of registers and bits. v4.108

It should. I'm using MPLAB. Go into the Project Menu. Select Build
Options. Then find the section for List File format. Select "Symbolic"
format. That will give you the register names in the .LST file.

I searched the CCS directories, and I could not find an example file
for the UART_AUTODETECT feature. I don't think they have one.
FFT



Joined: 07 Jul 2010
Posts: 92

View user's profile Send private message

PostPosted: Tue Aug 03, 2010 12:44 pm     Reply with quote

Thanks for the compiler options, it become better now.

If there are some people who work using this uart option, let inform us.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page 1, 2  Next
Page 1 of 2

 
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