View previous topic :: View next topic |
Author |
Message |
Guest
|
Loosing characters on RS232 at 115200 |
Posted: Mon Nov 17, 2003 6:48 am |
|
|
Can somebody help me please,
I'm communicating using the PIC 16F627 using the hardware USART. It's a simple connection, 2 wires - one for rx. and one for tx. The voltage levels match (well, I use a voltage divider to bring the PIC's voltage from 3.5 down to 3 but apart from that they match up)
The baud rate for communication is 115200 but there is no flow control for the transmission. The PIC receives 3 characters from a burst of 10, I know this is probably the overflow error being trigerred and I've tried all the remedies on this site (I think) (turn off and on receive circuit, ERRORS in #use RS232 ... ) so I was just wondering if there is a definitive way to deal with this?
Maybe someone could post a transmit / receive piece of code for the PIC (interrupt driven or polled, either or)
Thanks a million,
KK |
|
|
Ttelmah Guest
|
Re: Loosing characters on RS232 at 115200 |
Posted: Mon Nov 17, 2003 6:50 am |
|
|
Anonymous wrote: | Can somebody help me please,
I'm communicating using the PIC 16F627 using the hardware USART. It's a simple connection, 2 wires - one for rx. and one for tx. The voltage levels match (well, I use a voltage divider to bring the PIC's voltage from 3.5 down to 3 but apart from that they match up)
The baud rate for communication is 115200 but there is no flow control for the transmission. The PIC receives 3 characters from a burst of 10, I know this is probably the overflow error being trigerred and I've tried all the remedies on this site (I think) (turn off and on receive circuit, ERRORS in #use RS232 ... ) so I was just wondering if there is a definitive way to deal with this?
Maybe someone could post a transmit / receive piece of code for the PIC (interrupt driven or polled, either or)
Thanks a million,
KK |
What clock rate is the PIC?. This makes a huge difference to how easy/difficult this is...
Best Wishes |
|
|
jamesjl
Joined: 22 Sep 2003 Posts: 52 Location: UK
|
PIC oscillator frequency Vs RS232 Baud rate. |
Posted: Mon Nov 17, 2003 6:52 am |
|
|
Your Baud rate of 115200 is very high for a PIC I think! What frequency are you driving your PIC at. I am not sure what the relationship is but I am sure that the slower the oscillator frequency of your hardware the slower your Baud rate has to be to ensure accurate communications.
Hope this helps.
Jason. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Nov 17, 2003 7:08 am |
|
|
Nope, 115200 is very doable. I currently have one receiving a DMX stream which is at 250000. Of course, I am running at 20MHz.
To the orginal poster:
There are lots of examples posted here on how to do this. You might also post you code. Not sure what you are refering to about the voltages. You might explain this a bit more. What are you communicating with? |
|
|
kennethkearney
Joined: 17 Nov 2003 Posts: 7
|
|
Posted: Mon Nov 17, 2003 7:30 am |
|
|
The clock rate is 20MHz, this was the best one from the data sheet 1.36% error should be well within the operating range. The program wouldn't even compile when I had it as a clock speed of 4MHz so I'm guessing that it's ok |
|
|
kennethkearney
Joined: 17 Nov 2003 Posts: 7
|
|
Posted: Mon Nov 17, 2003 7:49 am |
|
|
Last message contd.
I'm communicating with a Nokia phone on the fbus. It works at a 3V level but like I said, the PIC picks up 3 characters and then doesn't give anything else back.
Code :
#use delay (clock=20000000)
// NB these pins are wrt the PIC
#define PC_RATE 19200
#define PC_TXD pin_a1 // RS232 Transmit
#define PC_RXD pin_a0 // RS232 Receive
#define RTS pin_a3 // RS232 Ready To Send
#define phone_RATE 115200
#define phone_TXD pin_b2 // FBus serial communication with the phone.
#define phone_RXD pin_b1 // Would need to operate the PIC half and full duplex
// at the same time to work with MBUS
/*########### Everything below is the same as the ##############
############# code previously supplied as MAX2ARM.c ############*/
void initialise(void);
int8 gethex1(void);
int8 gethex(void);
void put_PC(int8 c);
void put_phone (int8 c);
int8 get_phone (void);
int kbhit_PC (void);
int kbhit_phone (void);
#use rs232(baud = phone_RATE, xmit = phone_TXD, rcv = phone_RXD, parity = n, bits=8, errors)
void put_phone (int8 c)
{
putc (c);
}
int8 get_phone (void)
{
return (getc());
}
int kbhit_phone (void)
{
return (kbhit());
}
#use rs232(baud=PC_RATE, xmit=PC_TXD, rcv=PC_RXD, bits=8)
int8 gethex1(void)
{
int8 digit;
digit = getc();
if(digit<='9')
return(digit-'0');
else
return((toupper(digit)-'A')+10);
}
/*--------------------------------------------------------- gethex --*/
/* used to get hex data from PC */
int8 gethex(void)
{
int low, high;
high = gethex1();
low = gethex1();
if(low == 0xdd)
return(high);
else
return( high*16+low);
}
void put_PC (int8 c)
{
int high, low;
high = 0xf & (c >> 4);
low = 0xf & c;
if (high<=9)
{
putc(48+high);
}
else
{
putc(55+high);
}
if (low<=9)
{
putc(48+low);
}
else
{
putc(55+low);
}
putc(0x20); //puts a space between each of the hex numbers
}
int kbhit_PC (void)
{
return (kbhit());
}
for(;;)
{
while (kbhit_phone()==1)
{
buffer[i] = get_phone();
i++;
}
bit_clear(*0x18,4); // clear the Continous Receive Enable flag to disable the receiver
bit_set(*0x18,4); // re-enable it
for (n=0; n<i; n++)
{
put_PC(buffer[n]);
}
i=0;
}
This is part of a program to echo on the Hyperterminal what is being sent to the PIC but like I said, it will only return 3 characters |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Mon Nov 17, 2003 8:53 am |
|
|
I didn't check your code that closely but if you are trying to echo the characters using a software uart, that is probably your problem. You will get an overflow since you are not removing the chars from the hardware uart buffer. The software uart requires tight delay loops where interrupts should be disabled so even using an isr would not work for you. If possible, you should wait until you have received all the chars and then transmit them. |
|
|
Ttelmah Guest
|
|
Posted: Mon Nov 17, 2003 9:09 am |
|
|
Mark wrote: | I didn't check your code that closely but if you are trying to echo the characters using a software uart, that is probably your problem. You will get an overflow since you are not removing the chars from the hardware uart buffer. The software uart requires tight delay loops where interrupts should be disabled so even using an isr would not work for you. If possible, you should wait until you have received all the chars and then transmit them. |
Also, I don't think the voltages being described do meet the PIC's input requirements...
The RX input, has a Schmidt input buffer (fig 5-10, and table 17.3), which requires a signal level of 0.8Vdd, to ensure the 'high' level is seen. If the PIC is running off 5v (as the comment about a voltage divider on the output implies), then it will not reliably see the incoming data signal.
Best Wishes |
|
|
Neutone
Joined: 08 Sep 2003 Posts: 839 Location: Houston
|
|
Posted: Mon Nov 17, 2003 9:36 am |
|
|
I would try a tight loop to see if the chip is recieving the data stream. Send a string requesting a responce from the phone. Dont try to send a single byte at a time. Leave the watch dog running without a reset so you can see the same event repeatedly.
Code: |
puts("xxxxxx");
while(1)
{ Getc();
Test_Pin=!Test_Pin;
}
|
Something this simple will let you see if the signal can being recieved by the chip. All you need is to place a scope on the test pin and see how many times the pin toggles. |
|
|
kennethkearney
Joined: 17 Nov 2003 Posts: 7
|
|
Posted: Mon Nov 17, 2003 10:08 am |
|
|
Thanks for the help,
I'm getting all the data now using #int_rda and streamed input and output.
New problem though.
When I want to putc the data to the PC, I have to turn off the interrupts, output the data and turn back on the interrupts, by which time I have lost 1 or 2 characters!!!
Is there a better way to do this? (If I don't turn off the interrupts, the PIC outputs rubbish as it gets interrupted) |
|
|
|