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

PSoC™ 5, 3 & 1 Forum Discussions

Y_r
Level 4
Level 4
50 replies posted 50 sign-ins 25 replies posted

EDITED:

Hello @EvPa_264126 ,

I have used your response from this link, as a start for my firmware interfacing to the ESP-8266 with PSOC5 LP.
But I am having an issue with the WaitText() function that has been used.

The firmware doesn't 'return 1' even when the string response is received properly from the ESP (checked the UART log) and only acts as a delay for the amount of time that is specified.

I would really appreciate it if you review the attached firmware and let me know what could be the issue.

Regards,
Yash

0 Likes
1 Solution

Yash,

When you say:


The main issue that I am facing is that if the ESP does not have power, ...


I'm not understanding this statement.  The ESP is not powered?  I'm assuming this in not the case.

Suggestion:

Create a a 3rd UART-type port on your CY8CKIT-059 (I'm assuming that's what you're using).  You can use the USB-UART with the microUSB connector on the target board.

On this port, send the raw Rx data from the UART-ESP in characters.  With this new UART port, you can use a Term program with char to hex conversion to actually see the UART_ESP Rx response data.  With this you can tailor your WaitText() to better see the ESP board responses from your commands.

Len
"Engineering is an Art. The Art of Compromise."

View solution in original post

0 Likes
10 Replies
EvPa_264126
Level 7
Level 7
500 replies posted 250 replies posted 100 likes received
Sorry, I will home after 4 days, please wait.
0 Likes

Hi @MotooTanaka @Len_CONSULTRON ,

I would really appreciate it if you could provide some insights as to what might be the issue with my implementation?
Or if you have implemented similar functions while interfacing with ESP or GSM modules, any insight would be great.

The function is used to wait for a response, for the specified time, from the ESP after an AT command is sent to the module.

The issue is that the function is just timing out instead of returning 1 once the actual string is received.

Hope to hear from you soon.

Regards,
Yash

0 Likes

Yash,

Based on your attached link, you were able to get the ESP-01 interface to work.  Congratulations.

It appears you're trying to get a ESP-8266 interface to work.  

I have issues with trying to help you.  Here is my list:

  • I don't have an ESP-8266 to test.
  • The WaitFor() function you refer to does not exist in your PSoC project.  Is this code running on the ESP-8266?
  • You are using port pins P1.6 and P1.7 on the PSoC UART component to talk to the ESP-8266.  These pins do not have the native ability to voltage-level translate like the pins on port 12.  
    Your previous project talking to the ESP-01 made use of port12 SIO functions to level translate.
    I'm not aware which ESP-8266 your are interfacing but it is my understanding that since the CPU/IC is a Wi-Fi, chances are that the part IO will be limited to 3.3V until there are voltage level translators on the PCB.

With these issues above, my help will be limited.

Here's my suggestions to prove out your interface:

  • In the ESP8266 code, output a known string to its UART to the PSoC.   Print this string to the UART debug port.  This should confirm the ESP8266 Tx to PSoC UART Rx interface.
  • Add ESP8266 code to accept a single character on the UART Rx.  Make this character a lower-case 'k'.  When the ESP8266 receives this character, change the ESP8266 output string.  This confirms the PSoC Tx to ESP8266 Rx interface.

The above suggestions are a low-level test of your interface.

It these tests are successful, then the remaining issues will be at a higher-level.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi @Len_CONSULTRON ,

I did get the ESP-01 working back then, but since it required level translation, i shifted to using a NodeMCU V3 which has the Tx and Rx as 5V tolerant pins. The hardware is not the issue.

 

Apologies, my bad. The function I was referring to was WaitText() in the ESPDataLogger.c file of the attached project in my question.

The firmware is completely running on PSOC.

I am having an issue with this implementation of the WaitText() function where it doesn't exit from the loop even after the reception of the actually expected response to the PSOC and waits till the duration is complete.

I hope you can provide some insight into what could be the issue with the implementation of the said function.

Regards,
Yash

0 Likes

Yash,

Have you verified that the HW interface to the ESP8266 UART port is 5V compatible?

Here's my code analysis of your WaitText() function.  It has issues.

 

uint16  WaitText(char *target, int time) 		 
 {

    uint8 targetLen = strlen(target); 								
    uint8 index = 0;  												// maximum target string length is 255 bytes
    char c;															
    do	
    {
    	c = UART_ESP_ReadRxData();										
      	if( c == target[index])
        {
		Test_Write(1);
        	Test_Write(0);
        	if(++index >= targetLen) {return 1; }
        }	// return true, if all chars in the target match
      	else  index = 0;   //..........................     				
	  
        if( !UART_ESP_GetRxBufferSize())
        {
            CyDelay(1); 
            time--;
        }	
    } while(time);
return 0;	
} 

 

You're using UART_ESP_ReadRxData().  This is an issue here since this function returns immediately whether or not new Rx data is there or not.  If Rx data is not there, the variable c is filled with the previous Rx character received.  This 'false' data would reset your index (ie index = 0;)  

If you're going to use UART_ESP_ReadRxData() you also need to qualify it with a successful return code from the function first.  This function is UART_ESP_ReadRxStatus().

Instead of UART_ESP_ReadRxData() you can use UART_ESP_GetChar().  This function returns NULL ('\0') if no new character is available.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi @Len_CONSULTRON ,

 

Thanks for your input.

I tried using the UART_ESP_GetChar() in the current implementation of the WaitText() function, but unfortunately, the function still behaves as a delay and no the actual waiting for response function.

If it would be possible, can you share how the WaitText() function could be modified so that there is a return(exit) from the function when the 'expected string' response is received from ESP? or returns 0 if the response is not received?

Regards,
Yash

 

0 Likes

Yash,

Try this WaitText() replacement function.

uint16  WaitText(char *target, int time) 		 
 {

    uint8 targetLen = strlen(target); 								
    uint8 index = 0;  												// maximum target string length is 255 bytes
    char c;															
    do	
    {
    	c = UART_ESP_GetChar();										
      	if( c == '\0') {}	/* ignore if the character is '\0' */
      	else if( c == target[index])
        {
			Test_Write(1);
        	Test_Write(0);
        	if(++index >= targetLen) {return 1; } // return true, if all chars in the target match
        }	
      	else  index = 0;   // restart the string comparison    				
	  
        if( !UART_ESP_GetRxBufferSize())
        {
            CyDelay(1); 
            time--;
        }	
    	
    } while(time);
return 0;	
} 
Len
"Engineering is an Art. The Art of Compromise."

Yash,

Did my replacement function work for you?

Len
"Engineering is an Art. The Art of Compromise."
0 Likes

Hi @Len_CONSULTRON ,

 I tried the function you suggested, but unfortunately, the function does not work as intended, and still times out.

The main issue that I am facing is that if the ESP does not have power, even then the function is printing the 'AT:OK' and similar text onto the terminal which is supposed to be printed only if the response is received from the ESP (tested this by removing the power cable to the ESP during the init sequence, but the function still proceeded).

Hope you can provide some insight as to what could be the issue.

Regards,
Yash

0 Likes

Yash,

When you say:


The main issue that I am facing is that if the ESP does not have power, ...


I'm not understanding this statement.  The ESP is not powered?  I'm assuming this in not the case.

Suggestion:

Create a a 3rd UART-type port on your CY8CKIT-059 (I'm assuming that's what you're using).  You can use the USB-UART with the microUSB connector on the target board.

On this port, send the raw Rx data from the UART-ESP in characters.  With this new UART port, you can use a Term program with char to hex conversion to actually see the UART_ESP Rx response data.  With this you can tailor your WaitText() to better see the ESP board responses from your commands.

Len
"Engineering is an Art. The Art of Compromise."
0 Likes