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

Help with re-initializing Manchester connection

Discussion in 'Microcontrollers' started by Vizier87, Aug 21, 2017.

  1. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    Hi guys, I'm doing a simple Manchester communications. Basically my Tx sends 0xfa and the if the Rx reads 0xfa, an LED lights up.


    I've achieved this using the following code for the receiver:
    Code (C):

      while (1) {
           data_ = Man_Receive(&error);             // Attempt byte receive
           if (error) {                            // If error occured
             ErrorCount++;                         // Update error counter
             if (ErrorCount > 20) {                // In case of multiple errors
               //data_ = Man_Synchro();               // Try to synchronize again
               Man_Receive_Init();               // Alternative, try to Initialize Receiver again
               ErrorCount = 0;                     // Reset error counter
               }
           }

           else {
             if (data_  != 0xfa)
             Indicator = 0;

             if (data_  == 0xfa)
             Indicator = 1;
      }
     
    This worked nicely for a wire-to-wire transmission. I could connect and re-connect the wire, reset the PIC and it would work nicely.

    However, using cheap 315MHz RF modules, I'd have to have a wire-to-wire transmission first before it'll be synchronized.

    Does this mean I have to use a timer to refresh the initialization?
     
  2. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    Added problem: I really don't understand the part MikroC states:
    On the other hand, the example code given in the help directory states that the timer is enabled after the Man_Receive_Init is called. Can somebody explain this? Doesn't this mean that the interrupt enabled will affect the Man_Receive_Init?

    Code (c):

    Man_Receive_Init();
      [I]// try Man_Receive with blocking prevention mechanism[/I]
      INTCON.GIE = 1;               [I]// Global interrupt enable[/I]
      INTCON.T0IE = 1;              [I]// Enable Timer0 overflow interrupt[/I]
      data1 = Man_Receive(&error);
      INTCON.GIE = 0;               [I]// Global interrupt disable[/I]

     
    I'm still fuzzy with my fundamentals so bear with me guys.

    Vizier87.
     
  3. Vizier87

    Vizier87 Active Member

    Joined:
    May 12, 2009
    Messages:
    1,495
    Likes:
    12
    Location:
    Johor Bahru, Malaysia
    Okay so here's a bit of code-fu that I'm trying out:

    Code (c):

    while(1){
       
         gie_bit = 1;               // Global interrupt enable
         t0ie_bit = 1;              // Enable Timer0 overflow interrupt
         data_ = Man_Receive(&error);             // Attempt byte receive
         gie_bit = 0;
       
       
         if (error) {                             // If error occured
           ErrorCount++;                          // Update error counter
           if (ErrorCount > 20) {                 // In case of multiple errors
             //data_ = Man_Synchro();             // Try to synchronize again
             Man_Receive_Init();                  // Alternative, try to Initialize Receiver again
             ErrorCount = 0;                      // Reset error counter
           }
         }

         if (data_  != 0xfa){
           Indicator = 0;
         }

         if (data_  == 0xfa){
           Indicator = 1;
         }

      }

     
    I've tried an interrupt routine but the example in the MikroC help directory puts it too simply. Anyone can suggest if I'm going in the right direction here?

    Right now it's still the same. A wire-to-wire transmission works-ish but not wireless. It seems my first code worked best.

    Thanks.. and help!
     

Share This Page