Shop OBEX P1 Docs P2 Docs Learn Events
commented code for the full duplex serial communication protocol! — Parallax Forums

commented code for the full duplex serial communication protocol!

gandolfgandolf Posts: 3
edited 2009-04-08 12:33 in Propeller 1
Gentlemen i am working on this application where in i have to connect a bluetooth module to the propeller. I was trying to understand how the serial protocol works and the commenting in the code posted in the website is insufficient .
I would appreciate it if anyone could help me out by providing me a completely commented code for the above mentioned protocol.........

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-08 04:36
    You will get more help and faster help by asking specific questions and providing information specifically about what you know and what you understand.

    The Simple_Serial object from the Propeller Object Exchange is probably the simplest serial interface you will find for the Propeller. It's all written in Spin and can handle roughly 19.2KBaud. You can easily add receive buffering to it and run a copy in a separate cog for buffered reception. There are several other serial drivers that use assembly to provide buffering, higher Bauds, and multiple serial ports in one cog. Since the Spin interfaces for all of these are very similar, they can generally be substituted for each other with minor changes if any.

    You are not likely to get a "completely commented code". Most of the experts who respond here are volunteers and are much more likely to answer well asked questions than to spend time and effort producing a "finished document". There's nothing wrong in asking ... sometimes volunteers become inspired and take on a mostly thankless time-consuming task, but you will do much better following the above suggestion.
  • gandolfgandolf Posts: 3
    edited 2009-04-08 05:18
    Thanks for the advice mike. I'll be specific from now onwards... In the simple serial interface code i have the following doubts
    1. in the first method
    PUB start(rxpin,txpin,mode, baudrate)
    stop
    longfill(@rx_head,0,4).........................what exactly is @rx_head here(address of what)?

    we reserve 4 long memory locations from the starting address @rx_head, what are we reserving this for?

    2. In the second method

    Pub Stop

    if cog
    (cogstop~ -1)
    longfill(@rx_head,0,9)..........here when freeing a cog we set 9 long memory location staring from @rx_head to 0, why 9 long memory locations staring from @rx_head?

    what do long memory locations rx_head,rx_tail, tx_head, tx_tail, rxtx_mode contain?
  • Mike GreenMike Green Posts: 23,101
    edited 2009-04-08 05:39
    1) Look in the VAR section. You'll see a group of variables. rx_head is the first of a group of 9 long word variables. The LONGFILL statement initializes the first 4 of these variables to zero. The address of the first variable is passed to the assembly cog and it references the whole group of variables using the address of the first.

    2) The LONGFILL in the stop method just reinitializes the 9 long word variables that are passed to the assembly routine. The assembly routine is stopped at this point, so it's not vital to reinitialize these, but it's cleaner to do so.

    rx_head: output index of the current receive buffer (data gets removed from the buffer at the output index position)
    rx_tail: input index of the current receive buffer (new data gets put in the buffer at the input index position)
    tx_head: output index of the current transmit buffer (data gets removed from the buffer at the output index position)
    tx_tail: input index of the current transmit buffer (new data gets put in the buffer at the input index position)
    rx_pin: a copy of the rxpin parameter to the start method
    tx_pin: a copy of the txpin parameter to the start method
    bit_ticks: CLKFREQ / baudrate, calculated from the baudrate parameter to the start method
    rxtx_mode: a copy of the mode parameter to the start method
    buffer_ptr: the address of the receive buffer (the transmit buffer follows the receive buffer)
  • T ChapT Chap Posts: 4,223
    edited 2009-04-08 06:24
    You may come out better with more of an approach of determining what you want to do first, then work backwards towards the answer, rather than trying to understand the objects and their innerworkings first. Just my experience with the Prop and Spin at least. There are lots of examples of serial com in the forums, and on some of the objects as well.


    If you haven't already found it,

    http://forums.parallax.com/showthread.php?p=562370

    this search tool will help you dig through the forum easier.

    Post Edited (TChapman) : 4/8/2009 6:30:14 AM GMT
  • gandolfgandolf Posts: 3
    edited 2009-04-08 12:33
    Thanks mike ........If i have any questions i will post them online .....thanks for the help again.
Sign In or Register to comment.