5 Replies Latest reply on Sep 21, 2015 11:33 PM by userc_43238

    Communicating with PSoC using Matlab

       I've been trying to control my PSoC code from Matlab via USBUART and have had difficulty sending data from Matlab to the chip.


      I have tried impementing both the SPIM_SAR_USB example project and CE60246 (modified for an updated USB interface). Implementing CE60246, I have tried sending data using the fwrite and binblockwrite (I don't think this second one should work).  In both cases, Matlab does not complete the transmission and freezes.


      Sending data from the PSoC to Matlab has worked fine, so long as the ..PutData() script is inserted in a forever loop. Sending a receipt acknowledgement from Matlab that would terminate the for loop and allow the program to continue is exactly what I want to do next. Has anybody had similar issues, and if so, is there a solution? 


      Thanks for reading

        • 1. Re: Communicating with PSoC using Matlab
                  Hi TImC   
          I haven't MATLAB and CE60246, however   
          I was considering something in program of PSoC.   
          [1] You can see received data by using JTAG or SWD debugger.   
          What was received data?   
          ... /* Wait for input data from PC */   
          ... while(USBUART_1_DataIsReady() == 0u);   
          ... USBUART_1_GetAll(rdBuffer);   
          ... <--- CHECK DATA HERE   
          [2] I think, this code is suspicious   
          ... sprintf((char *)wrBuffer, "The ADC_0 channel(%d) is: 0x%4x \n\r\n\r", <--- this ONE   
          ... (int)rdValue, adcReading);   
          ... PrintToUSBUART((char8 *)wrBuffer);   
          On the Matlab side, will receive two lines.   
          If so, Is Matlib work correctly?   
          This might be out of point, I'm not sure.   
          • 2. Re: Communicating with PSoC using Matlab
                    Hi PSoC73, Thanks for replying, and for the pointer. I had not considered SWD and do not have a miniprog at my disposal. The code you cite works on a puTTy-type terminal, pointing to the COM port connected to the PSoC. However, I have not been able to send a piece of data from matlab using fwrite. That said, the complementary function, fread, works fine, so long as the data to be read is transmitted repeatedly by PSoC.   
            • 3. Re: Communicating with PSoC using Matlab
                      I don know why you couldnt SWD debugging.   
              What program cable did you use?   
              Anyway, you need to isolate the problem.   
              if had no debugger, you can check it LED debug.   
              Put TestPin_write(0) and TestPin_write(1)   
              before test point and after test point.   
              • 4. Re: Communicating with PSoC using Matlab

                If you do not have a PSOC board for debugging, you can always create a simple


                UART link to PC and pass debug info over that, like variable values, port and pin states,


                etc. You can get a UART example project by right clicking unselected UART component,


                and picking "Find example project". You can add that to you workspace of open in a new


                workspace and cut and paste to your target workspace.




                Regards, Dana.

                • 5. Re: Communicating with PSoC using Matlab

                  can anyone help me whether matlab will generate a c code automatically for psoc controller?