8 Replies Latest reply on Mar 30, 2018 1:18 AM by ameya_mahajan_2724956

    PSoC 4 UART communication with ESP8266

    ameya_mahajan_2724956

      Hello,

       

      I am using Cypress PSoC 4, CY8CKIT-042-BLE, CY8C4248LQI-BL583 and ESP8266.

       

      I want these two modules to communicate with each other through UART.

       

      I am unable to send a complete string, for example, a 15 bytes string. I want to use the parameters of the string in the application.

       

      But, the complete data between them. I tried using APIs- UART_UARTGetByte() and UART_UARTGetChar(), if I wanted to receive data from the ESP which it prints serially.

       

      And used UART_UARTPutString() &  UART_UartPutChar() when I want to put string on serial port of ESP.

       

      It's not working.

        • 1. Re: PSoC 4 UART communication with ESP8266
          user_24585443

          Hello,

           

          Could you be a bit more specific, please?

          Have you tried the communication separately with PC terminal SW? PSoC <> PC and ESP <> PC? Do the modules share the same power supply or at least a common ground?

           

          Also, different ESP8266 come with different firmwares and bugs. I personally had a bad experience and would buy some solid wireless module with the manufacturer's support.

           

          David

          • 2. Re: PSoC 4 UART communication with ESP8266
            ameya_mahajan_2724956

            Hello David,

             

            Thank you for replying.

            Yes, I checked PSoC<>PC and ESP<>PC on TeraTerm. Both are working.

             

            The PSoC is set at 3.3V and ESP through PC.

             

            The data gets transmitted but only partially.

            • 3. Re: PSoC 4 UART communication with ESP8266
              user_24585443

              Hello,

               

              Could you share your archived project and attach a screen shot of the terminal, what is sent and what not?

               

              You say PSoC<>PC sends all bytes, but PSoC<>ESP doesn't send everything?

               

              David

              • 4. Re: PSoC 4 UART communication with ESP8266
                ameya_mahajan_2724956

                Hello,

                 

                Sorry for late reply. But, I later tried by using interrupt, but I am not getting the complete string. Attached Screenshot COM 1 is ESP and COM11 is Arduino Uno (Connected to PSoC).

                 

                Thanks in advance.ESP PSoC.jpg

                • 5. Re: PSoC 4 UART communication with ESP8266
                  user_1377889

                  Can you please post your 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

                  • 6. Re: PSoC 4 UART communication with ESP8266
                    moniosni_1404216

                    Are you using the Arduino IDE for the ESP8266?

                     

                    I have achieved bidirectional (PSoC 4 <-> ESP8266) communication using the Arduino IDE to program the ESP8266.

                     

                    From the side of PSoC, I used sprintf() to make my sequence a string, and then i sent it to ESP using UART_UARTPutString() .

                     

                    For example, I have a variable char str[32] and I use in my main:

                     

                    sprintf(str, "%1.5lf", 3.14);

                    UART_UARTPutString(str);

                    UART_UARTPutString("\r\n");

                        

                     

                     

                     

                    From the ESP side, I created this scetch that reads incoming messages:

                     

                     

                    void loop()

                    {

                         while (Serial.available () > 0)

                             processIncomingByte (Serial.read ());

                    }

                     

                    void processIncomingByte (const byte inByte)

                    {

                         static char input_line [MAX_INPUT];

                         static unsigned int input_pos = 0;

                     

                          switch (inByte)

                          {

                               case '\n':   // end of text

                               input_line [input_pos] = 0;  // terminating null byte

                        

                               // terminator reached! process input_line here ...

                               process_data (input_line);

                        

                               // reset buffer for next time

                               input_pos = 0;

                               break;

                     

                     

                               case '\r':   // discard carriage return

                               break;

                     

                     

                             default:

                             // keep adding if not full ... allow for terminating null byte

                             if (input_pos < (MAX_INPUT - 1))

                                 input_line [input_pos++] = inByte;

                             break;

                        }  // end of switch

                    } // end of processIncomingByte

                     

                     

                    void process_data (const char * data)

                    {

                         Serial.println (data);

                    }  // end of process_data

                    • 7. Re: PSoC 4 UART communication with ESP8266
                      Mark Hastings

                      When I get odd behavior using sprintf() or scanf() I would increase the heap size.  Also check the size of your input/output buffer and any string arrays you are using to make sure they are at least a few bytes bigger than you need.  I don't know how many times I have seen people use exactly the same size buffer as the length of the string forgetting about the terminating zero.  When your string exceeds the size of the array, weird things can happen depending on the order of your defined variaibles, and it may even almost work for a while.

                       

                      Sorry if the above suggestions seem too trivial, but when things don't make sense I start looking for the simplest of mistakes.  Often I even get too stubborn to look for them and waste time.

                       

                      Mark

                      • 8. Re: PSoC 4 UART communication with ESP8266
                        ameya_mahajan_2724956

                        Hello,

                         

                        Thank you everyone for taking time and replying to the question.

                         

                        The issue is resolved.

                         

                        I didn't use any ISR for the code.

                         

                        I did something like this:

                        while(1)

                        {

                        if((UART_UartGetChar)!=0)

                                {

                                    x = UART_UartGetChar();

                                    InBuffer[0] = x;

                                  

                                   //did_stuff

                         

                         

                                           UART_UartPutString(InBuffer);

                                            UART_UartPutString("\n\r");

                                            UART_rx_ClearInterrupt();

                                  }

                        }

                        UART rx-tx buzzer size increased to 100 and nothing else changed in the UART SCB Block.