serin pin question
cplatt
Posts: 55
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.
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
- 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."
Anyway, the lights flash whenever data is going past.
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.
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 "!"
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
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.
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.