Shop OBEX P1 Docs P2 Docs Learn Events
Serial problem, Does reading and writing i.e opening file from PC constantly re — Parallax Forums

Serial problem, Does reading and writing i.e opening file from PC constantly re

boonboyboonboy Posts: 10
edited 2007-05-04 05:56 in BASIC Stamp
Hello again guys. Im using fopen and fread to send data to the bs2, fwrite works fine it sends the data to the bs2 and I get a response over debug window. But the bs2 seems to only do this once then not again. It looks like the bstamp is being reset , I read a couple of posts ago about the bs2 being reset on a file open, some line or other being set high and resetting the bs2, could this be my problem. Could I be getting a reply and then my device being reset/wiped so no more writes or reads are available. If this is so is there a buffer where the value sent from my serout could be retrieved and also is there a way to get round this problem.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-04-22 15:30
    If you are using the programming port for your connection (and it sounds like that's what you're doing), the Stamp will be reset when the port is opened and closed because the DTR line is toggled and that is used during programming to reset the Stamp. Serial I/O on the Stamp is not buffered. You have several choices:

    1) Use a serial cable or jumper cable or adapter that has DTR disconnected. You use a normal cable/adapter for programming the Stamp.

    2) Use another set of pins on the Stamp for your data connection to the PC. The PBasic manual shows how to do this in the section on the SERIN/SEROUT statements. It requires a resistor in series with the serial input line (and I suggest a 470 ohm resistor in series with the serial output line as well in case there's an error in connecting the Stamp or a program bug).
  • Naphtali MooreNaphtali Moore Posts: 42
    edited 2007-04-24 06:36
    Hmmmm.... I working on the same thing but using ReadFile and WriteFile.... anyways... I have not noted the BS resetting when I use CreateFile to open the port. I am using a BOE for testing and have included a simple LED on pin 15. When the stamp restarts the LED flashes 10 times. So I know when the program has restarted. Please keep us updated with any success you may have [noparse]:)[/noparse]
  • Naphtali MooreNaphtali Moore Posts: 42
    edited 2007-05-03 06:44
    MIKE,
    I have a normal straight through cable. If I cut out the DTR pin would it then work for SERIN/SEROUT communication. OR do i have to loop the DTR back on another line in the cable?
  • Mike GreenMike Green Posts: 23,101
    edited 2007-05-03 14:07
    Unless the PC end requires it (not normally), you only need the receive data, transmit data, and a ground. For your data, cutting the DTR pin would work. As I mentioned, you'd have to swap cables to download programs.
  • Naphtali MooreNaphtali Moore Posts: 42
    edited 2007-05-04 05:56
    Great. Thanks Mike! Now to decide if I want to just cut the pin or to build an adapter with a switch on DTR. I thinks its time for a trip to Radio Shack, hehe.
Sign In or Register to comment.