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.

USART Pic to Pic communication

Status
Not open for further replies.

Ianb007

Junior Member level 1
Joined
Feb 17, 2010
Messages
16
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,429
I am using 2x PIC18f4431's. The one PIC reads PORTB and then sends it via USART (TX). The other PIC then receives the USART signal via the RX pin and then outputs it to its PORTB. I nowhave the problem that the first PIC that reads its PORT B, when displayed on an oscilloscope, shows a light flickering of a couple pins being "on" while they have nothing connected to them or are in the "off" position. On and off meaning, a 5V applied to a pin and 0V/nothing respectively. I have tried putting 1K and 10k pull down resistors of PORTB, but that doesn't seem to help. Even if I have only the Sending pic connected to power and read the PORT and output it via USART, the USART signal seems to at have a flickering bit between the clearly "on" bits. It looks like the pic is sometimes reading a pin to be on when it is off. I am using a baud rate of 9.615kHz. Any known reason or solution?
 

I've never used that particular PIC but based on experience with lots of other types, I suggest you look at the code for initializing PORTB, in particular, ensure no other internal peripherals are using the pins. It's easy to overlook that (example) you might be outputting PWM on a pin then reading it straight back in as though it was a dedicated input. In theory, if the port is configured properly as an input, the pins should float so your pull-up or pull-down resistors should tie the inputs to a fixed logic level, nothing inside the IC should be able to change that. Can you post your initializing code?

Brian.
 

Hi. I tried using the 18f4520, but I had the same results. I will have a look at my configuration settings too. Here is my code:

#include <p18F4431.h>
#include <usart.h>

void main() //Main function
{
TRISB = 1; //Transmit data register initialization set to on.
TRISA = 1; //Transmit data register initialization set to on.
OSCCON = 0xf0; //Internal oscillator set to 8MHz
PORTB = 0; //Initialize PORT B to be 0 or “off”
PORTA = 0; //Initialize PORT A to be 0 or “off”

while(1) //Start an infinite loop
{
OpenUSART(USART_TX_INT_OFF & USART_RX_INT_OFF &
USART_ASYNCH_MODE & USART_EIGHT_BIT &
USART_CONT_RX & USART_BRGH_LOW, 12); //USART opening line and USART settings configuration. SPBRG = 12 is the baud rate setting

while(1){ //Infinite loop start
WriteUSART(PORTB); //Write the input from PORT B to USART on TX pin
}
}
}
 

i think TRISB should be 0xff and not 1!!!!!!
as you want alll the port to be input and not only RB0

---------- Post added at 18:28 ---------- Previous post was at 18:26 ----------

also don't forget the pull-ups (or pull-downs you choose)
 

Also check the parameter you pass to "WriteUSART()", should it be the port name or the actual bytes to send?
Another thing to check is if the USART buffer is empty before you reload it. In a constant loop you might be 'force feeding' it before it has had time to empty itself.

Brian.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top