Shop OBEX P1 Docs P2 Docs Learn Events
serin pin question — Parallax Forums

serin pin question

cplattcplatt Posts: 55
edited 2008-10-29 18:38 in BASIC Stamp
Sorry I'm kinda new to this.

Had great success communicating from my BS2 to PC. Now trying to go from my PC to BS2 and its harder because the stamp has no buffer probably. Figured out the R pin (serial receiving pin) is the dedicated pin on the BOE, Pin 16. What do the two lights mean that flash during serial communication? Should I set up another pin for the F pin (serial flow control), or is there an dedicated pin on the board for that also? Are there any hardware jumpers I have to do to go from the Stamp to the PC or should the BOE be all set up? Seems like the DEC command should do a great job at flow control so there should be no need.

Right now I am sending a byte from the PC to the BS2 and then WRITE(ing) it into the EEPROM, then coming back later to check it with a READ command. (the PC cannot send to the BS2 and the BS2 use the debug window to receive at the same time since they would both use the comm port simultaneously) So far I am only reading nonsense from the EEPROM though. I probably got the var size or DEC formatter screwed up somehow and reading hex or something.

serData var byte
SERIN 16, 16780, [noparse][[/noparse]DEC serData]
WRITE 0, serData

where 1234A sent from the PC, should READ 1234 right?



Thanks for your help.

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2008-10-28 10:08
    I think you're going to have to clarify a few things:

    - You're using a BS2 module on a BOE, right?
    - When you say "the two lights that flash", where are those lights? On the BOE?
    - How are you sending the bytes from the PC?

    I suggest that rather than getting EEPROM involved in this, you hook up a LED to the BS2, and write a couple of lines that toggle the LED if you receive the data you're trying to send. Test that to make sure it works when you directly put in the data (through DEBUGIN), and then use that as your indicator. Better yet, if you have an LCD, use that to display the received information.

    Speaking of DEBUGIN, is there a reason you're using SERIN instead of DEBUGIN?

    (From the Stamp Manual):

    "DEBUGIN is actually a special case of the SERIN instruction. It is set for
    inverted (RS-232-compatible) serial input through the programming
    connector (the SIN pin) at 9600 baud (19200 baud on BS2px), no parity, 8
    data bits, and 1 stop bit."
  • cplattcplatt Posts: 55
    edited 2008-10-28 15:16
    Yes, BOE, USB (virtual serial) with BS2p40. The leds are two, one red and one blue in about the middle of the board. I suspect at least one is driven low by pin 16. Haven't tried Debugin yet, it would be perfect if it pull up the debug window!! Using the led I tried, but it got very frustrating cause the only thing I could get it to tell me was the output <>0.
  • SRLMSRLM Posts: 5,045
    edited 2008-10-28 15:19
    What's wrong with just using DEBUGIN?

    Anyway, the lights flash whenever data is going past.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-10-29 00:38
    Hi, first I would lean toward using SERIN over DEBUGIN, SERIN gives you features of control over the serial port that DEBUGIN does not.

    With regard to sending data from the PC to the Stamp when using P16 (programming port) every character you send is echoed back to the PC's buffer and sent again at the next transmission, so for example if you sent·1 at the first transmission then sent·2 with the second transmission what would actually be sent at the second transmission would be 12, instead of the Stamp receiving 12 during the two sends it would receive 112. This can be overcome by emptying the buffer before each transmission, or parsing the echoed data out or using another of the Stamps pins with a RS232 line driver (which is quite an easy thing to do with plenty of examples on these forums).

    where 1234A sent from the PC, should READ 1234 right?

    Your serData is defined as a byte, a byte can only hold a value from 0 to 255.

    Which program are you using to interface to the Stamp?

    Jeff T.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-10-29 00:54
    There's no buffer on the Stamp side of the connection, just on the PC side.· When you send data from the PC to the Stamp, it will be echoed back to the PC, but the Stamp will only receive data actually sent while the Stamp is waiting in a SERIN or DEBUGIN statement.

    The PC buffer does need to be flushed out before any Stamp data is expected.· If the Stamp prefixes its messages with some unique character (like "!") not otherwise used, the PC can just ignore anything up to the next "!"
  • cplattcplatt Posts: 55
    edited 2008-10-29 13:18
    Starting to get a good handle thanks to you guys. I got everything to work sending and receiving to the stamp using Serin- couldn't ever get Debugin to work because the PC and Stamp always tried to use the COM port at the same time and would give me an error.

    First sending from the stamp to the PC was relatively easy just following the many examples if the stamp is programmed and the editor must be closed (com conflicts again). Also DTR on the PC side ComPort side must be disabled (it resets the stamp (??)) and the stamps have their own ideal baud rate that can be found in tables under the SerIn command.

    Learned that sending data from the PC using Serout the data has to be less than a byte 0-256 or a word 0-65536 (less than 256 not equal! -I know I'm no rocket scientist). With Serout the data must have a non-decimal character after the byte or word to tell the stamp to stop listening and process; ie, "255A". The stamp sees 255. The DEC command must be used on the stamp side or it will obviously interpret 255 as hex and you would get hex codes of 2+5+5. (though I could never get this). This final help was instead of writing the incoming data to the EEPROM and then reading it (again because of the aforementioned com conflicts) I just set up a LED on an unused pin. If the anticipated data came in, light up the led , and thats exactly what happened!!! Also the stamp must invoke Serin in some loop of at least once a second waiting for the incoming data or it seems to miss the PC's transmission.

    Whereas you can send alpha numeric characters directly from the stamp to the PC like "Hello World" You cannot send "Hello World" from the PC to the Stamp directly so far to my knowledge easily. All characters must be converted to decimal from ascii and then somehow a routine on the stamp to receive the info sequentially because of the size limitations.

    A final problem that I had with Serin and Serout that is mentioned somewhere is that you cannot interrupt the stamp once programmed (lock up the editor with programming errors, etc. ) or it will appear that it has been "destroyed" ("No Stamp Present"- the editor sees only and echo and loop.) This is scary to say the least, but the stamp just has to be turned off, disconnected from the PC and then reconnected and it will be found once again.

    Anyhow any further enlightenment is encouraged but I am now on the right track with great thanks to everyone in multiple threads. (Unsoundcode, Mr. Savage; I could never switch from basic to VBexpress because I had many complicated legacy modules in VB6 that I could never replace with my limited abilities, so I muddled through this in VB6 on the pc side [noparse];)[/noparse] ).

    Post Edited (cplatt) : 10/29/2008 1:28:40 PM GMT
  • allanlane5allanlane5 Posts: 3,815
    edited 2008-10-29 13:31
    Good analysis. The DTR problem is because the BS2 IDE uses DTR as a non-maskable 'RESET' to the BS2, usually in preparation for programming.

    I'm surprised that you had to power-off the BS2 to get the IDE to 'find' it again -- but if that works for you, go for it.
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-10-29 18:38
    Hi, just wanted to add that yes it is possible to send "Hello World" from the PC to the Stamp. I am used to dealing with VB Express so forgive me if there are a few errors in what I say, but with the SerialPort (MSCOMM in VB6) the data you are sending is an ASCII string unless you specifically have it set up for a byte array, so when you send the value of "1" you are sending the ASCII value 49. The DEC formatter of the Stamp is used to convert the value of an ASCII character into its respective character. So sending "23" the Stamp would see the two values 50 and 51 , your DEC formatter would be DEC2 and convert the ASCII 50 and 51 to 23 decimal.

    It is possible by using the STR formatter of the SERIN instruction with a small byte array to receive strings of 10,15 or 20 bytes depending on your memory use. For example the ASCII code for Hello is 72 101 108 108 111, one way to get this at the Stamp is SERIN RX,baud,[noparse][[/noparse]STR sData\5] then sData would hold the string "Hello" (look in the help files for clarification.)

    Lastly if you add a Line feed or a Carriage return to the end of you data it tells the Stamp SERIN that you have finished sending and to move on. So instead of sending 255A as you mentioned it·is better to send 255 10 or 13 (10 is linefeed 13 is carriage return)

    Jeff T.

    PS. Mike Green suggested using a header character such as "!" , this is a great idea if you are able to use it.
Sign In or Register to comment.