Comm between two prop boards
Rsadeika
Posts: 3,837
I am running into some problems with comms between two prop boards and displaying too a terminal via XBee. Basically I have two boards connected with a common ground wire, using P14 and P15 on the GG board, P0 and P1 on the Activity board. The Activity board is accessed via an XBee connection(P11,P10), the problem is with having strings displayed to the xbee terminal screen. Sometimes I get parts of a string, and other times I get a partial string when I try to access the GG board . I have tried using fflush(xbee) with no success, it seems that in this configuration, the XBee is not behaving as expected.
I remember at one time I had a spin program that was acting in similar way, but a specific XBee command too flush the buffers seemed to work. In this case it seems like the C fflush is not doing the job or I am not using it correctly. Anybody see what the problem might be?
Thanks
Ray
I remember at one time I had a spin program that was acting in similar way, but a specific XBee command too flush the buffers seemed to work. In this case it seems like the C fflush is not doing the job or I am not using it correctly. Anybody see what the problem might be?
Thanks
Ray
/* testAB.c */ #include "simpletools.h" #include "simpletext.h" #include "fdserial.h" serial *cGG; serial *xbee; int main() { // Add startup code here. /* Rx Tx Mode Baud*/ cGG = fdserial_open(0, 1, 0, 9600); // Connection to GG board xbee = fdserial_open(11,10,0,9600); char inBuff[40]; char inSpec[40]; while(1) { // Add main loop code here. writeStr(xbee,">"); readStr(xbee,inBuff,40); if(!strcmp(inBuff,"test1")) { writeStr(cGG,"test1\n"); //pause(50); readStr(cGG,inSpec,40); pause(50); fprintf(xbee,"%s",inSpec); //fflush(xbee); } else { writeLine(xbee,"?cAB?"); } } }
/* testGG.c */ #include "simpletools.h" #include "simpletext.h" #include "fdserial.h" serial *cAB; int main() { // Add startup code here. /* Rx TX Mode Baud */ cAB = fdserial_open(15,14, 0, 9600); // Connect to AB char inBuff[40]; while(1) { // Add main loop code here. writeStr(cAB,">>\n"); readStr(cAB,inBuff,40); if(!strcmp(inBuff,"test1")) { writeStr(cAB,"GG, sent it.\n"); } else { writeStr(cAB,"?testGG?\n"); } } }
Comments
My specific headache is the serial stuff, simpleterm_open(xxx), serial_open(x,x,x,x), and fdserial_open(x,x,x,x). These have library specific commands which cannot be used interchangeably.
simpleterm_open - here you can use commands like writeStr(xx,xx), readStr(xx,xx), ..., etc. This only works with the SimpleIDE terminal window. If you try to use it with a different assigned port, you get some very mixed results, some commands seem to work while others do not, but you get no warnings as to what is occuring.
serial_open - here you only get to use only four commands, which makes this almost useless.
fdserial_open - same thing here, you only get four commands, so why the duplication?
And the biggest concern, in the example program below, the program does work as expected, yet you get no warnings about what is not occurring. The problem, the testGG.c program sends fdserial_txChar(xx,xx) byte value which the testAB.c program using serial_rxChar(xx) to read that byte value, is not responding. When I change the code in testAB.c too use fdserial_rxChar(xx) then everything works as expected. So, is serial_rxChar(xx) corrupted or is something else going on?
It would really be nice if simpletools could use the attributes of serial_open, fdserial_open, or both. Short of that maybe we need a PropellerIDE C/C++ program.
Ray
Do you know where to find any of the documentation on serial or fdserial?
Documentation simpletext Library
Documentation fdserial Library
This is what I have to go by in the Documents library folder that appears with the last SimpleIDE install.
Ray
Function List:
Functions
fdserial * fdserial_open (int rxpin, int txpin, int mode, int baudrate)
Initializes and starts native assembly driver in a cog. More...
void fdserial_close (fdserial *term)
Stop stops the cog running the native assembly driver.
int fdserial_rxCheck (fdserial *term)
Gets a byte from the receive queue if available function does not block. More...
void fdserial_rxFlush (fdserial *term)
Empties the receive queue.
int fdserial_rxReady (fdserial *term)
Find out if a byte is ready in the receive buffer. The function does not block. More...
int fdserial_rxTime (fdserial *term, int ms)
Gets a byte from the receive queue if available by timeout function blocks if no recieve for ms timeout. More...
int fdserial_rxChar (fdserial *term)
Waits for a byte from the receive queue. blocks until somehting is ready. More...
int fdserial_txChar (fdserial *term, int txbyte)
Sends a byte on the transmit queue. More...
int fdserial_txEmpty (fdserial *term)
Find out if the tx queue is empty. More...
void fdserial_txFlush (fdserial *term)
Flush the transmit queue.
All of these functions are also available for fdserial, serial, and vgatext. These devices are all of type text_t. Andy chose to hide this fact to make it more "simple." There are certainly more than 4 functions available per device.
Either use all Simple Library functions or use stdio.h functions. Do not mix them.
Functions fprintf and fflush are designed to work with stdio.h devices, not simpletext devices.
Is there a code example somewhere that mixes fprintf and a simpletext.h device?
Ray
The reason to use writeChar/readChar is to have more maintainable code without resorting to using the huge stdio.h methods.
The device used with all writeChar or other simpletext.h functions in a single program can be changed just by changing the device open method and variable assignment. The same can be done with putChar and friends with just a few more lines of code.
If you decide to use vgatext instead of fdserial for output, that's relatively painless if you use putChar/writeChar. If you have multiple files with fdserial_txChar() in them, you would have to change every file to use another device.
serial_open() do not use a COG. The functions that you would use with fdserial_open() would generally be the fdserial*() functions, and with serial_open() you would use the functions like putChar(), writeChar(), ..., etc. So, what is the intended use for simpleterm_open() and what are the functions? And you also mentioned that you cannot mix the different functions with a specific *_open(). Also, can fdserial_open() be used with XMMC mode, or will there be some serious problems? Since it has been a long time ago that I had used fdserial with stdio.h, what is the proper way of opening up a port with that? I am very sure that I have not seen that in the Learn site.
One problem that I was seeing is when I tried to use fdserial_txChar() or writeDec() or serial_txChar() when I had used fdserial_open(), I was getting different results with each function. I guess now I have been warned, and mix and match at your own risk.
I noticed on the Learn site, there is no detailed explanation for how to use serial in the correct manner, hopefully Andy will accidentally browse here and maybe consider adding a chapter as to how to use serial, and all of the variations, in a correct and beneficial manner.
Ray