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

problem with 38400 baud

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



Joined: 06 Oct 2008
Posts: 43

View user's profile Send private message

problem with 38400 baud
PostPosted: Wed Feb 05, 2014 1:13 am     Reply with quote

hi,
I am trying to communicate with a sensor that runs on 38400 baud rate. When i used the serial hardware pins on my pic, it runs ok. But when i use different pins via software UART, it doesn't communicate with the sensor. Can anybody shed light on this? thanks.

Here are some details of my code:
Compiler pch 4.124

Excerpt:
Code:

#include <18F67K22.h>
#device adc=12
#device PASS_STRINGS = IN_RAM

#FUSES WDT_SW, WDT32768, INTRC_IO, NOPROTECT, NOIESO, BROWNOUT, PUT, NOCPD, STVREN, NODEBUG, NOWRTD, NOEBTR, NOCPB, NOEBTRB, NOWRTC, NOWRTB, FCMEN, NOXINST, MCLR, RTCOSC_T1
#use delay(clock=16000000)

#use rs232(baud=57600, xmit=PIN_G1, rcv=PIN_G2, stream=PC)
#use rs232(baud=38400, xmit=PIN_D6, rcv=PIN_D5, stream=SENSOR)
Ttelmah



Joined: 11 Mar 2010
Posts: 19459

View user's profile Send private message

PostPosted: Wed Feb 05, 2014 2:03 am     Reply with quote

Seriously, you talk about it 'communicating', but not what you are trying to do.

You need to understand a key difference between hardware and software serial.

Hardware serial is full duplex. Stuff can be received at the same time as stuff is being sent.
Software serial is half duplex. You can only send or receive at any one time.
Then hardware serial is buffered. A character (max. 1.99999 characters), can be stored in the chip's receive hardware at any time, waiting to be processed.
Software serial, requires your code to be polling the incoming line at least twice as often as the bit time (actually more like 3* for reliable operation), and be doing this before the first bit arrives.

So assuming you are sending a command to the sensor, that then replies, software serial can do this, but your code will need to be written to delay by no more than 1/3rd a bit time, between receiving the last bit of a character, and going back to waiting for the next character.
If the sensor starts to reply before transmissions are finished, then it is never going to work with software serial.
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