Wilksey
|
|
Group: Forum Members
Posts: 14,
Visits: 18
|
Hi Pradeep, The very very first thing I would do is get a 9 way D-SUB and solder pins 2 and 3 together, this will form a loopback. And then use Hyperterminal to see if you can get the serial port working properly i.e. sending ascii. Once you are happy that this is working, use VB and MSCOMM and send data in Hex and make sure you are receiving data. One thing about uC's as well which I forgot to mention, most drive using true logic and inverted logic levels, some have another mode called 'open', make sure you are using the correct logic baud setting, if you get these wrong you will end up with FF's 8F's etc in hex filling up the port, and in some cases i've noticed millions of '00' coming through! This will be in the ATMega datasheet. Make sure you turn handshaking off, uC dont care about handshaking. Pin 5 of the 9 way should be connected to ground, however i've never had trouble leaving it floating. Let us know how you get on! Hope this helps.
~Wilksey~
|
|
|
CDRIVE
|
|
Group: Forum Members
Posts: 548,
Visits: 2.6K
|
Wilksey (11/18/2008)
Hi Pradeep, The very very first thing I would do is get a 9 way D-SUB and solder pins 2 and 3 together, this will form a loopback. Actually, the commercial Loopback testers which include LED indicators Data In/Out, DTR/DSR, RTS/CTS & TC/RC are dirt cheap when puchased in the right place. It's hardly worth making your own. This isn't a loopback model but can be used in-line between the PC and the external device or a Loopback connector can be plugged into it. I have this model. This EBAY item is another in line model with DB9 connectors. The model 31D3 - 47200 shown here is the loopback model that I've had for over 9 years.
________________________________________________________________ "So much to learn. So little time to do it. Wise men know it's later than one thinks"! Mark's Syntax.Zip Pause Sub I don't answer programming questions via PMs. That's what the forum is for!
|
|
|
mvPradeepemb
|
|
Group: Forum Members
Posts: 46,
Visits: 85
|
By the way, which model USB/Serial converter did you buy? I am using FRONTech USB/Serial converter and the port works good in loopback test, but still i am receving Garbage value... One thing about uC's as well which I forgot to mention, most drive using true logic and inverted logic levels, some have another mode called 'open', make sure you are using the correct logic baud setting, if you get these wrong you will end up with FF's 8F's etc in hex filling up the port, and in some cases i've noticed millions of '00' coming through! This will be in the ATMega datasheet. The TX pin of AVR, drives in True logic, and i am receving just full of zeros as you mentioned....
|
|
|
CDRIVE
|
|
Group: Forum Members
Posts: 548,
Visits: 2.6K
|
Not that this is relevant but does this chip use the Break command? Also, please post your code. Here's some loopback code to test your converter for recognition of the Break signal. If your converter recognizes the Break signal "Break detected" will be printed to the form. ' In Module! Option Explicit Public Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
' Credits: (Milk (Sleep+Pause Sub)). (Wayne Spangler (Pause Sub)) Public Sub Pause(ByVal Delay As Single) Delay = Timer + Delay If Delay > 86400 Then 'more than number of seconds in a day Delay = Delay - 86400 Do DoEvents ' to process events. Sleep 1 ' to not eat cpu Loop Until Timer < 1 End If Do DoEvents ' to process events. Sleep 1 ' to not eat cpu Loop While Delay > Timer End Sub
' In Form
Option Explicit
Private Sub Command1_Click() Dim OutBuffer Text1.Text = "" OutBuffer = "This is the first block" MSComm1.RThreshold = 1 MSComm1.CommPort = 1 '4 ' MSComm1.InputMode = comInputModeBinary MSComm1.PortOpen = True MSComm1.Output = OutBuffer Pause 0.5 If MSComm1.InBufferCount = 0 Then MSComm1.Break = True End If Pause 0.5 MSComm1.Break = False OutBuffer = " This is the second block" MSComm1.Output = OutBuffer End Sub
Private Sub MSComm1_OnComm() Select Case MSComm1.CommEvent Case comEvReceive Text1.Text = Text1.Text & MSComm1.Input Case comEventBreak Print "Break Detected!" End Select End Sub
Private Sub Form_Unload(Cancel As Integer) MSComm1.PortOpen = False End Sub
________________________________________________________________ "So much to learn. So little time to do it. Wise men know it's later than one thinks"! Mark's Syntax.Zip Pause Sub I don't answer programming questions via PMs. That's what the forum is for!
|
|
|
Wilksey
|
|
Group: Forum Members
Posts: 14,
Visits: 18
|
Ok,
By doing a simple RX / TX crossover (solder 1 wire to 2 pins)test will prove that the port is working correctly, and as you mentioned that you conducted a loopback test I assume you have already done this.
Generally speaking we are using a dumb serial port, which simply receives and transmits data at set data rate (baud), check the Parity of the ATMega port and stop / databits if you can, though I expect you have already done this?
Can you change the logic type in the ATMega? With the RS232 I have always driven true, and in my uC (PIC18F452) I can use Open True, Open Inverted, Driven True and Driven Inverted.
As mentioned I always use Driven True.
I will have a look tomorrow and see if I can replicate the 0's racing through the port, but I am sure the reason it happened to mine is because of either:
1) Parity
2) Logic Mode
3) Oscillator frequency set wrong.
I have had a case where my software was written for a 4MHz oscillator and I replace it with a 8MHz oscillator and it messed up the timings, as well as setting a 3.7Mhz crystal to 4 MHz as opposed to 3 MHz.
Most of my debugging on the PC is done with a (Free I think) utility called Moxa Scope, it ha saved me headaches you wouldn't believe!
Check these settings and let us know.
~Wilksey~
|
|
|
CDRIVE
|
|
Group: Forum Members
Posts: 548,
Visits: 2.6K
|
When working with MSComm I've found Microsoft's Portmon to be a valuable tool.
________________________________________________________________ "So much to learn. So little time to do it. Wise men know it's later than one thinks"! Mark's Syntax.Zip Pause Sub I don't answer programming questions via PMs. That's what the forum is for!
|
|
|
CDRIVE
|
|
Group: Forum Members
Posts: 548,
Visits: 2.6K
|
Are you sure those are zeros and not what what you see when printing non printable chars (round corner squares) when in Text mode? Please post your code.
________________________________________________________________ "So much to learn. So little time to do it. Wise men know it's later than one thinks"! Mark's Syntax.Zip Pause Sub I don't answer programming questions via PMs. That's what the forum is for!
|
|
|
mvPradeepemb
|
|
Group: Forum Members
Posts: 46,
Visits: 85
|
Private Sub Form_Load() MSComm1.Settings = "9600,N,8,1" MSComm1.CommPort = 4 MSComm1.InputLen = 1 MSComm1.RThreshold = 1 MSComm1.InputMode = comInputModeBinary MSComm1.PortOpen = True End Sub Private Sub Form_Unload(Cancel As Integer) If MSComm1.PortOpen = False Then MSComm1.PortOpen = True End If
End Sub Private Sub MSComm1_OnComm() MSComm1.RThreshold = 1 Dim InBuffer As Variant InBuffer = Val("&H" & MSComm1.Input) If MSComm1.CommEvent = comEvReceive Then Text1.Text = Text1.Text & InBuffer End If End Sub I can receive only zeros and ones.....
|
|
|
CDRIVE
|
|
Group: Forum Members
Posts: 548,
Visits: 2.6K
|
mvPradeepemb (11/21/2008)
Private Sub Form_Load() MSComm1.Settings = "9600,N,8,1" MSComm1.CommPort = 4 MSComm1.InputLen = 1 MSComm1.RThreshold = 1 MSComm1.InputMode = comInputModeBinary MSComm1.PortOpen = True End Sub Private Sub Form_Unload(Cancel As Integer) If MSComm1.PortOpen = False Then ' This doesn't MSComm1.PortOpen = True ' make sense !! End If
End Sub Private Sub MSComm1_OnComm() MSComm1.RThreshold = 1 Dim InBuffer As Variant InBuffer = Val("&H" & MSComm1.Input) If MSComm1.CommEvent = comEvReceive Then Text1.Text = Text1.Text & InBuffer End If End Sub I can receive only zeros and ones..... I told you in previous posts that you must output & input binary data in a Byte Array. I also gave you code and this isn't it.
________________________________________________________________ "So much to learn. So little time to do it. Wise men know it's later than one thinks"! Mark's Syntax.Zip Pause Sub I don't answer programming questions via PMs. That's what the forum is for!
|
|
|
mvPradeepemb
|
|
Group: Forum Members
Posts: 46,
Visits: 85
|
Option ExplicitPrivate Sub Command1_Click() Dim BytesToSend(7) As Byte ' Dimensioned to 8 Bytes Dim OutBuffer BytesToSend(0) = &H49 ' = Char 'I' & Decimal '73' BytesToSend(1) = &H23 ' = Char '#' & Decimal '35' BytesToSend(2) = &H4A ' = Char 'J' & Decimal '74' BytesToSend(3) = &H4B ' = Char 'K' & Decimal '75' BytesToSend(4) = &H4C ' = Char 'L' & Decimal '76' BytesToSend(5) = &H33 ' = Char '3' & Decimal '51' BytesToSend(6) = &H6A ' = Char 'j' & Decimal '106' BytesToSend(7) = &H1A ' = EOF Char: Decimal '26' ' Bytes are outputted in the order of there Index Number(Index)! ' MSComm1.PortOpen = True OutBuffer = BytesToSend() MSComm1.Output = OutBuffer Command1.Enabled = False Text1.Text = "" End Sub Private Sub Form_Load() MSComm1.CommPort = 3 ' mscomm1.Settings = (Your Settings) MSComm1.RThreshold = 8 MSComm1.InputMode = comInputModeBinary MSComm1.PortOpen = True End Sub Private Sub MSComm1_OnComm() If MSComm1.CommEvent = comEvReceive Then Dim InBuffer Dim DimensionedByteArray(7) As Byte ' Can handle up to 8 Bytes Dim intCount As Integer Dim intDecimal As Integer InBuffer = MSComm1.Input For intCount = 0 To (LenB(InBuffer) - 1) DimensionedByteArray(intCount) = CByte(InBuffer(intCount)) intDecimal = DimensionedByteArray(intCount) Text1.Text = Text1.Text & " " & intDecimal ' Display Decimal number Debug.Print intCount Next intCount Debug.Print TypeName(intDecimal) ' Confirm intDecimal data is Integer End If End Sub Loopback test works perfect as i click the command button. But when i interfaced with controller i receive the data as 0 56 0 56 0 56 where my transmitted value is 5
|
|
|