Shop OBEX P1 Docs P2 Docs Learn Events
Another SERIN question- Help! — Parallax Forums

Another SERIN question- Help!

Don MDon M Posts: 1,652
edited 2008-09-14 22:31 in BASIC Stamp
Hi all-

I am pretty much a newbie with understanding this programming so please bear with me. I am trying to use a Basic Stamp to read DEX info from a control board.

I have the Saleae Logic analyzer to which I connected to this control board and read the communication data stream·that was done by a program in the PC through the PC serial port to this control board. I have saved some of that communication to a PDF file labeled DEX attached to this post so you can see the dialog back and forth between the control board and the PC. I am trying to mimic this process using a Basic Stamp instead of a PC. I am eventually looking to store this information to a USB memory stick using the Parallax USB Data Logger board but want to get the basics down first in just talking back and forth to the board.

My first effort is to better understand how to format and write this code to just send the initialization data and then read the returned info into the debug screen. I have also attached my first attempt at programming·for sending the info to the control board and debugging its response. I have looked through this forum and various other examples trying to piece meal something together that I can understand however I am having a tough go of it so far. What is hard for me to understand is the type of data I am looking to receive and to tell the stamp how to wait for that right data and what to do once it comes. I am very much in favor of reading any tutorials in regards to this type of project. Reading the Stamp manual helps but I don't get a full understanfding of all the "options" available for the SERIN command and what the purpose and why it does what it does type of explanation. I see in a recent post here someone trying to communicate with a weather station. I thought maybe some of that code may help and tried a few snippets of it but it did not seem to work for me.

In my first attempt here I send the board the required ENQ command to which it replies DLE 0 however I cant seem to display this on the debug screen.

Thanks in advance for everyones help.

By the way I'll mention that in the PDF file the black printing indicates the message that·would come·from the Stamp and the red indicates the response from the control board back to the Stamp.

Post Edited (donm) : 9/14/2008 3:45:15 PM GMT

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-14 15:56
    Start with a description of the serial data. That will help us.
    What's the Baud?
    What voltage levels are involved (RS232, +5V logic, +3.3V logic)?
    What signal polarity is used (normal - 1=high/0=low or inverted - 1=low/0=high)?

    Given that the Baud constant is correct, your program should send an ENQ byte and
    receive one byte. Note that the DEBUG statement is a special form of the SEROUT
    statement. The way you've written it will display the value of ioByte as a single
    character. You might want to use "DEBUG DEC ioByte,CR" to display the received
    byte as a decimal number.
  • Don MDon M Posts: 1,652
    edited 2008-09-14 16:11
    Hi Mike,

    The baud rate to the board is 9600. I can connect to this board via RS232 or TTL. Obviously I am using TTL with the Stamp. I use RS232 when its connected to the PC. Connecting to the board isn't the issue here as that does work and the board indicates on the display that something is communicating with it. I can see the traffic on my Saleae Logic- the stamp sends the ENQ (0x05) and the board replies with a DLE 0 (0x10, 0)

    I tried adding your DEBUG DEC ioByte,CR and the debug screen displays "16". Before changing it by adding the DEC formatter the debug display would show a small box character.

    What I need to do is acknowledge the DLE 0 then continue on to send the next command to the board which would be DLE (0x10), SOH (0x01) "some numbers, etc.", the another DLE, ETX and a check sum and then wait for another response from the board which would be a DLE 1.

    I know what I want to send and know what to look for in terms of a response but what I don't know is how to tell the Basic Stamp how to do it. Thats what I need help with.

    Don
  • Don MDon M Posts: 1,652
    edited 2008-09-14 16:15
    The ascii 16 displayed would be the equivalent of the DLE (Hex 10) but it doesnt show the next byte after it which should be a "0".
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-14 17:27
    Your test program doesn't show the next byte because you only read a single byte.

    To read two bytes, you can do: "SERIN Pin,Baud,[noparse][[/noparse]firstByte, secondByte]".
    You can wait for a specific character like DLE (ignoring the rest), then read what follows with: "SERIN Pin,Baud,[noparse][[/noparse]WAIT(DLE), ioByte]".

    A lot depends on how much error checking you need to do and how quickly the characters arrive. The Stamps do not buffer their I/O, so your program needs to be sitting and waiting in a SERIN statement when the character actually arrives. If you read one byte like you did and then do some testing to see what it was before you go read another one, you may miss the next character. This is particularly true at 9600 Baud where the BS2 is marginal at best for receiving. There are some 3rd party receive buffers that essentially are microcontrollers usually in an 8-pin package, that just receive serial characters and buffer them until the Stamp can take them (www.proteanlogic.com/product_periph_rs232.shtml).
  • Don MDon M Posts: 1,652
    edited 2008-09-14 17:56
    Mike,

    Thanks for your help thus far. I have been hacking together some additional code and the control board responds with the anticipated reponses. I just need some lessons on how to clean up my code. I found that if I send SEROUT TX,BAUD,[noparse][[/noparse]DEC 0] and succesive commands alike that there is a delay I notice in my Logic screen versus sending them like SEROUT TX,BAUD,[noparse][[/noparse]$30]. Seems like it takes some processing time for the Stamp to convert a hex number to decimal equivalent?

    Should I consider a different model Stamp that may be more applicable·for this application? Today would be the day to order if so.

    Anyway- I have attached my code thus far. I'll try your other suggestions.

    Thanks.

    Don
  • UnsoundcodeUnsoundcode Posts: 1,532
    edited 2008-09-14 18:18
    Hi Don, you will probably notice an improvement if you creat an array for your data before you transmit. You would need to check out the Special Formatter STR in the Pbasic help files.

    sData VAR Byte(21)· 'create the array

    sData(0) = $some_number

    sData(1) = $another_number·· 'etc. etc.

    SEROUT TX,baud,[noparse][[/noparse]STR sData\21] 'transmit all in one string

    Jeff T.
  • Mike GreenMike Green Posts: 23,101
    edited 2008-09-14 18:24
    1) Yes, the formatters take a little time to execute. You can do SEROUT TX,BAUD,[noparse][[/noparse]"0"] if you want and it does the same thing.

    2) More speed would certainly be useful in your application. You might as well get a BS2px which provides more memory and additional capabilities.

    3) You can combine SEROUT statements and save room in memory. For example, you can put

    SEROUT TX,BAUD,[noparse][[/noparse]DLE,SOH,"1234567890RR01L01",DLE,3,$de,$4d,ioByte]
  • Don MDon M Posts: 1,652
    edited 2008-09-14 20:55
    Guys- Thanks for your help. Like I mentioned earlier I am rather dense to some of this stuff at first. I know what results I need but just getting there in some sort of orderly fashion is where I struggle.

    Don M.
  • Don MDon M Posts: 1,652
    edited 2008-09-14 22:31
    Here is another try at it. I don't understand why Debug will only display the first character of the string it is receiving.
    If I try SERIN RX,BAUD,[noparse][[/noparse]WAIT(SOH),ioByte2\20] I get an error trying to download code to Stamp.

    Any ideas what I am doing wrong here?

    Thanks.
Sign In or Register to comment.