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

RS 232 Communication Problem
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
hhuurrkkaann



Joined: 08 Jan 2013
Posts: 14

View user's profile Send private message

RS 232 Communication Problem
PostPosted: Wed Apr 27, 2016 7:18 am     Reply with quote

Hi,
I am trying to receive string data...
I am transmitting "sending-data" string by one pic, and trying to receive data by other pic... But I could not receive all data,,,

I want to get the all string and send it to LCD,,,
I know that "getc" function is only get one letter, but with which function I can get all string data...
Thanks.





Last edited by hhuurrkkaann on Wed Apr 27, 2016 12:48 pm; edited 1 time in total
temtronic



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

View user's profile Send private message

PostPosted: Wed Apr 27, 2016 7:38 am     Reply with quote

Well your 'simulated' hardware is wrong. You do not have correct RS-232. You need to consult the 'MAX232' datasheet, the PIC Compiler manual or other source to see how to wire up proper RS-232 communications.

Until you have correct hardware, there's no point in looking at software issues.

Jay
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Wed Apr 27, 2016 8:48 am     Reply with quote

Hi,

Actually, you don't need a MAX232 IC or 'RS-232' at all, you can directly connect the UART of PIC # 1 to the UART of PIC #2. PIC #1 Tx -> PIC #2 Rx & PIC #2 Tx -> PIC #1 Rx. That should solve your 'hardware' problems.....
_________________
John

If it's worth doing, it's worth doing in real hardware!
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Wed Apr 27, 2016 8:52 am     Reply with quote

It's funny. He obviously realises that the PIC can't send RS232 without buffering, but then expects another PIC to receive RS232 directly.....

There is also the speed problem. The PC can receive data continuously at 9600bps, and display it, but an LCD can't. Especially when each incoming character is replaced with 10 on the display....
hhuurrkkaann



Joined: 08 Jan 2013
Posts: 14

View user's profile Send private message

PostPosted: Wed Apr 27, 2016 1:03 pm     Reply with quote

Smile It is really funny. I am crazy Smile sorry for my foolish mistake...

Forget max 232 Smile

Now the real problem is software.

Problem is:

how to get all the string data like "OIHUFRW23434HKJAS"...

getc(), getchar() functions only get one letter, not all the string...

gets() function gets all the string but wait for enter button... but I want to get all string data directly and display it at lcd...

do you have any idea...

thanks...
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Wed Apr 27, 2016 1:08 pm     Reply with quote

Try the CCS supplied examples

Mike
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Wed Apr 27, 2016 2:01 pm     Reply with quote

Key is a simple understanding.
A 'string' is just a sequence of characters. Nothing more or less. Inside C itself, it has an extra terminating '\0' to mark it's end in memory, but this is not sent. If you simply echo each single character to the display, this is what the terminal program does.
Delay between your strings (a real LCD, will not accept more than a few hundred characters per second), and your problem is solved.
Ideally though to have the text display on separate lines, you'd want to send a line feed after each line of text, and then the gets will work (line feed is the 'enter button').
hhuurrkkaann



Joined: 08 Jan 2013
Posts: 14

View user's profile Send private message

PostPosted: Wed Apr 27, 2016 2:04 pm     Reply with quote

Ttelmah wrote:
Key is a simple understanding.
A 'string' is just a sequence of characters. Nothing more or less. Inside C itself, it has an extra terminating '\0' to mark it's end in memory, but this is not sent. If you simply echo each single character to the display, this is what the terminal program does.
Delay between your strings (a real LCD, will not accept more than a few hundred characters per second), and your problem is solved.
Ideally though to have the text display on separate lines, you'd want to send a line feed after each line of text, and then the gets will work (line feed is the 'enter button').


I got it, thanks. But ı think '\0' is working with "gets" function :S


Last edited by hhuurrkkaann on Thu Apr 28, 2016 7:53 am; edited 1 time in total
hhuurrkkaann



Joined: 08 Jan 2013
Posts: 14

View user's profile Send private message

PostPosted: Thu Apr 28, 2016 7:50 am     Reply with quote

:(

It does not working,,,

As I explained before, I want to get string (like "1234KJHNFCKRWS") and display it on LCD... But string data is not sending via computer so there is no enter button so we can not use "gets" function... I must use getc or getchar function...

but with getc or getchar functions I can not get all the string data...

how can I get this string and display it on LCD...

I am trying about 5 hours but I could not find any solution...




Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Thu Apr 28, 2016 7:57 am     Reply with quote

There is a big problem unless you have something in the data to say 'this is the end of a line'. Otherwise if a character is missed or your count does not align with the transmission, data is always going to go to the wrong place. This is why things like GPS strings have both a line feed, and a '$' marker to say 'new line'.
Just echo the character. Don't add spaces, or count or anything....
Ideally send a line feed so your display knows when to go back to the left:

Code:

   int c;

   while (TRUE)
   {
       if (kbhit())
       {
            c=getc();
            if (c=='\n')
               lcd_gotoxy(0,0); //if a line feed go to the top corner
            else
               lcd_putc(c); //otherwise just display the character
       }
   }


If you want to use INT_RDA (good idea), then use the code in ex_sisr.c, and use bkbhit, and bgetc in your main, instead of kbhit and getc.

Repeat the mantra 50* (and then do it again...). An interrupt should do just what is necessary to handle the hardware even that triggered it _nothing else_.
In your code, your interrupt sends two characters for every one received, so will run out of time.....

Also, since you disable the interrupt, after one character, everything will be lost.

The _HARDWARE_ disables all interrupts in an interrupt handler. Don't fiddle. Study ex_sisr.c
hhuurrkkaann



Joined: 08 Jan 2013
Posts: 14

View user's profile Send private message

PostPosted: Thu Apr 28, 2016 12:12 pm     Reply with quote

@Ttelmah,

I will study ex_sisr.c as you said.
But I am sure that I will need your and other friend's help again,
thanks for your kind and helpful personality....
hhuurrkkaann



Joined: 08 Jan 2013
Posts: 14

View user's profile Send private message

PostPosted: Fri Apr 29, 2016 1:55 am     Reply with quote

I tried your code but as you know your code is only getting one character. Maybe I could not understand you but, but I am always getting only "2W".. (not all the string)

I also tried ex_sisr.c, and get the same result... it also get only "2W"...

I could not understand why it is really hard to get string unless pressing enter button...




temtronic



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

View user's profile Send private message

PostPosted: Fri Apr 29, 2016 5:02 am     Reply with quote

You MUST add 'errors' to the use rs232(...options...) ! Your latest code doesn't have that and that is why you only get 2 characters.This is explained in the 'UART' section of the datasheet as well as the use rs232 section of the CCS manual.
'Errors' adds code that prevents the hardware UART from 'stalling' or 'failing' after 2 characters, which is exactly what you're seeing.
The PIC hardware UART has a 2 character 'buffer'. If you send it data faster than the PIC can handle it will 'overrun' and stop.

Jay
Ttelmah



Joined: 11 Mar 2010
Posts: 19499

View user's profile Send private message

PostPosted: Fri Apr 29, 2016 7:15 am     Reply with quote

The fundamental problem though is that you need to use buffering.

What is happening, is that by the time the two characters have actually been displayed, a couple more characters have already arrived, and hung the UART!....

The LCD is _slow_.

The whole thing is never going to work with characters arriving continuously at 9600bps. If you slow the transmission (put a 0.1second gap between each message), and then use interrupt driven buffering (ex_sisr), then by the time the second message arrives, the LCD has enough time to display the first one.....
ezflyr



Joined: 25 Oct 2010
Posts: 1019
Location: Tewksbury, MA

View user's profile Send private message

PostPosted: Fri Apr 29, 2016 8:29 am     Reply with quote

Ttelmah wrote:
a couple more characters have already arrived, and hung the UART!....


Hmmm, is it actually possible to hang a Proteus (virtual) UART??? Rolling Eyes Laughing
_________________
John

If it's worth doing, it's worth doing in real hardware!
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