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.

spi to rs232 coverter

Status
Not open for further replies.

nikolai_dlsu

New Member
hi! we have an ADIS16350 sensor which has a SPI compatible interface. we want to convert the sensor output to rs232 interface because we will be using rs232 in our own GUI in visual basic 6.0. does anybody know how can this be done? thanks:)
 
You can also use the PC serial port to bit bang SPI in VB by using the handshake lines. As long as your comfortable with the windows API then have a read of .

Mike.
 
vb6 experts

Is there anyone here, from the philippines who can help us in the visual basic part of our thesis? We really need help!!! Thanks a lot!!!
 
You could bit bash the SPI device using your PCs parallel port, if you're using XP you need a special DLL to get access to the port though.
Else like the other posts said you'll need something to make the SPI data RS232 compatible. Any small microcontroller could do it.
 
Pommie said:
You can also use the PC serial port to bit bang SPI in VB by using the handshake lines. As long as your comfortable with the windows API then have a read of .

Mike.

hi Mike,
I use Visual Basic 5 programs to emulate 'SPI' on the PC's parallel port to work with SPI external devices.

The MCP3202/04 12bit ADC works OK, with a couple of LM35 makes a nice and simple dual temperature measurement system.

Regards
 
hi nikolai_dlsu,

Extracted from my program, the working parts of the VB5 SPI code.

You should be able to paste the routines into VB6 OK.

Code:
'PC parallel port working with MCP3302 SPI device
'
option explicit

Dim CmdStr0, CmdStr1 As String
Dim Ary(24) As Long

'port addresses
Const Po378 = &H378, Pi379 = &H379, P37A = &H37A, P37B = &H37B

'command string for MCP3302 SPI
CmdStr0 = Trim("000000011000000000000000") ' chn0
CmdStr1 = Trim("000000011100000000000000") ' chn1

Const EhDhCh = 7 'cs hi, do hi, clk hi'' ready state
Const ElDhCh = 3 'cs lo, do hi, clk hi
Const ElDhCl = 2 'cs lo, do hi, clk lo
Const ElDlCh = 1 'cs lo, do lo, clk hi
Const ElDlCl = 0 'cs lo, do lo, clk lo
Const Dinp = &H80 '' '0000,0001_1000,0000_0000,0000

'-------------------------------------
Private Sub Form_Load()

Form1.Show

MakePwrAry
 
CmdStr0 = Trim("000000011000000000000000") ' chn0
CmdStr1 = Trim("000000011100000000000000") ' chn1


End Sub
'---------------------------------
Private Sub ReadSPI()
DoEvents

Out Po378, ElDhCh

'send  data bits to ADC msb 1st
For p = 1 To 24
If Mid$(CmdStr0, p, 1) = "1" Then
Out Po378, ElDhCh
Out Po378, ElDhCl '''ClDh
Out Po378, ElDhCh ''ChDh
Else ' lo
Out Po378, ElDlCh
Out Po378, ElDlCl ''ClDl
Out Po378, ElDlCh ''''ChDl
End If


V = Inp(Pi379) And Dinp
     If V <> Dinp Then
     ADCValue1 = ADCValue1 + Ary(p)
     End If
Next p

Out Po378, EhDhCh

End Sub

'-----------------------------
Private Sub MakePwrAry()
'precalculate weighting for array when ADC is read,
Dim p As Long

p = 1
For z = 24 To 13 Step -1
Ary(z) = p
p = p * 2
Next z

For z = 12 To 1 Step -1
Ary(z) = 0
Next z
End Sub

EDIT:
Added a zip file, shows port connections.
Place the DLL's in the Windows\System folder.
 
Last edited:
You're best off simply having a microcontroller receive the data and immediately output the same data using the UART peripheral. This will take advantage of hardware peripherals to remove any need for bit banging, which will make the job simpler.
 
SPI to RS232 convertor

Dear ericgibbs
The code giving me error "invalid outside procedure" when i m trying ro run the ur code..as i m very new to VB6.0 and very urgent need the SPI to RS232 convector as i have one 24-bit ADC ADS1240E which has SPI interface.
Kindly guide me to communicate this ADC..Advance 100000++ thanks..please prove me solution , i will be very thankful to u or anybody can guide me ..please.
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top