• 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.

Help with re-initializing Manchester connection

Status
Not open for further replies.

Vizier87

Active Member
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:
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?
 

Vizier87

Active Member
Added problem: I really don't understand the part MikroC states:
  • The Manchester receive routines are blocking calls (Man_Receive_Init and Man_Synchro). This means that MCU will wait until the task has been performed (e.g. byte is received, synchronization achieved, etc).
  • Manchester code library implements time-based activities, so interrupts need to be disabled when using it.
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?

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.
 

Vizier87

Active Member
Okay so here's a bit of code-fu that I'm trying out:

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!
 
Status
Not open for further replies.

Latest threads

EE World Online Articles

Loading
Top