Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The problem is that both your send and receive functions are polled and blocking. When you call the receive function, it will only return after a complete message is received. Dito for the send function, but in case of send the duration is propably shorter (your program will propably only call send when there is a message to be sent, while receive can wait for days before a message arrives.</p> <p>If you require asynchronous commmunication, the best is to use interrupt based communications; at least for the receive and ideally for both send and receive.</p> <p>It is also possible to impement this using polled communications, but then you need to write a function which checks if a character is available for receive (or if tx-empty), to read/write the next character from/to the buffer.</p> <p>The advantages of interrupt based communication are:</p> <ul> <li>full duplex</li> <li>less cpu time is used (no wait loops necessary)</li> <li>less power (it allows the cpu to go to a low power/standby mode, with wakeup on interrupt; polling always requires full power)</li> </ul> <p>As a first step I advise you to implement (or get) a interrupt based receive; even when the transmit function is still blocked, it will allow full duplex operation with minimal effort. If you haven't got a os (rtos/scheduler) you'll have to think of a synchronisation mechanism. The simplest form is for your receive to handle a message if there is one available, and to return immediately if there isn't a (complete) message.</p> <p>good luck.</p> <p><strong>Edit after comments</strong> On a message-by-message basis, things may seem to work if the desktop is reacting on messages sent by the controller. If your controller has a large FIFO buffer (i.e. 64 bytes) on the receive, this may work. Most controllers I know haven't got this. Many have only a single character buffer. You can detect this using an OVERFLOW bit in the registers; if this is set, then characters were lost on receive. </p> <p>Some usecases: * you want to send 2 messages in one go (say: init + do_something). The pc responds to the first msg, but the controller is still sending and drops most of the data. * PC starts sending before controller is executing the receive() function. Data at the beginning of the packet may get lost * any drop in communication may cause a deadlock (i.e. controller and desktop are both waiting for the other end to send something.</p> <p>So to diagnose: check the overflow bit. If it is set, you have lost data and you need to work on the interrupt functions. If possible, monitor both sides (at least the state; a blink a led for send, and one for receive for instance).</p> <p>A rs232 monitor may help you (you'll need some additional ports for this. There are many (including freeware) applications which can monitor multiple rs232 ports and provide timestamps. So you can observe the order of communications. Google found me : <a href="http://www.commfront.com/RS232_Protocol_Analyzer_Monitor/RS232-Analyzer.htm" rel="nofollow noreferrer">link</a>; I've used several similar utilities in the past years.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload