1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

Xbee UART between PICs

Discussion in 'Microcontrollers' started by Vizier87, Dec 20, 2011.

  1. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    hi guys,
    Back to business for me after learning heaps of optical circuits (but my programming still stinks :eek:)

    I connected an Xbee to both my uCs, 877A as a transmitter and 4455 as a receiver. I powered my Xbees up using a 3.3V regulator, and the rest is pretty much direct I suppose.

    I checked the output of the transmitter using an O-Scope and got a nice square wave, and the same square wave at the receiver end. So i suppose the program's the one making the problem.

    It's all simple: The received data will be displayed at PORTD. So far I received nothing.

    Here's the transmitter (PIC16f877A):

    Code (c):
    void main() {

     adcon1=0b00000111;  //pcfg settings: all digital I/O
     cmcon= 0b00000111;  //comparators off
     cvrcon=0;           //voltage comparators off
     txsta=0b00000100;   //8-bit, Async mode, Hi-Speed,
     intcon=0b11000000;  //enable all peripheral interrupts
     spbrg=129;           //9.6 kBps

     trise=0x07;         //porte=input, pspmode_bit=0;
     trisa=0b100000;     //ra5=input
     trisd=0xff;         //rd4=input, rest output
     trisb=0;            //portb=output
     trisc=0b10111111;   //input for keypads and RX=input/TX=0utput

     spen_bit=1;        // serial port enable
     portb=0;
     porta=0;
     



       while (1){
       
            txreg=0xAA;
            txen_bit=1;

       }
    }
    The receiver is a PIC18F4455:
    Code (C):
    void main() {

    trisd=0;
    latd=0;

    spen_bit=1; //enable rx-tx
    rx9_bit=0;  //8-bit
    cren_bit=1;//enable receiver



    sync_bit=0;        //asynchronous mode selected
    brgh_bit=1;        //hi-speed
    brg16_bit=0;       //16-bit not selected

    trisc=0b10000000; // rc7=input
    intcon=0b11000000; //enable all interrupts

    spbrg=129;         //9.6 kbps
     
    while (1){

          rcreg=portd;

      }
    }
    Appreciate the time spent on this. Thanks.

    Vizier87.
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    ??????

    If this is the receiver.. shouldn't it be the other way round.
     
    • Like Like x 1
  3. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    okay, I've exchanged it. But it keeps getting "garbage" i.e PORTD keeps changing outputs, and even if I didn't turn the transmitter on, it retains it's state.

    How do I improve the receiving quality?
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK

    How far apart are the modules...... with any kind of aerial, they should be at least a metre away...

    I ALWAYS test on a PC first.. just to be sure they are talking ( and they are setup correctly) have you downloaded X-CTU, to check they are on the same PANID ?
     
  6. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    err you mean we have to "setup" these things through PC first? I thought's they're just like other modules?

    So.... basically I have to build the FTDI-wired-to-the-Xbee circuit first to configure it, is it?

    Thanks dude...
     
  7. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    I thought the nearer they are, the better? Pardon for my ignorance... this is a revelation for me. :)
     
  8. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    If they are too close, the signal saturates....
     
  9. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    Also, you mean we have to "setup" these things through PC first? I thought's they're just like other modules?

    Basically I have to build the FTDI-wired-to-the-Xbee circuit first to configure it, is it?

    Thanks Ian.
     
  10. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    I bought one of these
     

    Attached Files:

    • xbee.PNG
      xbee.PNG
      File size:
      478.2 KB
      Views:
      96
    Last edited: Dec 20, 2011
  11. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    so if the X-CTU doesn't set it up, the Xbee wouldn't work properly, is it? Or is it just to check the transmissibility?
     
  12. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,305
    Likes:
    914
    Location:
    Rochdale UK
    All I know is that the X-CTU detects what software is on the module (there is quite a few versions) and lets you make a pair.. You set up the speed (baud) and then put them on the same PANID.. then you can tell them which module to talk to.... Download the manual and have a read. These things do a whole lot more.

    Also check out XRF modules... They are plug and play, and you can set up networks... They are pin compatible to the xbee.
     
  13. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    allright dude. thanks for the input. I'm going nuts modifying the code anyway so I'm gonna give this a shot, God willing.
     

Share This Page