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.

help to "Sync" usart

Status
Not open for further replies.

Rudy_1

New Member
Hi.

Using RF FSK modules with two 16F628, one way link. How may I sync the stream, I mean, send some preamble, like 8 x 0x55, and what?

The problem is that my code only work when i send the code twice.

TX code:

#include <16f628a.h>
#fuses INTRC_IO, WDT, PROTECT, NOBROWNOUT, NOMCLR, CPD, PUT , NOLVP
#use delay(clock=4000000, RESTART_WDT)
#use rs232(baud=2400, xmit=pin_b2, rcv=pin_b1, ERRORS)
#use fast_io(a)
#use fast_io(b)
#byte porta = 0x05
#byte portb = 0x06
#byte txsta = 0x98
#byte rcsta = 0x18
#byte pir1 = 0x0c
#byte pie1 = 0x8c

#bit txen = txsta.5
#bit spen = rcsta.7

#bit up=porta.3
#bit dw=porta.4

int page=0;
int aux_0=0;
int flag_0=0;

#bit deb=flag_0.0

void antideb()
{
aux_0++;
if(aux_0==0xff)deb=0;
}
void tx()
{
output_high(pin_b2);
spen=1;
delay_ms(5);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x55);
putc(0x10); // this is what I want, recognizes the 0x10 as unique address.
deb=1;
spen=0;
output_low(pin_b2);
}

Help.
 
I always suggest to begin with a direct connection first, or at least PIC to PC connection (via MAX232 or else), then add the RF.

We don't see your receiver code yet :eek:
 
You can't really send raw serial data over a radio link, unless you have modules with built-in endocders/decoders - the normal method is to use Manchester coding, you can check my tutorial for one method.
 
I already done that, but I think that will be impossible to do something without transmitting and receive the clock too.

I am thinking in use the auxiliary circuit below to get it working properly, don’t see any other choice to send all bits I want. If I use some “specials” radios, the cost will rise too much.

In fact, I will only do one more try, working around a code I got on the web.

#int_RDA
void RDA_isr(void) {
rx_buffer[rx_wr_index] = getc();
rxd = rx_buffer[rx_wr_index]; // this just makes it easier typing-wise later on
rx_wr_index++;
if (rx_wr_index > RX_BUFFER_SIZE) {
rx_wr_index = 0;
}

// now look for unique ID: "Dave "
if (rxd == 'D' && lock_state == 0) {
lock_state++;
}
else if (rxd == 'a' && lock_state == 1) {
lock_state++;
}
else if (rxd == 'v' && lock_state == 2) {
lock_state++;
}
else if (rxd == 'e' && lock_state == 3) {
lock_state++;
}
else if (rxd == ' ' && lock_state == 4) { // got the entire string "Dave ", in that order
lock_state = 0; // reset our "combination lock"
got_id = TRUE;
valid_data_count = 0xff; // get ready to count the number of data bytes - we know we have to expect 5 (Rocks)
// also going to reset the buffer write index back to 0, so that I know where my valid data will be
rx_wr_index = 0;
}
else { // we didn't receive "Dave ", so reset the lock back to the beginning
lock_state = 0;
}

if (got_id && ++valid_data_count == 5) {
data_avail = TRUE;
got_id = FALSE;
}
}

Take a look.
 

Attachments

  • imagem.jpeg
    imagem.jpeg
    45.5 KB · Views: 147
Rudy_1 said:
I already done that, but I think that will be impossible to do something without transmitting and receive the clock too.

Not at all, why not do like I said, and check my tutorial which shows how it's done - but in assembler, not C.
 
Nigel Goodwin said:
Not at all, why not do like I said, and check my tutorial which shows how it's done - but in assembler, not C.

Ok, where can i found it? I will take alook.
 
My friend, I think you convince me to try a little bit more; of course I will need your help to make some changes in that code for my application.

There are so many times I don’t write in assembly, but this I can fix.
Here are some questions;

1 – FSK modules don´t work? Because I using this ones, RFsolutions is very difficult to me to acquire, I have Phoenix distributor in Brazil, I think they have something near to this modules, but is very expensive.

2 – What tutorial do you think is more “adaptive” to my requirements? My intention is to send about 128bits to air.

3 – For what I saw, the code is sending A/D conversion to air, this is not my intention, once we choose one code for the tutorial list, can you please help me to erase all code regarding to it, I think I can handle this, but just in case, I will need some help.

4 – Like I explained, my intention is to have a LCD, four buttons and nothing more, my C routine will choose some device in my car, by using two of the four buttons, the others two will turn on or off the device I choose before, nothing more, nothing lass then this. How may I send bytes or values between C code and assembly code?

By now I will do compile this two devices in MPlab, verify the hardware you show, and make some tests.

Thanks very very very much for now.
 
Rudy_1 said:
My friend, I think you convince me to try a little bit more; of course I will need your help to make some changes in that code for my application.

There are so many times I don’t write in assembly, but this I can fix.
Here are some questions;

1 – FSK modules don´t work?

Of course they work, as long as you use them properly.

2 – What tutorial do you think is more “adaptive” to my requirements? My intention is to send about 128bits to air.

128 bits is a lot of data really, how is that used for your LCD and four buttons?. Obviously it's not a problem, you could either send it as a single packet, or split it into smaller packets.

3 – For what I saw, the code is sending A/D conversion to air, this is not my intention, once we choose one code for the tutorial list, can you please help me to erase all code regarding to it, I think I can handle this, but just in case, I will need some help.

My tutorials just send packets of data, I can't even remember off hand what the exact source of the data was?, but it makes no difference either way.

4 – Like I explained, my intention is to have a LCD, four buttons and nothing more, my C routine will choose some device in my car, by using two of the four buttons, the others two will turn on or off the device I choose before, nothing more, nothing lass then this. How may I send bytes or values between C code and assembly code?

I don't do C, so I've no idea, sorry.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top