|
|
View previous topic :: View next topic |
Author |
Message |
overmindx
Joined: 06 Oct 2008 Posts: 43
|
problem with 38400 baud |
Posted: Wed Feb 05, 2014 1:13 am |
|
|
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: 19589
|
|
Posted: Wed Feb 05, 2014 2:03 am |
|
|
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. |
|
|
|
|
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
|