This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to run the 8051 board using Matlab instead of Keil uVision

Hi.I am a student at electrical & electronics engineering.My final project is related to this topic.I have a 8051 board that has a serial communication with computer.I have a software that is written on Keil uVision programme and it works properly.My aim is to use Matlab programme instead of using Keil uVision.I tried several times and I saw that Matlab transmits the data to the 8051 board by using serial port but the board doesn't work in spite of receiving the data.I am waiting for you ideas to solve this problem.Thank you for your attention.Bye:))

  • "My aim is to use Matlab programme instead of using Keil uVision"

    What exactly do you mean by that?

    Do you want to use Matlab as a replacement IDE for uVision; ie as an editor, project manager, and build utility for your C51 source code?

    Or do you just want your running 8051 program to communicate with Matlab over an RS232 link?

    "Matlab transmits the data to the 8051 board by using serial port..."

    What data?

    "...but the board doesn't work in spite of receiving the data"

    How do you know that the board received the data?
    In particular, how are you sure that the board received the data, the whole data, and nothing but the data - ie, free from errors, omissions, and additions?

    Please explain fully what you mean by "doesn't work"
    - What does happen?
    - What should happen?
    - What have you considered so far to account for the difference?

  • How could you use Matlab instead of Keil?
    Do you meam that you wanna use Matlab instead of hyper-terminal?

    You can write a Matlab script to send data over serial connection just by means of several commands to establish the connection. While Matlab 6.5 has some problem with closing the connection in my case.
    You can refer to the following code (written by me. not sample code:) )

    %fid = fopen( filename, 'rt');
    if ( fid == -1 )
        disp( [ 'Fail to open ' filename ] );
        return;
    end;
    fid2 = serial( 'COM1', 'BaudRate', 57600);
    fid2.timeout = 3;
    %fopen( fid2 )
    message = fid2.status;
    if ( message(1) ~= 'o' )
        disp( [ 'Fail to open COM1'] );
        return;
    end;
    

  • "When only matlab program is running(Keil is inactive) we measured the data from serial port by using an oscilloscope,we saw that an information transmitted but we don't know if it is the real command or not."
    http://www.keil.com/forum/docs/thread7219.asp

    Use a terminal (or a terminal program on a PC; eg, Hypoterminal) to check what is being sent.

    "But if we run the Keil we don't know if Matlab transmits the data or not."

    You can have the Keil simulator use the PC's COM port for its simulated serial input and output.
    See the Manual for details.

    Run your 8051 code in the Keil simulator, with the simulated UART IO directed to a COM port.
    Now connect the COM port used by Matlab to the COM port used by the uVision simulator - using a suitable cross-over cable.
    If you don't have two COM ports on the same PC, you will need to use two PCs!

    You now have your 8051 code running in the uVision simulator and communication over RS232 with Matlab. Happy debugging!

  • our board controls a cnc machine that has ability to move in three axises. ın z axis it can drill pcb cards. and we have programs that are written in C language. And these C programs are loaded to keil. So for example when we write a command "circle" with its parameters(i.e centre and radius) the cnc machine draws a circle with the given centre and radius. Here we want to do this by using Matlab.So we want our running 8051 program to communicate with Matlab over an RS232 link.The data is the commands like circle,line,freemotion etc.. that is written on Matlab as a string.
    I wrote a matlab code to transmit the data to the board like this:

    s = serial('COM1')
    fopen(s)
    fprintf(s,'freemotion')
    fclose(s)
    delete(s)
    clear s

    By running this code we expect to run the cnc machine properly.
    When only matlab program is running(Keil is inactive) we measured the data from serial port by using an oscilloscope,we saw that an information transmitted but we don't know if it is the real command or not.
    But if we run the Keil we don't know if Matlab transmits the data or not.

  • Well done - you got there!

    Did you notice my previous reply? (see above)

  • I think you need to make sure you have set up your baud rate properly in matlab and in your keil program. You can use the set() function in matlab to set the baud rate as well as other parameters like parity, etc. Or you can see the Matlab code that Vincent posted. The parameters you set up in matlab should match the ones you have setup in keil. The matlab script you provided does not do this.

    Andrew has a good idea of using the Keil Simulator to test this before you try it on the real hardware.

  • the baudrate values for keil and matlab are the same and equal to 9600. But when we run the matlab program it gives an error as below

    warning: a timeout occured before the terminator was reached

  • From http://www.keil.com/forum/docs/thread7205.asp

    "the baudrate values for keil and matlab are the same and equal to 9600."

    Baud rate is not the only thing: You must have all settings identical including parity, number of bits, etc, etc,...

    "But when we run the matlab program it gives an error as below

    warning: a timeout occured before the terminator was reached"


    OK - just read that literally:

    "a timeout occurred" - means that it was waiting, and had waited too long, so it gave up.

    "before the terminator was reached" - it was expecting some sort of "terminator", but didn't see it.

    So, the possibilities are:

    1. The timeout is too quick - you must allow enough time for your 8051 to send whatever it sends.

    2. The 8051 didn't send anything

    3. The 8051 sent the wrong thing

    4. The 8051 did send the right thing, but Matlab either didn't receive it at all, or received it incorrectly

    5. The 8051 did send the right thing, and Matlab did receive it, but your Matlab program has a bug and didn't recognise it.

    etc, etc, etc,...


    You need to adopt a systematic approach, taking just one step at a time, and identify precisely what is and isn't happening.

    At the moment, you just have far too many variables in the equation!!

  • I couldn't solve this problem below:
    warning: a timeout occured before the terminator was reached.
    i cannot stop my matlab programme.this error occurs all the time than i can only do Ctrl+Alt+Delete to stop it.

    I think my matlab programme runs but don't see a terminator to stop.So what is terminator and how can i add it to my programme to solve this problem.
    Do İ have to add a terminator code to the programme in uvision2 that is written by using c programme?
    When i read the matlab help i saw terminators as CR and LF.What are they and what is the difference between them?How can i add them to my programme?
    Thank you for your attention!!

  • Now you're asking Matlab questions - so you need to ask Matlab.