PSoC4 pioneer and ESP8266 WiFi module problem

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

cross mob
Anonymous
Not applicable

Hello guys, 

   

 

   

I started to mess around with  ESP8266 and PSoC4 pioneer kit (CY8C4245AXI-483), this is my uart set up: 

   

https://i.imgur.com/UrOn4K9.png 

   

https://i.imgur.com/oP5A643.png

   

I have set up my ESP8266 pins like this: 

   

CE - 3.3 V 

   

3.3 V - 3.3 V 

   

RX - TX P1[1]

   

TX - RX P1[0]

   

GND - GND 

   

RST - P2[2] 

   

Everything else is left float. 

   

 

   

I send AT command and check for OK response from ESP like this: 

   

<code>

   

UART_PutString("AT\r\n");  

   

 if (!WaitText("OK", 100)) 
        UART_1_UartPutString("UART does not work\r\n"); // debug text to putty terminal

   

</code>

   

I use some code from similar projects, to check for OK response:

   

<code>

   

uint16  WaitText(char *target, int time)     /******************************************************/             
 {
uint8 targetLen = strlen(target);                                 // Длина искомого фрагмента
uint8 index = 0;                                                  // maximum target string length is 255 bytes
char c;                                                            // текущий символ
while(UART_GetRxBufferSize())
//do
{                             // читаем UART  
      c = UART_ReadRxData();                                        // это элемент[index] искомой строки?  
      if( c == target[index]){  if(++index >= targetLen){return 1; }}    // return true если все элементы строки найдены    if all chars in the target match
      else  index = 0;   //..........................                     // не тот фрагмент - обнуляемся 
      if( !UART_GetRxBufferSize()){CyDelay(1); time--;}    // при проверке с==0 - вычитывает несколько раз, поэтому ReadRxData и GetRxBufferSize
    } //while(time);
return 0;    // буфер данных пуст

   

</code>

   

The problem is, that I find no OK response. I thought that UART_PutString() function, does'nt put CR and LF chars at the end, so I put them myself, but I might be wrong, so I tried playing with combinations (no CR, but LF, no LF, but CR, no CR and no LF), but it still does'nt work, could it be that I configured my UART incorrectly? I know that the baud rate is correct, because I tested the esp on arduino board, and everything worked just fine. So at this point I am stumped, any ideas how to solve this?

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

The UART_1 baud rate is not set to 9600bd as your comment states.

   

    UART_PutString("Connecting to wifi!\r\n");   

   


The above line might be meant for UART_1.

   

Your Data_and_Func.h contains variables. Better declare them as external in the .h file and define them in the .c file. #include the .h in the .c

   

The handling of UART conflicts with the internal interrupt. Use UART_GetRxBufferSize() only and while non-zero read off character by character until you get your terminator (\n or \r).

   

Temporarily disabling interrupts is best done using critical sections. See in System Reference Guide (Creator Help).

   

 

   

Bob

View solution in original post

0 Likes
8 Replies
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Increase your buffer size to 2+ the size of the max data to be sent or received.

0 Likes
Anonymous
Not applicable

Good tip, but it doesn't seem to be the problem, my max string length in bytes is 255, so this should be good: 
https://i.imgur.com/M8crojr.png

   

But it doesn't help, when I debug it still says that RX buffer is empty, I tried enabling/disabling interrupts at that part, but no luck, I tried checking the UART_RX_STS_FIFO_NOTEMPTY flag instead of buffer size with UART_ReadRxStatus(), because UART_GetRxBufferSize() doesn't return any info about FIFO register status, but again no luck. I am a bit stumped on why this doesn't work, maybe my interrupts are bad? Any tips?

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

To see whether you configured your UART correctly you need to 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

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

Okey, here you go

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

The UART_1 baud rate is not set to 9600bd as your comment states.

   

    UART_PutString("Connecting to wifi!\r\n");   

   


The above line might be meant for UART_1.

   

Your Data_and_Func.h contains variables. Better declare them as external in the .h file and define them in the .c file. #include the .h in the .c

   

The handling of UART conflicts with the internal interrupt. Use UART_GetRxBufferSize() only and while non-zero read off character by character until you get your terminator (\n or \r).

   

Temporarily disabling interrupts is best done using critical sections. See in System Reference Guide (Creator Help).

   

 

   

Bob

0 Likes
Anonymous
Not applicable

Okay I changed the baud rate for UART_1 and the string, you were correct on those, but that wasn't too big of a problem, I changed CyDisableInterupt; to uint8 interuptStatus = CyEnterCriticalSection(); and CyEnableInterrupt to CyExitCriticalSection(interuptStatus); as you suggested, but what do you mean by saying : 

   
    

The handling of UART conflicts with the internal interrupt. Use UART_GetRxBufferSize() only and while non-zero read off character by character until you get your terminator (\n or \r).

   
   

Also, how should I handle interrupts in my function uint16  WaitText(char *target, int time); then? 

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

Also, how should I handle interrupts in my function...

   

You should not care for interrupts, they are handled by the UART component. Just use UART_GetRxBufferSize() to check for received bytes in a loop and handle reading and interpreting them.

   

 

   

Bob

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

Hey, I managed to start the ESP with some code from here and have it connect to my router, I use wire shark to see data transactions between ESP and my router when I send data from DHT22, but I don't see any TCP data transactions on 8080 port. Also, once I connected my ESP to router, I can't receive any OK responses after restart (my ESP is base firmware), though the module is still connected to the router and in wireshark I can see some group change requests from the chip. What could be the problem? 

0 Likes