Shop OBEX P1 Docs P2 Docs Learn Events
Bidirection serial communication — Parallax Forums

Bidirection serial communication

brianLbrianL Posts: 8
edited 2009-12-29 18:47 in General Discussion
I’ve been trying to figure out why I can only send strings to my pic controller.· When I try using the Uart receiveByte() method I only get a solid 2vdc signal.· Below is some of the code I used to try and get this to work.· The parallax USB oscilloscope has helped a ton, but I’m still stuck with this problem.· Any help would be appreciated.
Thanks,
Brian
·
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
package mainclasses;
import· stamp.core.*;
import Arobot.*;
·
public class Arobot2 extends VirtualPeripheral {
· public static picnet motor = new picnet();
· //public static picnet2 motor2 = new picnet2();·· tried creating an object here first and also tried using a static method in picnet2 class
·
· public static void main() {
···· char r = 'b';
···· int j = 0, cnt = 0;
···· motor.run();
···· while (true) {
···· cnt++;
···· if (r == 'A')
····· motor.stop();
···· if (r == 'b')
····· {
····· if (cnt == 5)· {·· // cnt being used because I don't know how to instantly switch from transmit to receive after string is sent when Uart is background VP
······· j=picnet2.wildCard;················ // if I get rid of this line the controller will send the string to the pic
······· continue;
······· }
····· else
······· continue;
····· }
···· else····· {
····· motor.run();
····· r='b';
····· }
·· }
· }
}
/////////////////////////////////////////////////////////////////////////////////////////
·
package Arobot;
import stamp.core.*;
·
public class picnet2 {
· public static int wildCard = 0;
· public static final int netPin = CPU.pin8;
· public static Uart UartReceive = new Uart(Uart.dirReceive, netPin, Uart.dontInvert, Uart.speed2400, Uart.stop1);
·
· public void showByte()· {
· wildCard=UartReceive.receiveByte();
· }
· }

Comments

  • Peter VerkaikPeter Verkaik Posts: 3,956
    edited 2009-10-29 18:06
    Hi,

    First, do not declare
    public class Arobot2 extends VirtualPeripheral {
    but use
    public class Arobot2 {

    You can change a Uart from transmit to receive
    by using
    myUart.setDirection(Uart.dirReceive)

    Also, since you use a single pin for transmit and receive,
    use a 1k resistor between Javelin I/O pin and your PIC pin.
    This is to protect the pins in case both devices transmit
    at the same time.

    regards peter
  • KaderkhanKaderkhan Posts: 1
    edited 2009-10-30 17:08
    HI guys

    how are you? I would like to thanks for your comments and I think that Bidirectional Serial Communication Modules ... 1. Simplified bidirectional communication module, depicting ... Crosstalk in bidirectional serial communication.Serial ports, also called communication (COM) ports, are bidirectional. The bidirectional communication allows each device to receive and transmit data.


    Thanks

    Post Edited By Moderator (Bean (Hitt Consulting)) : 12/31/2009 3:50:56 PM GMT
  • brianLbrianL Posts: 8
    edited 2009-11-03 23:05
    I’ve had family in town so I’m just now getting a chance to try out some of your advice. I’m still having some trouble. I tried before using the setDir(Uart.dirReceive) method but wasn’t able to get it to work. Would this switch from transmission to receive instantly? I can’t remember if I even had to get a char ‘A’ back from my pic controller; I’m thinking that I used to just transmit a string with the distance as the last four bits and my motor would just stop when the pic read the distance from the enoder. My pic came preprogrammed so I don’t know exactly how it behaves (robot kit). I was also trying to use the compass AppMod in serial mode. This is parallax compass that is now obsolete. One of these days I’ll have more time to actually concentrate on my hobbies. .

    Best Regards,
    Brian
  • ashiqashiq Posts: 1
    edited 2009-12-29 18:47
    Ah .. so all USB communication is half duplex!

    This means that if I were to create a TTL serial <-> USB convertor, for example, and had the serial port been full duplex, I would have to have large buffers on the serial port side to buffer in/out data until it got sent through the USB port?

    1. Does that mean a TTL serial <-> USB convertor is never a true convertor? In other words a full duplex serial port after a TTL serial <-> USB conversion becomes a "virtual half duplex" serial port (if I wre to emulate a serial port on the USB side)?

    2. What are good half duplex projects using VUSB?

    Post Edited By Moderator (Bean (Hitt Consulting)) : 12/31/2009 3:51:38 PM GMT
Sign In or Register to comment.