Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Microcontrollers receiving raw data from zigbee?

Status
Not open for further replies.

gabriellimhj

Junior Member level 3
Junior Member level 3
Joined
Oct 30, 2013
Messages
30
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Visit site
Activity points
181
hi, as title stated. I have written some source code but i'm not sure if the code is correct or not. 1.PNG2.PNG3.PNG
 

In ISR remove the line... You are disabling serial interrupt after receiving the first character and then not re-enabling it. Also there is no need to disable the serial interrupt. Have you configured Zigbee or XBee using XCTU software?


Code C - [expand]
1
TI_1 = ES1 = 0;

 

thanks for the reply. yup i configured my zigbee using telegesis before putting it on mircocontroller.
 

hi how do i write the source code if i want to on a LED to indicate receiving data and off LED when not receiving data. thank you
 

i mean the LED will be light up when the correct raw data is received and nothing happen when wrong data is received. The correct data received should be !A@ as i have set it on my telegesis. Thank You
 

Read UART data using interrupt and set a flag in ISR after data receive is complete. Use this flag in while(1). If flag is set then test if data is valid, if valid turn ON LED else turn OFF.
 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//ISR
 
if(RI == 1){
 
 
    uard_rd[i] = SBUF;
    i++;
    
    if(i > dataLength)process = 1;
 
}
 
//main()
 
while(1){
 
    if(process){
 
        if((uart_rd[0] == 'A') && (uart_rd[1] == 'B'))LED = 1;
        else LED = 0;
 
                process = 0;
                i = 0;
    }
 
}

 


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#include <absacc.h>
 
sbit mybit = P1^4;
 
unsigned char code start_header = '!';
unsigned char code end_header = '@';
unsigned char inforstart = 0;
unsigned char infor[20];
unsigned char inforcount = 0;
unsigned char i = 0;
 
void main(void){
        TMOD = 0x20;
        SCON0 = 0x50;
        TH1  = 0xFD;    //9600 bps
        TR1  = 1;
}
 
//send data as "!A@" and test
 
void serial_int (void) interrupt 4{
{
  if(RI_0);     //check RI until set
  {
    infor[i++] = SBUF0;
 
    if (infor[0] =='!')     
    {   
        inforstart = 1;
        inforcount = 0;
    }
    
    if(inforstart == 1)
    {
        if (infor[2] =='@')
        {   
            inforstart = 0;
            if(infor[1] == 'A')mybit = 1;
            else mybit=0;
            i = 0;
                        
        }
    }
    
        
    
  }
 
  RI_0 = 0; 
}

 

Hi, the LED is still ON even before i receive any data. I added a line but it still cannot works.
void serial_int (void) interrupt 4{
while(1)
{
mybit=0;
if(RI_0==0); //check RI until set
 

sorry, this is the full code. Yes LED is set as output. Now for this new code, once i received data the LED will off.
 

Attachments

  • testing3.txt
    911 bytes · Views: 84

This mikroC Code is working. I found the problem. Some other interrupt other than serial interrupt is occuring. Mention exact device you are using.

mikroC PRO 8051 project files + Proteus simulation attached.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
sbit mybit at P1_4_bit;
 
unsigned char infor[5];
unsigned char i = 0;
 
void SerialInterrupt() iv IVT_ADDR_ES ilevel 0 ics ICS_AUTO{
  
  if(RI_bit);
  {
    infor[i] = SBUF;
    i++;
    RI_bit = 0;
  }
 
  RI_bit = 0;
 
}
 
void main(){
 
     P1 = 0x00;
     P3 = 0x03;
          
     TMOD = 0x20;
     SCON = 0x50;
     TH1  = 0xFD;
     TR1_bit  = 1;
     EA_bit = 1;
     ES_bit = 1;
 
     while(1){
     
            /*
            SBUF = 'K';
            while(TI_bit == 0);
            TI_bit = 0;
            */
 
 
            if(i >= 3){
            
                    if((infor[0] == '!') && (infor[1] == 'A') && (infor[2] == '@'))
                    {
                             mybit = 1;
                    }
                    else mybit = 0;
                    
                    i = 0;
            }
            
 
     }
}

 

Attachments

  • AT89C51 UART.rar
    22 KB · Views: 57
  • AT89C51 UART rev1.rar
    21.9 KB · Views: 57
Last edited:

hi, may i know what exact device u need? the attached file is working but i have to receive about 10 data or more(meaning i send !A@ >10times) before the LED on. where what i want is once receive 1 data the LED will be on.
 

Attachments

  • working1.txt
    985 bytes · Views: 58

I'm sending !A@ from zigbee to another zigbee on microcontroller. It's just a 1 time sequence. LED OFF when nothing is pressed or data received is not !A@.
 

Sending !A@ 10 times is the one time sequence? Micro has to check if !A@ is received 10 times and then turn ON LED else turn OFF?

This code checks if !A@ is received 10 times. If yes LED is ON else LED is OFF.


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
sbit mybit at P1_4_bit;
 
unsigned char infor[30];
unsigned char i = 0;
unsigned short j, count = 0;
 
void SerialInterrupt() iv IVT_ADDR_ES ilevel 0 ics ICS_AUTO{
  
  if(RI_bit);
  {
    infor[i] = SBUF;
    i++;
    RI_bit = 0;
  }
 
  RI_bit = 0;
 
}
 
void main(){
 
 
     
     P1 = 0x00;
     P3 = 0x03;
 
     TMOD = 0x20;
     SCON = 0x50;
     TH1  = 0xFD;
     TR1_bit  = 1;
     EA_bit = 1;
     ES_bit = 1;
 
     while(1){
     
 
            //SBUF = 'K';
            //while(TI_bit == 0);
            //TI_bit = 0;
 
 
            if(i >= 30){
            
                    for(j = 0; j < 30; j + 3){
                            if((infor[j] == '!') && (infor[j + 1] == 'A') && (infor[j + 2] == '@'))
                                             count++;
 
                    }
                    
                    for(j = 0; j < 30; j++)
                             infor[j] = '\0';        //Clear array
                             
                    if(count == 10)mybit = 1;
                    else mybit = 0;
 
                    count = 0;                       //Reset counter
            }
 
     }
}

 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top