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 support@ccsinfo.com

RS232 read data from buffer

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



Joined: 07 Nov 2008
Posts: 60

View user's profile Send private message

RS232 read data from buffer
PostPosted: Fri Jan 30, 2009 7:10 am     Reply with quote

Hi, I need help about reading data from serial:

Quote:

#int_RDA
void RDA_isr()
{
char clearing;
int cmd;
int val;
char comando;
char string[10], term[3], *ptr;
output_high(PIN_B7);
>gets(string); using this line and sending 55,61 doesn't work
>strcpy(string,"55,61"); if I use this line it ok reading 55 and 61
strcpy(term,",");
ptr = strtok(string, term);
cmd=ptr;
while(ptr!=0) {
val=ptr;
ptr = strtok(0, term);
}
puts(cmd);
puts(val);
clearing=U1RXREG;
delay_ms(300);
output_low(PIN_B7);
}

Commented line above tested separately, but I cannot have a readable character; could someone help me
Thanks
Regards
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Fri Jan 30, 2009 8:16 am     Reply with quote

Some issues.

Using code tags is good but only if you indent your code in the first place.

strtok returns a pointer to a string.
ptr is defined as a pointer char *ptr; This is OK
cmd and val are ints.
int cmd;
int val;

cmd = ptr; is wrong but seems to work!
The sam ewith val=ptr;

you need to define cmd and val as char *.
char *cmd, *val;

Now for the problem.

gets(string);
Won't work within the interrupt routine!
#int_RDA will interrupt when there is a single character in the input buffer. You read this and store it.

Where are you getting the info from ?
Ttelmah
Guest







PostPosted: Fri Jan 30, 2009 8:19 am     Reply with quote

Understand one thing.
INT_RDA, implies that _one_ character (just one, not a string, not a command etc. etc.,), has been received, and is available to read.
Your RDA handler, wants to receive just this one character, or you might as well not use the interrupt at all, but just sit in the main and receive the string.
Look at ex_sisr, for an example of what the handler should do.

Best Wishes
nicotec



Joined: 07 Nov 2008
Posts: 60

View user's profile Send private message

reading serial
PostPosted: Fri Jan 30, 2009 1:04 pm     Reply with quote

I written a vbcode which send to serial port some command like "55,1" or "4,3" ended with LF and CR.
Now I need to read these command to do high state some pin
I wish to use interrupt because it's important the execution of the command, since normally (using do while(true)) my code read analog input and sending to serial port read value.

In Alternative:
If I use gets() in do-while loop the program stop to work, waiting for data, while I wish to continue if no string available for about 250ms.

I hope You can help me to find a solution.
Thanks and regards.
Ttelmah
Guest







PostPosted: Fri Jan 30, 2009 3:04 pm     Reply with quote

Look at ex_sisr.
All you do, is in your main, as it loops, you check if a character is in the buffer. If it is, read it, and check it against the next expected value in your string. When you reach the last character do what you want at this point.

Best Wishes
nicotec



Joined: 07 Nov 2008
Posts: 60

View user's profile Send private message

PostPosted: Mon Feb 02, 2009 9:05 am     Reply with quote

Hi, I still not solved my problem since if I send a character, I cannot receive it; see below:
sending with HyperTerminal, receiving with c=getc and resending what received but different
send "A" corresponding ƒ
send "B" corresponding †
send "C" corresponding ‡
send "D" corresponding Œ
send "E" corresponding 

Related code is:
Code:
[color=darkred][i][quote]do
{
   set_adc_channel( 9 );
   an_1 = read_adc();
   set_adc_channel( 10 );
   an_2 = read_adc();
   set_adc_channel( 11 );
   an_3 = read_adc();
   output_high(PIN_B6);
   printf("%Lu%c%Lu%c%Lu%c%c",an_1,10,an_2,10,an_3,10,13);
   delay_ms(500);
    c=getc();
    putc(c);
} while(true);   [/quote][/i][/color]
Please note that I'm using PIC24FJ16GA002 and MAX233; Also I don't believe to be an hardware problem because I can send and receive character but not returning the same; it appear a problem with type of character coding.
Can anyone hel me, please.
Thanks and regards
nicotec



Joined: 07 Nov 2008
Posts: 60

View user's profile Send private message

PostPosted: Mon Feb 02, 2009 9:29 am     Reply with quote

sorry, probably I have found matter regarding baud rate too high for pic24 using inosc 8MHz; I will post if confirmed or not, here.
Thanks
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