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.

Serial Communication between two pic micro

Status
Not open for further replies.

amindzo

Member
Hi,
I have a problem with serial communication. I want to send a byte to the reciver by Rf transmitter and reciever.I read the sensor data and pic16F873A send it to RF transmitter and then RF reciever take it to the pic16F873A in reciever circuit.
maby you said the reoson is the errors would be occurs in RF transportation.
but i coonect two micro by a wire and also i have aproblem. and in the reciever lcd don't show any number or a wrong number.
wire that i use is short.
what is the problem?
is it in my software?
i write it in pic basic.
i write my program for transmitter and reciever.
could you help me with this?


tarnsmitter:
define OSC 4
include"modedefs.bas"
trisb= %00000000

x var byte
y var byte
i var byte
pause 2000
x=23
y=2
for i=1 to 10
serout PORTB.7,N1200,[y]
serout PORTB.7,N1200,[x]
next i
end




reciever:
define OSC 4
include"modedefs.bas"
' Set LCD Data port
DEFINE LCD_DREG PORTC
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTC
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTC
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
pause 100
lcdout $fe,1
trisb= %11111111
x var byte
y var byte
z var byte
start:
lcdout $fe,1
serin PORTB.5,N1200,[2],x
serin PORTB.5,N1200,[2],y
serin PORTB.5,N1200,[2],z
if (y=z) then
lcdout $fe,1,#y
endif
pause 5000
goto start
end




Amin Derazgisoo
 
i just read the data of the sensor and get it to pic and then micro take it to RF transmitter and in the reciever circuit,RF reciever get the serial date and give it to micro.
but i have aproblem. i also have a oproblem by connecting two micro by wire.
and there are alot of errors.
 
Begin with a simple wire solution and try to understand what you do first. Sure your program don't work. try the following
Code:
'    Transmitter
'    ===========
define OSC 4
include "modedefs.bas"
TRISB = 0

y var byte
z var byte
i var byte

y=20
z=200
LOW PORTB.7 ' set serial output to normal state
Pause 2000  ' settle delay

Start:
    for i=1 to 10
        serout PORTB.7,N1200,[2,y,z]
        next i
    goto Start
    end
Code:
'    Receiver
'    ========
define OSC 4
include "modedefs.bas"
trisb= %11111111
DEFINE LCD_DREG PORTC
DEFINE LCD_DBIT 4
DEFINE LCD_RSREG PORTC
DEFINE LCD_RSBIT 1
DEFINE LCD_EREG PORTC
DEFINE LCD_EBIT 0
DEFINE LCD_BITS 4
DEFINE LCD_LINES 2
pause 100
lcdout $fe,1
y var byte
z var byte

start:
    SERIN2 PORTB.5,N1200,[Wait(2),y,z]
    lcdout $fe,1,DEC y, DEC z
    goto start
    end

Once this one work, implement the RF... but you'll have to do more than that simple above. Reliable RF is not as simple as most might think.
 
Last edited:
assuming your errors are due to serial I/O on your direct connected pics, a couple of possibilities:
- running both with internal osc could result in too much baudrate error (you could be seeing up to double the spec'd error rate)
- what kind of wire are you using between them - twisted or parallel? running over other signal sources? route the wires away from signal sources.
- bypassed your power on both PICs?

lots of people do use straight async on RF TX/RX but there are issues. it can be made to work but you are better off using some sort of coding - manchester, for example.
 
I used 20M crystal for my work but it didn't work.when i used 4M crystal it works but it has errors.i want to use haming code .
i want to send about 10 bytes.i want to know that i should send each byte for example 10 times or
i send all of them 10 times?
i think my program is wrong.could you help me with this?
 
Last edited:
i just read the data of the sensor and get it to pic and then micro take it to RF transmitter and in the reciever circuit,RF reciever get the serial date and give it to micro.
but i have aproblem. i also have a oproblem by connecting two micro by wire.
and there are alot of errors.
what do you mean?
what should i do?
 
You should be able to use async to communicate between 2 pics. especially at 1200 baud. something else is not right here. I would chase this one down.

you have connected the grounds of the 2 circuits, right? why don't you post a schematic?
 
I am not familier with pic basic, can you connect the output of your TX chip to the PC? and use something like Hyperterminal to read the bytes coming from the TX chip, if this works ok then it's the RX that is at fault.

I am also wondering if the RX chip is expecting the data to be "flipped/inverted" such as would happen with an rs232 translation chip like the MAX232, if so then you will not have any joy until you flip/invert this data :(

You can write some simple RS232 routines in assembler (AKA bit-banging) that will let you communicate with a PC directly (only a 10K resistor needed), if you want an example of this then let me know. Is it possible to incorperate asm into pic Basic??

Basically I am trying to say, break down your problem into smaller chunks to try and find were the problem is........ As nigel has said, this won't help with radio, but you will learn along the way ;) The main problem with radio is that when the TX (radio) module is not powered and active, you will see a lot of "noise" on the RX side, this is why basic serial comms won't work :(

Hope this helps
 
i have coonectedn the grounds of 2 circuit but in real they should be far as each other about 10 meter so i can't connect the grounds of two circuits.
 
let's clear up few things...
what are the error you refer to? Compilation error or what?

Are ou using PicBasic Pro or regular PICBAsic?

Are you sure it's MELABS PicBasic and not PROTON or else other PicBasic ?

As suggested here, try with your PC first, using the N1200 mode and a simple 1k-10K in serie to your PC will work... at least should. Case not, i'll suspect a hardware and/or configuration fuses setting problem.
 
wont the PC require inverting? in this case one transistor should do it (since it's only tx needed). plenty of circuits around. I wonder it that's a diversion, though.


there is clearly something wrong in the hardware or programming. I have been assuming he is seeing garbled characters but you never know where that could come from with out at least a schematic.
 
i use TXC1 and RXD1 RF transmitter and reciever from keymark company and i connect the data pin to PORTB.7 of micro directly.

and my program:
For transmitter:
define OSC 4
include"modedefs.bas"
x var byte
y var byte
i var byte
x=25
y=4
pause 2000
for i=1 to 5
serout PORTB.7,N1200,[y]
serout PORTB.7,N1200,[x]
next i
end

for reciever:
define OSC 4
include"modedefs.bas"
' Set LCD Data port
DEFINE LCD_DREG PORTC
' Set starting Data bit (0 or 4) if 4-bit bus
DEFINE LCD_DBIT 4
' Set LCD Register Select port
DEFINE LCD_RSREG PORTC
' Set LCD Register Select bit
DEFINE LCD_RSBIT 1
' Set LCD Enable port
DEFINE LCD_EREG PORTC
' Set LCD Enable bit
DEFINE LCD_EBIT 0
' Set LCD bus size (4 or 8 bits)
DEFINE LCD_BITS 4
' Set number of lines on LCD
DEFINE LCD_LINES 2
pause 100
lcdout $fe,1
x var byte
y var byte
z var byte
w var byte
serin PORTB.7,N1200,x
serin PORTB.7,N1200,[4],w
serin PORTB.7,N1200,[4],y
serin PORTB.7,N1200,[4],z

if w=z then
lcdout $fe,1,"y=",#w
goto finish
endif
if w=y then
lcdout $fe,1,"y=",#y
goto finish
endif
if y=z then
lcdout $fe,1,"y=",#y
goto finish
endif
lcdout $fe,1,#x
finish:
end


this is the simplest form of program because i should send 8 bytes by haming code.
 
Hi ! I want to send a value from one pic by USART to the other that will light its leds. Do you have a simple code writen in Assembly or C, please? I will really apprecciate it.
 
Status
Not open for further replies.

Latest threads

Back
Top