Continue to Site

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.

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

Wireless control.........

Status
Not open for further replies.

koolguy

Active Member
I am working on wireless based UART serial control using 2.2Ghz module everything is fine but i don't understanding while sending and using if cond at rx it is not working here is the code...

for Rx


Code:
void  HSerinit(void);
unsigned char Hserin(void);					// transmission functions
 
void main()
	{
	  
	HSerinit();
TRISC3=0;
TRISC1=0;
unsigned char ch;  
	while(1)
		{
RC1=0;
RC3=0;
	
	ch=Hserin();
if(ch=='a'){
RC3=1;
__delay_ms(200);
}
if(ch=='b'){
RC1=1;
__delay_ms(200);
}
		}
	}
 

 

 
unsigned char Hserin(void)
	{
	while(!RCIF);
	return RCREG;	
	}
 
void HSerinit()
	{
    TRISC = 0x80;                    // TX was an input!
    SPBRG = 129;                    // 20Mhz xtal 9600 BAUD
    TXSTA = 0x24;                    // TXEN and BRGH
    RCSTA = 0x90;                    // SPEN and CREN
	}



for tx


Code:
void  HSerinit(void),  Hserout(unsigned char ch);
 
void main(void)                        
    { 
	
	TRISA = 0xff ;                             
    HSerinit();
	__delay_ms(150);
unsigned char ch;
TRISD0=1;
TRISD1=1;
RD0=0;
RD1=0;
    while(1)                
        {

if(RD1==1){ch='a';
Hserout(ch);
}
if(RD0==1){
ch='b';k
Hserout(ch);
}
ch=0;	    }
	}
 

 
void Hserout(unsigned char ch)
	{
	while(!TXIF);
	TXREG = ch;	
	}
 

 
void HSerinit()
	{
    TRISC = 0x80;                    // TX was an input!
    SPBRG = 129;                    // 20Mhz xtal 9600 BAUD
    TXSTA = 0x24;                    // TXEN and BRGH
    RCSTA = 0x90;                    // SPEN and CREN
	}
 
OK< i notice one thing after watching in terminal window the serial comm is working as it should but when i press switch the led on other side glow and after pressing the same or other switch it does not work after reset the rx side uC then again it work...

so, problem is it require reset....
 
This is just a guess, but should you clear a flag (RCIF or TXIF) after receiving (or sending) one char.. Read from the datasheet the details how the UART module works.
 
Last edited:
Also put some delays in the tx code so that the code does not send data continuously when you press a button. 200 ms delay after the send commands "Hserout(ch);".
 
This is just a guess, but should you clear a flag (RCIF or TXIF) after receiving (or sending) one char.. Read from the datasheet the details how the UART module works.

I think thatch not might the problem because terminal window is showing the data cont. and without error..
when i press the any switch the serial data transmission start and work only once.
in IAN sir code he was using buffer for PWM control from ADC, i am not sure what to do he may help.. ...

HserinString(inbuff); // get incomming data
Code:
rxdata = getInt(inbuff);	// turn to decimal
   		CCPR1L = (unsigned char)rxdata ;// set PWM
 
Have you ever read the datasheet?
 
This is just a guess, but should you clear a flag (RCIF or TXIF) after receiving (or sending) one char.. Read from the datasheet the details how the UART module works.

so, you mean to say i should clear the interupt??
 
I mean to say terminal window is showing cont. data but why it is not working(led works only once need reset after that).
 
I mean to say terminal window is showing cont. data but why it is not working(led works only once need reset after that).

I understand what you are saying.

Did you add delays (200ms at least) after the "Hserout(ch);" commands.. in the tx-code?
 
Do you understand what I am saying? Did you add the delays?
 
Mr T is right Ritesh...

C:
while(1)                
	{
 
	if(RD1==1)
		{
		ch='a';
		Hserout(ch);
		}
	if(RD0==1)
		{
		ch='b';k
		Hserout(ch);
		}
	ch=0;	    
	}

This will be far too fast for the transmitter..

C:
while(1)                
	{
 
	if(RD1==1)
		{
		ch='a';
		Hserout(ch);
		}
	if(RD0==1)
		{
		ch='b';k
		Hserout(ch);
		}
	ch=0;
	__delay_ms(200);
	}	
           
	}
If you use the 200ms delay the transmission will be better... You can then adjust the delay to suit..l
 
If you send 9600 baud data to an RF module that transmits at 2GHz then you should not need any delays anywhere and even if you did then 1mS would be more than adequate - 200mS is just ludicrous.

Saying that, I'm not even going to try and figure out what the problem might be as that would be pointless, the OP would simply ignore it anyway Man.

Mike.
 
If you send 9600 baud data to an RF module that transmits at 2GHz then you should not need any delays anywhere and even if you did then 1mS would be more than adequate - 200mS is just ludicrous.

My reasoning for the delay was that I don't know what happens at the receiving PIC when there is data coming in and nobody reads it. It might create a problem.. or not. The 200ms delay was to match the 200ms delay at the receiving PIC. I could check the datasheet, but I don't bother because I know Ritesh doesn't either. When he starts reading the datasheet, I might be motivated to put more effort to help him. Now I'm just guessing where the problem might be. He didn't even tell what PIC he is using. Actually he didn't even say he is using PIC, but that is easy to assume..
 
Last edited:
I read the datasheet because Pommie doubted my solution. I just had to check if my "guess" was right. Well, Ian already said I was right.. and he knows PICs. The datasheet says:

It is possible for two bytes of data to be received and
transferred to the RCREG FIFO and a third byte to
begin shifting to the RSR register. On the detection of
the Stop bit of the third byte, if the RCREG register is
still full, the Overrun Error bit, OERR (RCSTA<1>), will
be set.
The word in the RSR will be lost. The RCREG
register can be read twice to retrieve the two bytes in
the FIFO. Overrun bit OERR has to be cleared in soft-
ware. This is done by resetting the receive logic (CREN
is cleared and then set). If bit OERR is set, transfers
from the RSR register to the RCREG register are inhib-
ited and no further data will be received.
It is, therefore,
essential to clear error bit OERR if it is set.

So the problem is exactly what I suspected. If you (Ritesh) would just read the datasheet.. even a little. You might learn something.
https://www.electro-tech-online.com/custompdfs/2013/07/39582b.pdf

Of course delays are not a very good solution. Better solution is to check the error-bit and clear it if it is set. Or better yet, read the data often enough so that there is no Overrun Error happening.
 
Last edited:
If you send 9600 baud data to an RF module that transmits at 2GHz then you should not need any delays anywhere and even if you did then 1mS would be more than adequate - 200mS is just ludicrous.

Saying that, I'm not even going to try and figure out what the problem might be as that would be pointless, the OP would simply ignore it anyway Man.

Mike.

Not quite the same thing.... There will still be the delays in the upconvertor... To all and sundry outside the 2Gig transmitter it's still a 9600 connection..

The 2 / 2.4 gig wireless is broadband ( unless I'm off here )... The data packets with these transmitters are assigned are they not..

I am definitely not up to speed with wireless transmission... But the little XRF units I use, run at @900Mhz... I have to insert delays, obviously not 200mS, that would be ludicrous, but a little delay between packets.... The reason I do this is because the data seems to go further more reliably..

I remember that some of the XBee modules had very small packet sizes.... BUT!!! as the man from India is only sending ONE byte, all this is trivial...
 
Status
Not open for further replies.

Latest threads

Back
Top