USART and SUART query or two

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

USART and SUART query or two

Post by Francis » Thu Jul 12, 2007 11:14 am

I need to use USART and SUART in the same prog. and am a little confused about setting the baudrate and library name/prefix type thing.

I read the recent thread very relevant to my question, but it's left me scratching my head.

I, too, have:

Code: Select all

' Include Libraries:-
Include "suart.bas"
Include "usart.bas"
then in my initialise routine I had originally:

Code: Select all

    USART.SetBaudrate(br2400)                    ' Set hardware USART baud
    suart.SetBaudrate(sbr9600)                   ' Set software SUART baud
    suart.SetTX(PORTA.2)
which fails to compile.
I read the other thread and it suggests:

Code: Select all

    USART.SetBaudrate(br2400)                    ' Set hardware USART baud
    UART.SetBaudrate(sbr9600)                   ' Set software SUART baud
    UART.SetTX(PORTA.2)
Query No.1
If I include Suart.bas, how come it doesn't like the SUART. prefix in my command?
I thought it was good practise (mandatory?) to use the lib name as a prefix to prevent ambiguity etc?
How come 'UART' refers to the SUART library?
Have I misread the 'Help'? Where has the S gone?

Query No.2 which is a by-the-way.
I haven't tried running it yet, but was just wondering if 9600 on Suart was likely to be safe on an 18F2520 @ 8MHz? Or should I slow it down/use faster crystal.

Ta.

User avatar
David Barker
Swordfish Developer
Posts: 1214
Joined: Tue Oct 03, 2006 7:01 pm
Location: Saltburn by the Sea, UK
Contact:

Post by David Barker » Thu Jul 12, 2007 11:36 am

It's a typo in the help file

Code: Select all

    suart.SetBaudrate(sbr9600)                   ' Set software SUART baud
    suart.SetTX(PORTA.2)
should be

Code: Select all

    uart.SetBaudrate(sbr9600)                   ' Set software SUART baud
    uart.SetTX(PORTA.2)
If you click on the 'suart.bas' file link in the explorer window, you will see the correct module name. Sorry about that.

> I haven't tried running it yet, but was just wondering if
> 9600 on Suart was likely to be safe on an 18F2520 @ 8MHz
You should be OK, best thing to do is try it out - I would personally feel more comfortable with a lower baudrate at 8MHz. With software serial comms its useful to have a fast xtal or slow baudrate.

Francis
Registered User
Registered User
Posts: 314
Joined: Sun Mar 25, 2007 9:40 am
Location: Devon

Post by Francis » Thu Jul 12, 2007 1:42 pm

Thanks David,

I thought I was going to have to send my spectacles back to Ebay.

Cheers,

Francis.

Post Reply