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

Voltage level/ serial communications general Q
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
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

Voltage level/ serial communications general Q
PostPosted: Sun Dec 07, 2008 2:42 pm     Reply with quote

Hi-
I am trying to get a PIC to communicate serially with another controller.
The other controller has "serial communication" which has an RX, TX +5 and GND and uses a USB connector to interface with the PC.
My PIC is a 5V PIC and I have wired +5 to+5, GND to GND, TX to RX and RX to TX.

In my code I'm using the #use RS232 statement for C6 and C7 which correspond to the PIC 18F452. Is this the right thing to do?

I'm confused about the difference between RS232 and plain ol' serial.
Also is plain serial the same as USB?
And any other questions I didn't ask, but should have.

Thanks in advance,
N_N
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 07, 2008 2:48 pm     Reply with quote

Quote:
I am trying to get a PIC to communicate serially with another controller.

Post the manufacturer and part number of the controller.
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

PostPosted: Sun Dec 07, 2008 4:04 pm     Reply with quote

If I send this code, am I sending a character out on the TX line?
Thanks in advance!
N_N

Code:
#include <18F452.H>
#fuses HS,NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP   
#use delay(clock=20000000)                           
#use RS232 (baud = 9600, xmit= PIN_C6, rcv = PIN_C7)
#use standard_io(c)
//*****************************************************************
   char U;
   int cnt;
void main()
{
   cnt = 0;
   delay_ms(5000);
   while (1){
   printf("U"); // send msg OUT ON TX LINE?
      }
         }
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 07, 2008 4:13 pm     Reply with quote

Yes. You're sending out the "U" character continuously.
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

PostPosted: Sun Dec 07, 2008 4:57 pm     Reply with quote

Thank you!
BTW it is an OLED 32028-P1T from 4D Systems.
-N_N
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 07, 2008 5:24 pm     Reply with quote

I notice you're on their forum. You should ask them about the interface
specs. They don't state what they are in their data sheets. Someone
on their forum must know. I.e., what is the baud rate ? What is the
number of bits, and is parity used, etc. ? Are the serial signals non-
inverted ? That's what you need to know.
http://www.websitetoolbox.com/tool/post/4d/vpost?id=3153092
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Voltage level/ serial communications general Q
PostPosted: Sun Dec 07, 2008 6:32 pm     Reply with quote

Quote:

I'm confused about the difference between RS232 and plain ol' serial.

RS232 is a voltage level spec that is commonly used with async serial. Most micros that have a serial interface use an inverted polarity with their logic-level ports because the most common logic level to RS232 voltage converts are logic inverting. If you are connecting two devices that are both using the logic level inverted standard, then there is no need for an RS-232 buffer. But most serial devices that are intended to be plugged into other serial device adhear to some sort of RS-232 voltage standard.
As PCM Programmer said, you have to find out which standard is used by your particular device.
Quote:

Also is plain serial the same as USB?

No. But I understand the confusion because USB-serial converter modules are so common.
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 8:25 am     Reply with quote

Hello-
Thanks for replies.
The OLED's specs are stop bit = 1, parity= none and 8 (data) bits.
In the CCS manual, June 2008, page 133, the options for these do not
seem to correlate.
In the #use RS232 (baud = 9600, xmit= PIN_C6, rcv = PIN_C7, PARITY=X, BITS=X), PARITY can be N, E, or O. What do these options mean?
BITS- is this Stop or Data?
What are the default settings if I put nothing for these options.

Thanks!
N_N
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 8:32 am     Reply with quote

Quote:
...The OLED's specs are stop bit = 1, parity= none and 8 (data) bits.
In the CCS manual, June 2008, page 133, the options for these do not
seem to correlate.
In the #use RS232 (baud = 9600, xmit= PIN_C6, rcv = PIN_C7, PARITY=X, BITS=X), PARITY can be N, E, or O. What do these options mean?
BITS- is this Stop or Data?
What are the default settings if I put nothing for these options.

N=none (parity)
E=even parity
O=odd parity
BITS=8 or 9 (data bits)

So you would use PARITY=N, BITS=8

There is no explicit setting for the number of stop bits because the PIC always sends and checks one stop bit. Only some very old devices require 1.5 or 2 stop bits, and since your device is not one of them, don't bother looking into how you would use a PIC to communicate with such a device (but there are ways!).
_________________
Robert Scott
Real-Time Specialties
Embedded Systems Consulting
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 11:28 am     Reply with quote

I tested my above code with Hyperterminal, Windows XP. Using a USB->serial cable.
No matter what character or series of characters I put in the
Code:
printf("d");
line, I get p out.
If I put a number "12" or "3" or any other in, I get nothing out.

I configured HT with 9600, 8 data, 1 stop, parity NONE and Flow Control OFF.

Any ideas? Thanks in advance!
Nora
Ttelmah
Guest







PostPosted: Mon Dec 08, 2008 11:31 am     Reply with quote

With a USB-serial cable', you will need RS232 inverting buffers attached to the PIC...

Best Wishes
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 11:35 am     Reply with quote

Thanks Ttelmah!
I forgot to mention that I'm using a PICDEM Plus demo board with a MAX232 chip onboard.
So it is PC-->USB cable-->RS232 connector-> DB9 on PICDEM board-->Max232-->PIC.
~N_N
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 1:30 pm     Reply with quote

Your current task is merely to make a PicDem2-Plus board talk to
a PC, while using a USB-to-serial cable. That should work. Just
make sure that the COM configuration is the same in both the
PicDem2-Plus board and the terminal program on the PC.
Use 9600, N, 8, 1, with no handshaking, on the terminal program.


If you can't make it work, post:
1. The name of your terminal program.
2. Your test program that runs on the PicDem2-Plus board.
3. If you are using a manufactured RS-232 cable, or did you make it
yourself ? (I suggest that you use a store-bought cable).
4. Do you also have an ICD-U40 plugged into the PC ? There can be
a conflict with the USB serial cable.
Nora



Joined: 23 Mar 2008
Posts: 50

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 2:20 pm     Reply with quote

That is the problem...I am trying to do exactly that-
make a PICDEM plus talk to Hyperterminal.

If you can't make it work, post:
1. The name of your terminal program.
HYPERTERMINAL V5.1, WINDOWS XP

2. Your test program that runs on the PicDem2-Plus board.
Code:
#include <18F452.H>
#fuses HS,NOWDT,NOPROTECT, PUT, BROWNOUT, NOLVP
#use delay(clock=20000000)
#use RS232 (baud = 9600, xmit= PIN_C6, rcv = PIN_C7,BITS=8,PARITY=N,errors)
//#use RS232 (baud = 9600, xmit= PIN_C6, rcv = PIN_C7)
#use standard_io(c)
//*****************************************************************
  void main()
{
while(1){
   if(kbhit()){
   printf("xxx"); // send msg
   output_high(PIN_e2);
   }
   else
   {
   output_high(PIN_e2);
   delay_ms(200);
   output_low(PIN_e2);
   delay_ms(200);
      }
         }
}

I've used a few different versions of this, with and without waiting for hits and with and without LED blinks. The board does recognize the keyboard hit. The Hyperterm also will print the letter lowercase "p" in response to code telling it to printf.

3. If you are using a manufactured RS-232 cable, or did you make it
yourself ? (I suggest that you use a store-bought cable).
You give me way too much credit. I'm not coordinated enough to build my own. It is a GOLD X and I didn't see anything useful in the manual but here it is:
http://www.automationdirect.com/static/manuals/usbrs232manual/usbrs232manual.pdf

4. Do you also have an ICD-U40 plugged into the PC ? There can be
a conflict with the USB serial cable.
I have the ICD2 plugged into the PC.
Am unplugging it to see what I get.

Thanks in advance!
N_N
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Dec 08, 2008 2:48 pm     Reply with quote

Use this program. Any characters that are typed into the terminal
program will be sent to the PIC, and the PIC will then send them
back to the terminal program where they will be displayed.
Code:

#include <18F452.H>
#fuses HS, NOWDT, NOPROTECT, PUT, BROWNOUT, NOLVP   
#use delay(clock=20000000)                           
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

//=================================
void main()
{
char c;

printf("Start: ");

while(1)
  {
   c = getc();
   putc(c);
  }
 
}   
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