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

#use rs232

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



Joined: 23 Apr 2009
Posts: 42

View user's profile Send private message

#use rs232
PostPosted: Tue Jul 08, 2014 2:37 am     Reply with quote

Hello

Im having troubles with a analog input and RS232

At startup i put

#use rs232(baud=38400,xmit=pin_b5,rcv=pin_a2,stream=EEPROMPORT)
im doing some checks on this port for 5 seconds.

If no reply is done by receiving a service command I continue the program.

But the pin is never going back to input xmit=pin_b5
even if I place a set_tris_b(0xFF) command.

so how can u undo the

#use rs232(baud=38400,xmit=pin_b5,rcv=pin_a2,stream=EEPROMPORT)
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 3:10 am     Reply with quote

#USE RS232, on it's own doesn't do anything to stop the chip.
It is a configuration that is used by the functions getc, and putc.
It should be at the top of your file as a configuration. It is not code to use in the program.

Only getc can hang. Read the manual entry for it:
"This function waits for a character to come in over the RS232 RCV pin and returns the character."
Note 'waits'.....

The sequence should be:
Code:

#include <18F46K22.h> //chip definition
//ADC setup here if used.
//Now the fuses - depend on your device
#FUSES NOWDT,NOBROWNOUT,NOLVP,NOXINST

//Now the clock
#use delay(crystal=20000000)
//Now the RS232 configuration STREAM name if required
#use rs232(baud=38400,parity=N,UART1,bits=8,,errors)
//You must _always_ use ERRORS with a hardware UART, unless
//you generate your own error handling code.

void main(void)
{
   int16 delay_ctr;
   char x;
   //Now your code.
   //If you want to wait for a command, key is that you must _not_
   //call 'getc', unless a character is available

   for (delay_ctr=0;delay_ctr<50000;delay_ctr++)
   {
       if (kbhit())
       {
           //Now there _is_ a character so you can call getc
           x=getc();
           //and do what you want with the character parse the command
           //preferably with a state machine
       }
       else
          delay_us(100));
    }
    //now, the delay must be shorter than the time between
    //characters (260uSec for 38400bps). To avoid characters being missed.
    //If no character is available, the delay gets executed, so the unit
    //pauses for 100*50000uSec

Alternatively, you can set it so getc, won't hang (by adding TIMEOUT=xx to the RS232 declaration). Where 'xx' is a time in mSec to wait for a character. However your code then needs to change to test if the returned character is ==0, and RS232_ERRORS==0, to know that a timeout has occurred.

Do a search in the manual, for 'getc_timeout'.

Understand that if you are using gets, this calls getc.
koenbielen



Joined: 23 Apr 2009
Posts: 42

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 3:29 am     Reply with quote

Hello

Thanks for fast reply but you misunderstood my post

The problem in have is that my pin is set to output with the
#use rs232(baud=38400.... code
But never can be set again as analog input.


This is a analog input connector and is used at startup to go into service mode via serial commands.
So for a short time i check the pin.
If no command is received i continue the program.
So far so good.
Only thing is that when I further in my code specify the pin to be an analog input --> I will stay output.

Kind Regards
Ttelmah



Joined: 11 Mar 2010
Posts: 19546

View user's profile Send private message

PostPosted: Tue Jul 08, 2014 3:59 am     Reply with quote

You need to turn the UART off before the pin can be used for other things.

setup_UART(FALSE);

Tells the compiler to disable the UART.
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