November 23, 2024, 03:14:21 AM

News:

Got VSA?  Want to use your Prop-SX?  Now you can!  See the VSA section of the Library forum for Prop-SX code that works with VSA.


Serial Communications between Propeller and a Prop2

Started by bsnut, July 22, 2011, 08:25:43 PM

Previous topic - Next topic

bsnut

I am working on coming up with test code for my project that I am currently working on and want to make sure the I coded it is going to work. I also want to see, is there a need to buffer the incoming data at the Prop2?

I  also think this would be helpful to talk about this, since the HC-8 is a Propeller base product and will provide basic test code for everyone else.

Below is the test code that I was thinking about doing.

Propeller code:

serial.tx(number)


Prop2 code:

Main:
  SERIAL Sio, baud, timeout, fail, [DEC number]
  DEBUG CR, "Test ok: ", DEC number
  GOTO Main

Fail:
  DEBUG CR, "Test fail", CR
  GOTO Main
William Stefan
The Basic Stamp Nut

JonnyMac

You probably need to do something like this:

serial.dec(number)
serial.tx(13)


...on the Propeller end.  You need to convert the number to its character reprentation for using DEC on the BS2 end.  It also needs a non-digit character for termination, hence the 13 (CR) after the string.
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

Ok, I see how it's setup now and noticed this in my Propeller book. But, I didn't think it was not needed and tough whatever that was in the "number" variable was transmitted. 

So how many ms do I need for the constant "timeout"?
William Stefan
The Basic Stamp Nut

JonnyMac

That's entirely up to you and what you're trying to accomplish.  Without the timeout value, you're sitting on the SERIN; with it, you could break away and miss the message from the Propeller.  Since the Propeller buffers serial and won't miss a message, I suggest that you have the BS2 "ask" the Propeller for data when it's needed.
Jon McPhalen
EFX-TEK Hollywood Office

bsnut

That's what I though. I am going to try 50 ms, which gives more than a enough for propeller to send its information. I may lower it down after the first test works.
William Stefan
The Basic Stamp Nut

JonnyMac

July 23, 2011, 05:44:12 PM #5 Last Edit: July 23, 2011, 05:45:43 PM by JonnyMac
You can determine the length of the message:

  time = bytes x 10 x (1 / baud)

At 38400 it takes 26 microseconds to send a bit or 0.26 milliseconds to send a byte.  When your BS2 SEROUT command is finished the Propeller will have buffered the message (so long as you don't overrun the buffer size).  You only have to account for the "turnaround" of the message; this gives the Propeller enough time to process your command and prepare the response.  As long as the first byte of the response appears before the timeout expires, you're fine.

BTW, the FullDuplexSerial object also allows for a timeout.  We use this in the AP-16+ to handle a "broken" message (i.e., we get the start of a message but it never finishes)
Jon McPhalen
EFX-TEK Hollywood Office