Discussion in "8051 Discussion Forum" started by    Gastonio    Sep 9, 2010.
Fri Jan 21 2011, 05:18 am
#41
I modified transmitter and receiver programs to send single character with Manchester encoding and decoding. Well, character (in this case "B" (0x42 hex ascii) is received correctly when using wired conncetion, however I can't receive nothing, when using wireless connection. Code isn't working very well too because character appears on LCD after some time, maybe even after 6-8s or even more. Could you please take a look at those codes and maybe you'll notice what's wrong with them.

Transmitter:
#define uchar unsigned char
#define uint unsigned int
#include<intrins.h>
#include<reg52.h>
#include<math.h>
#include<stdio.h>
void SendSS(void)
{
putchar(0xF0);
}

void SendData(int txbyte)
{
unsigned char G=(1<<0);
int i,j,b,me;
b = txbyte;
for (i=0; i<2; i++) {
me = 0; // manchester encoded txbyte
for (j=0 ; j<4; j++) {
me >
>
=2;
if (b&G)
me |= 0x40; // 1->
0
else
me |= 0x80; // 0->
1
b >
>
=1;
}
putchar(me);
}
}

void sercon(void)
{
	SCON   = 0x50;		
	TMOD  |= 0x20;		
	TH1     = 0xE6;             
	TR1     = 1;                  	
	TI	   = 1;               
}

void main()
{

sercon();
   
	while(1)
	{
	SendSS();
	SendData(0x42);
	SendSS();
    
	}
}

Receiver:

#include<intrins.h>
//
#include<reg51.h>
//
#include<math.h>
//
#include<stdio.h>
//
#include<1602.h>
//
unsigned char a[8];
unsigned char buffer[8];

int DecodeData(int encoded)
{
int i,dec,enc,pattern;
enc = encoded;
if (enc == 0xf0) // start/end condition encountered
return 0xf0;
dec = 0;
for (i=0; i<4; i++) {
dec >
>
=1;
pattern = enc & 0x3;
if (pattern == 0x1) // 1
dec |= 1 << 3;
else if (pattern == 0x2)
dec &= ~(1 << 3); // 0
else
return 0xff; // illegal code
enc >
>
=2;
}
return dec;             
}

void sercon(void)
{
	SCON  = 0x50;		
	TMOD |= 0x20;		
	TH1   = 0xE6;             
	TR1   = 1;                  	
	TI	  = 1;   /*clear the buffer */            
}

void main()
{
int dec;
int dec1;
int dec2;
int dec3;
int dec4;
int data1;
sercon(); 
init();
while(1)
{
data1 = getchar();
dec = DecodeData(data1);
data1 = getchar();
dec = DecodeData(data1);
dec1 = dec;
data1 = getchar();
dec = DecodeData(data1);
dec2 = dec;
dec3 = dec2 << 4;
dec4 = dec3 + dec1;
writeCmd(0x80);
sprintf(buffer,"%s",dec4);
sendstring(buffer);  
}}


[ Edited Fri Jan 21 2011, 08:27 pm ]
Fri Jan 21 2011, 08:44 pm
#42
there is no point in using Manchester encoding coz you're ultimately sending data over uart. better to leave this method and concentrate on sending data over uart. I have seen datasheet and i feel you can use connect uart directly, like all other ASK modules this is also noisy.

try to do this way..send this string on uart and receive on other end

UUUUU$testUUUUU

send 5 'U' and then $ which means your start of data, when you receive $ on receiver end start reading data in a buffer, read 4 bytes and store in buffer then stop reading. display string on terminal.

make sure baudrate is around 4800bps or lesser 2400. Please try again.
Sat Jan 22 2011, 03:29 am
#43
Well, I've modified program to send U's, but still no good when connceting modules, only garbage. I don't believe I'll even make a reliable wireless conncetion without using encoder and decoder.

Transmitter:
#include<intrins.h>

#include<reg52.h>

#include<math.h>

#include<stdio.h>


void sercon(void)
{
	SCON   = 0x50;		
	TMOD  |= 0x20;		
	TH1     = 0xE6;             
	TR1     = 1;                  	
	TI	   = 1;               
}

void main()
{
sercon();
   
	while(1)
	{
putchar(0x55);
putchar(0x55);
putchar(0x55);
putchar(0x55);
putchar(0x55);
putchar(0x24);
	}
}

Receiver:
#include<intrins.h>

#include<reg51.h>

#include<math.h>

#include<stdio.h>

#include<1602.h>

unsigned char a[10];
unsigned char buffer[32];

void sercon(void)
{
	SCON  = 0x50;		
	TMOD |= 0x20;		
	TH1   = 0xE6;             
	TR1   = 1;                  	
	TI	  = 1;   /*clear the buffer */            
}

void main()
{

sercon(); 
init();
while(1)
{
writeCmd(0x80);
gets (a, sizeof(a)-1);
sprintf(buffer,"%s",a);
sendstring(buffer);  
}}
Sat Jan 22 2011, 05:28 pm
#44
hi Gastonio
u use which module by which u get good communication
it may be a cause of ur problem that this module uses encoder and decoder
Sat Jan 22 2011, 07:34 pm
#45
Hi, Majoka, I wrote an email to the manufacturer and they said those modules don't use encoding and decoding.
Sun Jan 23 2011, 12:00 am
#46
Well, I took a look at HT12E and HT12D micros. So as I understood, the data will come from I/O ports like P1, P2 and so on and Tx and Rx pins will work as flags and boudrate regulators but not as serial transmitter and receivers. Data transmitter in this case will be I/O ports.
Am I right?
And I saw that encoder and decoder have 4 data pins. So every time they will send just 4bits of info? And on receiver side I'll have to make bit operations in order to conncet pair of 4bits?
Sun Jan 23 2011, 03:45 am
#47
You were right, guys, it worked without any encoders or decoders. That's what I call experience At first I didn't believe it'll work. I see U's on the LCD but I can't see $.
But what's really strange is that I keep reveiving U's when I've even changed a program of transmitter. There is no temperature vaules but only UUU's.


[ Edited Sun Jan 23 2011, 04:07 am ]
Sun Jan 23 2011, 09:00 pm
#48

I wrote an email to the manufacturer and they said those modules don't use encoding and decoding.


now it is verify that it can work without that

Well, I took a look at HT12E and HT12D micros. So as I understood, the data will come from I/O ports like P1, P2 and so on and Tx and Rx pins will work as flags and boudrate regulators but not as serial transmitter and receivers. Data transmitter in this case will be I/O ports.
Am I right?
And I saw that encoder and decoder have 4 data pins. So every time they will send just 4bits of info? And on receiver side I'll have to make bit operations in order to conncet pair of 4bits?


some encoder r of 4 bits and some r of 8 bis u can use 8 bits also
in 4 bit it send data in 4 bits and u has to divide no's in 2 nibbles send it one by one and at rx side u then make it byte again

But what's really strange is that I keep reveiving U's when I've even changed a program of transmitter. There is no temperature vaules but only UUU's.


this is strange if u not transmit then is u also receive U
post ur code that u test for this
Sun Jan 23 2011, 09:08 pm
#49
The code is the same I posted above. Well, U is 010101010, so maybe transmitter isn't working well and just sending 1 0 1 0.
And yes, I saw encoders and decoders which can encode and decode 8 bits.
Sun Jan 23 2011, 09:15 pm
#50
i just suggest u that as a experiment try it with encoder and decoder
may be its work
go through this thread it has same problem like u
http://www.8051projects.net/forum-t37768-0.html


[ Edited Sun Jan 23 2011, 09:30 pm ]

Get Social

Information

Powered by e107 Forum System

Downloads

Comments

Richardedils
Wed Apr 24 2024, 04:07 am
ChrisLub
Tue Apr 23 2024, 05:21 pm
Davidbab
Tue Apr 23 2024, 10:41 am
Richardrit
Tue Apr 23 2024, 09:54 am
HenryLaf
Mon Apr 22 2024, 03:50 pm
bleradrar
Mon Apr 22 2024, 06:38 am
ppu-pro_ka
Sun Apr 21 2024, 07:39 pm
Infewow
Sun Apr 21 2024, 06:30 pm