Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/25/02 18:47
Read: times


 
#26322 - SERIAL COMMUNICATION PROBLEM
I am trying to do a simple serial communication between UC and PC. I am using MsComm in VB and HIN232 for RS232 level conversion with about 1.5m long RS232 cable.

In VB side, I have used 2 command buttons. Button1 is for transmission of data given in TextBox whereas Button2 is for data reception. when a button is pressed PC connects with UC, exchanges data and disconnects.

In case of data transmission from PC to UC, PC sends data 30 while for reception it sends 31.
These values will help UC to decide whether to transmit data or to recieve data. Here are the codes I have used in VB for data reception from UC.

Dim outdata() As Byte
Dim temporary() As Byte

MSComm1.InputMode = comInputModeBinary
MSComm1.CommPort = 2
MSComm1.Settings = "1200,N,8,1"
MSComm1.PortOpen = True
MSComm1.InBufferCount = 0
MSComm1.OutBufferCount = 0

outdata = Chr(31)'transmit 31(data reception)MSComm1.Output = outdata

Do
DoEvents
If MSComm1.InBufferCount Then
temporary = MSComm1.Input 'recived data Text1.Text = Format(temporary)
Exit Do
End If
Loop
MSComm1.PortOpen = False
=============================================For transmission of data, i have used similar code as follows:

Dim data() as Byte
Dim sett as Byte

sett = Text1.Text
....
...
data = Chr(30)'transmit 30 for data transm.
MSComm1.Output = data

Do
DoEvents
If MSComm1.InBufferCount Then'wait for UC"OK"
MSComm1.Output = Chr(sett)'send data
Exit Do
End If
Loop
MSComm1.PortOpen = False
=============================================
At UC side, I have used flags in serial interrupt routine which are changed when data is transmitted or recieved. The flags are checked in an endless loop and serviced as per data.
I have used crystal oscillator of 4.43 MHz and generate 1200 baud rate using timer1 with internal clock mode.

The Codes are:

txgoing equ 07h ;bit 7 of 21
serial equ 06h ;bit 6 of 21

org 23h ;serialcom interrupt handler
push acc
push psw
jb ti,TX_OPER ;If TI is set, handle for TX

clr ri
setb serial
mov a,sbuf
mov r2,a ;store the recieved byte in r2
pop psw
pop acc
reti

TX_OPER:
clr ti
clr txgoing
pop psw
pop acc
reti
=============================================(Main Program)
Loop:
acall SERIALCOM
ajmp Loop
=============================================SERIALCOM:
jb serial,comm ;if serial=1, start com.
ret
comm:
clr serial
mov a,r2 ;load the value sent by PC
cjne a,#31,Recieve;if A=31,UC transmits data

Transmit:
mov a,#12 ;UC sends data=31
mov sbuf,a
setb txgoing
Halt1: jb txgoing,Halt1

Recieve:
mov a,#40 ;UC "OK" COMMAND
mov sbuf,a
setb txgoing
Halt2:jb txgoing,Halt2
Halt3:jnb serial,Halt3;wait for value sent
clr serial
mov a,r2;load the recieved data in acc.
mov r4,a ;store the value in R4

ret
=============================================
PROBLEM:
When I press any Command Button in VB, the computer waits for data reception and it never gets the data. I think that the UC is not interrupted with data '30' and '31' sent for serial communication although I have enable the interrupt bits.

What's the defect in the code or in the concept I have used ?




List of 8 messages in thread
TopicAuthorDate
SERIAL COMMUNICATION PROBLEM            01/01/70 00:00      
RE: SERIAL COMMUNICATION PROBLEM            01/01/70 00:00      
RE: SERIAL COMMUNICATION PROBLEM            01/01/70 00:00      
RE: SERIAL COMMUNICATION PROBLEM            01/01/70 00:00      
RE: SERIAL COMMUNICATION PROBLEM            01/01/70 00:00      
RE: SERIAL COMMUNICATION PROBLEM            01/01/70 00:00      
RE: SERIAL COMMUNICATION PROBLEM            01/01/70 00:00      
RE: SERIAL COMMUNICATION PROBLEM            01/01/70 00:00      

Back to Subject List