BS2: Pls advice in a problem of communications
merlin
Posts: 40
Hi all, I am trying to communicate my BS2 with a device via serial protocol.
The device's manual declares:
"Data communications and control are accomplished using 3 wire synchronous serial interface:
Signal................Description..............................DEVICE =>BS2........................BS2=>DEVICE
DATA................Bidirectional Data Line.............. Data valid when SHS=0..........Data valid when MHS=0
MHS................Master Handshake...................... 0 = Data bit Valid....................0 = Data bit Accepted
........................(BS2 => Device)
SHS................Slave Handshake..........................0 = Data bit Accepted.............0 = Data bit Valid
........................(Device => BS2)
Data is transferred one bit at a time with full handshaking as follow:
1.- When BS2 has data to transmit, the BS2 sets DATA to the data value, verifies that SHS is in the HIGH state, then sets MHS to the LOW state to request a transfer.
2.- The Device senses the LOW state of MHS and reads DATA, which then seets SHS to the LOW state to acknowledge the DATA.
3.- BS2 senses the LOW state of SHS and sets MHS to HIGH state to indicate that DATA is no longer valid, and at the same time sets DATA HIGH releasing it.
4.- The Device then sets SHS to the HIGH state to indicate that the cycle is complete. Both device and BS2 are ready to transfer a new bit.
Due my lack of knowledge about this issues, I didn't get communication between the Device and BS2 using SHIFTIN / SHIFTOUT.
I really appreciate advices in the correct use of the SHIFTIN/OUT sentences in order to get Data transfer here.
Thanks in advance
daniel
The device's manual declares:
"Data communications and control are accomplished using 3 wire synchronous serial interface:
Signal................Description..............................DEVICE =>BS2........................BS2=>DEVICE
DATA................Bidirectional Data Line.............. Data valid when SHS=0..........Data valid when MHS=0
MHS................Master Handshake...................... 0 = Data bit Valid....................0 = Data bit Accepted
........................(BS2 => Device)
SHS................Slave Handshake..........................0 = Data bit Accepted.............0 = Data bit Valid
........................(Device => BS2)
Data is transferred one bit at a time with full handshaking as follow:
1.- When BS2 has data to transmit, the BS2 sets DATA to the data value, verifies that SHS is in the HIGH state, then sets MHS to the LOW state to request a transfer.
2.- The Device senses the LOW state of MHS and reads DATA, which then seets SHS to the LOW state to acknowledge the DATA.
3.- BS2 senses the LOW state of SHS and sets MHS to HIGH state to indicate that DATA is no longer valid, and at the same time sets DATA HIGH releasing it.
4.- The Device then sets SHS to the HIGH state to indicate that the cycle is complete. Both device and BS2 are ready to transfer a new bit.
Due my lack of knowledge about this issues, I didn't get communication between the Device and BS2 using SHIFTIN / SHIFTOUT.
I really appreciate advices in the correct use of the SHIFTIN/OUT sentences in order to get Data transfer here.
Thanks in advance
daniel
Comments
You can implement what you need using discrete statements like this shsPin, mhsPin, and dataPin are declared using the PIN declaration
bitNum and dataValue are byte variables declared using the VAR declaration
This will probably send a bit in about 3 to 5ms with a BS2.
Thank you very much for the response. I would never arrives to this solution by myself, but now I see and I found a very logical approach. I will implement it in a few hours and hopefully I will report this issue as solved!
I guess the DataIn and DataOut scenarios will be arranged with the aproppiate changes into values of shsPin and mhsPin as the Device protocol declares, is that rigth?
You said one bit will take about 3 to 5 ms...you mean one bit or one byte?
Best regards and thanks again
daniel
One bit will probably take about 3 to 5ms. I base that on timings provided here. You click on the app-note link at the bottom of the page. A lot of simple operations take a couple of hundred microseconds on the BS2.
I'm having some problems on my practical implementation: I am trying to send a code to the device (Hex30) because the device HAS to respond to this code, but nothings happens.
The code I wrote is:
' {$STAMP BS2px}
' {$PBASIC 2.5}
bitNum VAR Byte
dataValue VAR Byte
shsPin PIN 2
mhsPin PIN 1
dataPin PIN 0
dataPin = $30 ' asign a value to dataPin in order to be transferred
HIGH shspin
LOW mhspin
GOSUB call_device
END
'
sub-routine
call_device:
FOR bitNum = 1 TO 8
dataPin = dataValue >> 7
dataValue = dataValue << 1
waitForSHS1: IF shsPin = 0 THEN GOTO waitForSHS1
LOW mhsPin
waitForSHS0: IF shsPin = 1 THEN GOTO waitForSHS0
HIGH mhsPin
HIGH dataPin
NEXT
RETURN
Is this the rigth way to call the routine? Am I using the correct values of mhs and shs?
Pls take a look to the code and give me another tip to follow....thanks and regards
daniel