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

04-22-2007, 09:59 PM
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.

Mike Green
04-22-2007, 10:30 PM
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 Moore
04-24-2007, 01:36 PM
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 :)

Naphtali Moore
05-03-2007, 01:44 PM
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 Green
05-03-2007, 09:07 PM
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 Moore
05-04-2007, 12:56 PM
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.