Keil™, An ARM® Company

Discussion Forum

gets function giving problem

Next Thread | Thread List | Previous Thread Start a Thread | Settings

DetailsMessage
Read-Only
Author
Ameya Hardikar
Posted
7-May-2008 01:38
Toolset
C51
New! gets function giving problem

gets function giving problem
Ameya Hardikar

Dear All,

I am trying to read some float values/strings from a serial port. A VB based front end application sends me these values over a serial port.The communication between the front end application and firmware is ok. i.e. I am able to read single characters send by application and application is able to read values which my firmware is sending.
But whenever I try to read values from serial port using gets function or scanf function then sometimes it works and sometimes not. And when it works 'gets' does not assigns all values received to the string variable. e.g. if i am receiving "Ameya" then only "mey" is received.
At the same time this code works fine on a keil debugger. I am using customized forms of putchar() and _getkey() functions...
Also I have tried sending CR/LF characters from VB application for which gets waits..but the problem still persists. I am wondering if it is working with keil debugger what could be problem..? Please help me ..

Read-Only
Author
Andy Neil
Posted
7-May-2008 02:13
Toolset
C51
New! Duplicate thread

http://www.keil.com/forum/docs/thread12377.asp

Read-Only
Author
Tamir Michael
Posted
7-May-2008 02:44
Toolset
C51
New! RE: gets function giving problem

are you sure you don't suffer from time drift of some kind? if I remember correctly, RS232 clocks must be within 15% from each other in order to deliver their payload.

Read-Only
Author
Andy Neil
Posted
7-May-2008 02:57
Toolset
C51
New! RE: RS232 clocks must be within 15% (sic) from each other

It's the Baud rates that need to be closely matched - not the clocks.

And they need to be much closer than 15%!!

=:0

http://www.keil.com/c51/baudrate.asp

"For best results, choose baud rates that are accurate to +/-1% or better."

Read-Only
Author
Tamir Michael
Posted
7-May-2008 03:46
Toolset
C51
New! RE: RS232 clocks must be within 15% (sic) from each other

Andy, I think I almost gave you a heart attack, sorry for that...let me try to redeem my sin :)

"Besides having a maximum switching speed, RS-232 drivers must also meet
minimum standards to ensure that signals dont linger in the undefined region
between logic states when switching. For control signals and other signals at 40
bps and lower, the line must spend no more than 1 ms in the transition region
between a valid logic 0 and logic 1. For other data and timing signals, the limit
is 4% of a bit width, which works out to 2 μs at 20 kbps or 0.33 μs at 120 kbps.
An output that switches between -5V and +5V in 0.33 μs is changing at the
specified upper (fastest) limit for the slew rate. The signals’ rise and fall times
should also be as nearly equal as possible"
Read-Only
Author
Andy Neil
Posted
7-May-2008 04:32
Toolset
C51
New! RE: RS232 clocks must be within 15% (sic) from each other

That's all down to the transceiver hardware - so not really any concern for the software.

For an discussion on the effect of baud rate errors, see: http://www.8052.com/forum/read.phtml?id=91004 and follow the replies!

Read-Only
Author
Neil Kurzman
Posted
7-May-2008 14:35
Toolset
C51
New! RE: gets function giving problem

"Ameya" then only "mey" That sound like your code. I doubt a baud rate error would kill the first two bytes. How are you receiving the data are you using the serial interrupt? Are you trying to process data in the interupt? If not you need to. Try setting the inter-charter delay in VB. If that solves it you code is too slow.

Read-Only
Author
Andy Neil
Posted
7-May-2008 15:39
Toolset
C51
New! Don't *process* anything in the interrupt

"Are you trying to process data in the interupt? If not you need to."

No!
You should not try to process it in the interrupt!

The interrupt should do just the minimum to snatch it from the UART and put it into a buffer - the actual processing should be done in the main code...

This is well illustrated in the interrupt-driven serial examples provided by Keil; eg, http://www.keil.com/download/docs/200.asp

Next Thread | Thread List | Previous Thread Start a Thread | Settings