Interspecies Communication, or,,, talking between a BS2sx and an ATMEGA
xanatos
Posts: 1,120
Hi all,
Using SERIN and SEROUT to talk to a "black box" kind of thing.
The "Black Box" (herein known as the BB), has a serial connection on it, which is NORMALLY used with a special cable containing a MAX232 chip, which NORMALLY goes to a PC Serial port, and is talked-to with Hyperterminal (9600, 8, N, 1)
Said BB is working using the normal setup as described above.
The actual raw serial terminal on the side of the box is straight TTL level serial data - the MAX-232 (unless I mis-understand the MAX-232) isn't adding any data to the string.
So I am theorizing that I should be able to use my BS2sx with regular old SERIN and SEROUT to talk to this thing.
The normal operation of the box when hooked to Hyperterminal is (after configuration the COM port with 9600, 8 N 1), is to issue a CR to the box, and the box then returns a > to the hyperterminal window.
The operator then would issue a two character command string to the box, and off it goes.
I am attaching my code below. When I SEROUT my CR, and WAIT for my ">", I get nothing. Ever.
Can anyone tell me what I'm missing?
Thanks!
Dave
Using SERIN and SEROUT to talk to a "black box" kind of thing.
The "Black Box" (herein known as the BB), has a serial connection on it, which is NORMALLY used with a special cable containing a MAX232 chip, which NORMALLY goes to a PC Serial port, and is talked-to with Hyperterminal (9600, 8, N, 1)
Said BB is working using the normal setup as described above.
The actual raw serial terminal on the side of the box is straight TTL level serial data - the MAX-232 (unless I mis-understand the MAX-232) isn't adding any data to the string.
So I am theorizing that I should be able to use my BS2sx with regular old SERIN and SEROUT to talk to this thing.
The normal operation of the box when hooked to Hyperterminal is (after configuration the COM port with 9600, 8 N 1), is to issue a CR to the box, and the box then returns a > to the hyperterminal window.
The operator then would issue a two character command string to the box, and off it goes.
I am attaching my code below. When I SEROUT my CR, and WAIT for my ">", I get nothing. Ever.
Can anyone tell me what I'm missing?
Thanks!
Dave
' ========================================================================= ' Initial communications setup/test for sercomm with cbox. ' ' {$STAMP BS2sx} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Constants ]------------------------------------------------------- #SELECT $STAMP #CASE BS2, BS2E, BS2PE T2400 CON 396 T9600 CON 84 T19K2 CON 32 #CASE BS2SX, BS2P T2400 CON 1021 T9600 CON 240 T19K2 CON 110 #CASE BS2PX T1200 CON 3313 T2400 CON 1646 T4800 CON 813 T9600 CON 396 T19K2 CON 188 T38K4 CON 84 #ENDSELECT ' -----[ I/O Definitions ]------------------------------------------------- Crx PIN 7 ' Receive Pin on Centeron Receiver Ctx PIN 6 ' Transmit Pin on Centeron Receiver ' -----[ Variables ]------------------------------------------------------- serStr VAR Byte(10) ' -----[ Initialization ]-------------------------------------------------- 'Pins: '1: GND <---- closest to reset button '2: +5V '3: GND '4: TX '5: RX <---- closest to phone jacks ' -----[ Program Code ]---------------------------------------------------- Main: DO DEBUG "Sending...",CR SEROUT Crx, T9600, [CR] ' SERIN Ctx, T9600, 2000, nuttin, [WAIT(">")] DEBUG "Prompt received", CR LOOP STOP ' -----[ Subroutines ]----------------------------------------------------- nuttin: DEBUG "nuttin...",CR RETURN
Comments
Do you have a ground connection between the BS2 and the BB, in addition to the Tx/Rx wires?
Using the MAX232 cable, can you monitor on HyperTerminal what the BS2 is sending? A "CR" is hard to see, maybe try sending a printable character "X" until that's verified.
Using the Max232 cable, can you monitor on HyperTerminal the response from the BB while the BS2 is connected? That might rule out a response other than >.
Or you could for testing change your SERIN to capture one byte and display it, to see if it's a > or something else.
Try using Inverted baud mode, in case your MAX232 isn't inverting (although it should be).
Yes, TX to RX and RX to TX verified, as well as common ground. I'll try looking at the output of the BS2 with the Max232 cable, and tapping between them as well...
I'm still thinking there's going to be a $1A or something like that showing up somewhere :-)
Thanks, I'll let you know...
Best,
Dave
Try putting a pull-up or pull-down resistor on the output of the BB. It might have a tri-state or open source/open drain driver, which is floating between characters. The time that it is floating may be interpreted by the BS2 as data, hence the garbage characters.
Dave
I don't think so. If you are not using complex formatters, and just reading into an array of bytes, the BS2sx is fast enough at 9600. Are you doing it all in one read or multiple SERIN commands? The latter would cause some bits/bytes to be missed between commands if the data stream out of the BB is continuous.
Dave
I tried the pull-up/pull-down resistor test, no change. Again, the garbled-looking data is identical for a given command sent to the BB, so I don't think it's noise, I think that this is data actually being sent from the box, but which is not read by Hyperterminal.
So I tried my BS2px, and while I got the EXACT same garbled data, I was able to read a LOT more data by virtue of the SPSTR formatter - and by putting the data into SPRAM then reading it out with GETs, I was able to pull up ALL the data. I found I have to SKIP the first 16 bytes, which contain the menu label, then SPSTR 126 bytes. WHen I display those 126 bytes, the full text of the menu is there with minimal garbage. Below is the code and an example of the output as debugged to my debug window:
And output:
z‚‚z‚‚z‚‚z‚‚
‚5
M1= *000000 0000/00/00/00/00 0000 0
00C
M2= *000000 0000/00/00/00/00 0000 000C
M3= *000000 0000/00/00
Which should look like the hyperterminal display:
M0= *000000 0000/00/00/00/00 0000 000C
M1= *000000 0000/00/00/00/00 0000 000C
M2= *000000 0000/00/00/00/00 0000 000C
M3= *000000 0000/00/00/00/00 0000 000C
This is the worst of the examples at this point - some of the control characters coming across are interpreted by the debug window as HOME or CLS which are making it difficult to capture everything here.
I'm getting closer, but still a daunting task. If anyone recognizes what's happening and has a way around it, it would be greatly appreciated!
Dave
I had a similar issue in trying to print specific data in the DEBUG screen.
Cheers,
Dave
EDIT: I just set it to only debug characters between 12 and 127 and that cleaned stuff up a lot! Still - it's odd that there are 16 bytes of STUFF that come in before the data, and that somewhere, "encoded" in that preamble, is the header text, but it is no where to be seen inside of it...
Thanks for the assistance folks! I appreciate your ideas.
Dave