Shop OBEX P1 Docs P2 Docs Learn Events
Full Duplex Serial Com with Propeller C and Matlab Issues — Parallax Forums

Full Duplex Serial Com with Propeller C and Matlab Issues

cdkappycdkappy Posts: 4
edited 2015-03-25 11:46 in Learn with BlocklyProp
Hello, I am somewhat new to serial communications but did go through the half and full duplex serial lessons in Simple IDE. I am trying to use the Propeller Quick Start board as a data acquisition device and Matlab on my PC as the interface device and place to store the files. In my setup, Matlab needs to send some basic config (sample rate, channels to collect...) info and the start/stop flag. Using full duplex communication seemed to be the way to go. I have successfully connected and sent data both ways. My problem occurs when I use certain combinations of commands. The relevant part of my code looks like this:

// Matlab = fdserial_open(31, 30, 0, 115200); //
// int GetStart = fdserial_rxChar(Matlab); [/B] // This line receives a numeric 1 from Matlab. It comes out in ASCII format which I can handle
// dprint(Matlab, "%d\n", GetStart); // I'll get back a 49 in Matlab which is not a big deal for what I using this for
// int CollectInterval = readDec(Matlab); // This line is supposed to get the sample rate in ms from Matlab (no decimal, just an integer) I used this function since I needed to read more than one byte and have it formatted as a number I can directly use. However, this line seems to mess up the communications. Not sure but when I comment it out and run with a value of CollectInterval set in the Propeller program the rest of the program function properly.
// dprint(Matlab, "%d\n",CollectInterval); // Properly sends value to Matlab when set in the Propeller program.
// while(1)
// {
// dprint(Matlab, "%.1f %.1f %.1f %.1f %.1f %.1f %.1f %.1f\n", Temp[0],Temp[1],Temp[2],Temp[3],Temp[4],Temp[5],Temp[6],Temp[7]);
// } // This sends data beautifully to the Matlab object. when the I don't use readDec(Matlab) function. Is this function not usable when in full serial duplex??

This next question is broad and maybe a cry for help but is there a better way to read in data in full duplex mode other than one byte at a time?

Thanks!

Comments

  • cdkappycdkappy Posts: 4
    edited 2015-03-25 09:20
    So rather than work with Matlab for my serial interface, I did get the software shown above to work with the Simple IDE console. Not sure why Matlab would hang up reading in from the Propeller using the 'readDec()' Propeller function. Matlab is attempting to read after its transmit but returns timeouts from its (Matlab) 'fscanf()' function. Bottom line this apparently isn't a Propeller issue. If anyone with experience in this area has any suggestions, it would be greatly appreciated.
  • Keith YoungKeith Young Posts: 569
    edited 2015-03-25 09:41
    I won't have time to look in to this for at least a week, but I'm interested in trying it. I have Octave rather than Matlab, but hopefully I can have a go at it. Maybe someone else here can help you sooner than that.
  • cdkappycdkappy Posts: 4
    edited 2015-03-25 10:43
    Thanks Keith. Since I can interpret bytes one at a time using the Propeller 'fdserial...()' functions and convert them using atoi() and itoa() Propeller C functions and they don't seem to hiccup Matlab, that will be the way to go for now. I'm glad you mentioned Octave. I forgot all about it. Ultimately my project will be run from a Linux computer. My intent was to write the interface software (on the Linux computer) in C. I am using Matlab now because it is easiest (for me) to get started with because of their available libraries. However, I don't want to buy another Matlab license so would be very interested in what you find even if I do a work around for now. Thanks again. The direction of my project just changed somewhat!
  • edited 2015-03-25 10:50
    Hello cdkappy, Are you using readDec or writeDec to send to MATLAB's fscanf function? The writeDec function will transmit a character representation of a decimal value that MATLAB's fscanf should be able to receive. If it doesn't work as-is, try appending it with a terminating character or string.
  • cdkappycdkappy Posts: 4
    edited 2015-03-25 11:46
    Thanks Andy, that was it! So adding a '\n' to the Matlab function format of 'fprintf(obj1, '%d\n', DataRateMS);' resolved the issue. I'm assuming the Propeller 'readDec()' function is waiting for the whole stream and only "knows" the stream is finished when it sees the return symbol. 'readDec()' has no timeout. Matlab doesn't know this and continues on expecting the Propeller program has moved on as well. I will sleep well tonight :-)
Sign In or Register to comment.