Communication between MatLab and PSoC 4, through UART

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

Hi ,people. I'm try to connect PSoC 4 pioneer Kit with MatLab to graphing the data. when i receive one data the program work fin, but when add more sensor i have problem. the information was plotted is wrong, don't have coherence.

   

then, some one could give me suggestion??

   


very thanks in advance

   

happy new year..!

0 Likes
5 Replies
Anonymous
Not applicable

It is difficult to say anything about the interface unless one has seen the code on both side (PSoC 4 BLE, MATLAB).

   

But from your description, could it be an issue with the string of data sent from PSoC 4 BLE to MATLAB?

0 Likes
Anonymous
Not applicable

In the side of MatLab (which controlled the communication)

   

    fprintf(serial_PSoC,'%c','a');%with this i select which sensor I want to graphic
       pause(0.1);
    
%         variable=fread(serial_PSoC,4,'%f');
%         recepcion_ADC= str2double(variable);

   


        recepcion_ADC=fscanf(serial_PSoC,'%f');
        
        ADC(contador)=recepcion_ADC(1);      
        figure(1)
        subplot(2,2,1)
        plot(ADC,'b');

   

.......

   

 

   

In the side of Creator (which is controlled or expected to receive what data is to transmit )

   

    //CyDelay(55);
            UART_ClearTxBuffer();//clean buffer
            if(sensor_mux==1)//this work fine
            {LED_Verde_Write(0);
                UART_ClearTxBuffer();//clean buffer
                UART_PutString(volt);//char volt[5]
                
                //CyDelay(5);// delay for the bufer (don't work)
                UART_ClearTxBuffer();//clean buffer
                LED_Verde_Write(1);
            }
            else if(sensor_mux==0)
            {
                LED_Verde_Write(0);
                UART_ClearTxBuffer();//clean buffer
               UART_PutString(temp);//char temp[5]  
               
                //CyDelay(5);// delay for the bufer (don't work)
                UART_ClearTxBuffer();//clean buffer
                LED_Verde_Write(1);
            }

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

It is not a good practice to clear the UART buffers except when there was an error detected.

   

PutString() is blocking, so when there is no room in the buffer, the API will wait, interrupts must be enabled.

   

It would be easier for us to check your program when you provide us with a complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

Hi, bob and riot, sorry for delay, I was cleaning my code.
Here is both (creator and matlab).-

   

Happy new Year..!!

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Your handling of  UART still has a lot of  clear buffers() which only will lead to errors. The buffer is handled by the component when the interrupt is set to "internal" as you did for Tx.

   

Your declarations

   

    char volt[1],volt1[1],c[1];

   

only reserve one (1) byte for each variable, but you use them with sprintf() which will overwrite the variables following to your declaration. Increase the size to (more than) the required amount of the expected string.

   

 

   

Bob

0 Likes