pic Uart receive and transmit

Thread Starter

sovannarith

Joined Feb 11, 2010
18
Dear forum member,
Picture.jpg
I have a problem with using uart of pic 16f887 to communicate with PC via VB 6.0.
I can successfully send command from VB to control pic but I try to get text back from pic it doesn't work. but instead read text, I can read back only what I sent out.
Could you please help my problem.

I have write a small code for testing using MikroC pro for pic as bellow:
//*******************************************
char dataRx;

void main() {
ANSEL = 0; // Configure AN pins as digital
ANSELH = 0;
trisd=0;
portd=0xff;
UART1_Init(9600); // Initialize UART module at 9600 bps
Delay_ms(100); // Wait for UART module to stabilize

while (1) { // Endless loop
if (uart1_data_ready())
{
dataRx=uart1_read();
if (dataRx=='A')
{
uart1_write_text("You type A");
uart1_write(13);
uart1_write(10);

}
else if (dataRx=='B')
{
uart1_write_text("You type B");
uart1_write(13);
uart1_write(10);
}
else
{
uart1_write_text("I don't understand");
uart1_write(13);
uart1_write(10);
}
portd = dataRx;
}
}
//***********************************************

And my VB code as bellow:
'************************************************
Private Sub cmdDataReceive_Click()
Dim DataReceive$
DataReceive = MSComm1.Input
txtDataReceive.Text = DataReceive
End Sub

Private Sub cmdDataSend_Click()
Dim DataSend$
DataSend = txtDataSend.Text
MSComm1.Output = DataSend
End Sub

Private Sub Form_Load()
MSComm1.PortOpen = True
End Sub

Private Sub Form_Unload(Cancel As Integer)
MSComm1.PortOpen = False
End Sub
'*********************************************

I have also attached picture of circuit but instead use 10ufF I used 22pF. I don't know this can effect or not.

Thank for helping.
 

Brownout

Joined Jan 10, 2012
2,390
I got the same things when I connected Tx and Rx wrong. Make sure you have Tx(computer) -> Rx(Pic) and Rx(computer) ->Tx(Pic)
 

John P

Joined Oct 14, 2008
2,026
One thing you can do is take the wire from the TX pin of the processor, and connect it to the RX pin. Then anything you send from the computer should be received back by the computer. This tests all the wiring and the level-conversion chip. If that test passes and the chip still isn't communicating when you put the wire back, the problem has to be in the PIC. Not powered, not programmed right, oscillator not functioning, reset always active, there's a lot of things it could be.
 

BobTPH

Joined Jun 5, 2013
8,938
John P,

It sounds like he already has it wired that way, since he is receiving on the PC what he sends on the PC. I think there is a wiring error.

Bob
 

Thread Starter

sovannarith

Joined Feb 11, 2010
18
Thank you all for your comment.
now I can find the problem it causes from wire connection. I have to connect pin 5 of RS232 to ground level. now it works fine.
Thank all again.
 
Top