Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Mehrdad K
@mkeyno
@martinayotte I have to send AT command and read serial SIM module in certain of time in loop() function , can you elaborate what approach would be best ?
following is the code currently I use
int sendCmdAndWaitForResp(const char* cmd, const char *resp, unsigned timeout)
{
 SIM.write(cmd);
// Serial.println(cmd);
int len = strlen(resp);
    byte sum=0,Location=0;
    unsigned long timerStart,timerEnd;
    timerStart = millis();    
    while(1) {
        if(SIM.available()) {
                        char c = SIM.read();
                        // Serial.write(c);
                        if(c<32) SIM_BUFF+='_';
                        else     SIM_BUFF+=c;
                        Location++;
                        sum = (c==resp[sum]) ? sum+1 : 0;
                        if(sum == len) break;
                      }
        timerEnd = millis();
        if(timerEnd - timerStart > 1000 * timeout) return 0; 
      }
    while(SIM.available())    SIM.read(); 
    return Location-len+1;  
}
Martin Ayotte
@martinayotte
I would separate the handling of Send and the Response in 2 tasks. I presume that responses have some delimitter such CR or CRLF, accumulate the characters with while(Serial.available()) and process response only when the CRLF arrives. So, when responses is not yet completed, you simple leaving the loop()
Mehrdad K
@mkeyno
is it possible in your approach , may loose some responds while I'm doing other stuff in loop()?
Martin Ayotte
@martinayotte
Serial at 9600baud, meaning 960 chars/sec, leaving you plenty of time to do something else, especially if those other tasks are not blocking too.
Also, I think in the SDK layer, UART is using FIFO, although I don't know a big it is.
Mehrdad K
@mkeyno
that's why I choose low speed such as 9600, and as serial is interrupt driven I was hopping no mess with wifi stack
Martin Ayotte
@martinayotte
I was wrong : the FIFO seems to be handle in esp8266/2.3.0/cores/esp8266/uart.* with 128 bytes.
Mehrdad K
@mkeyno
actually I'm using software serial for reading module and set its buffer to 256
Martin Ayotte
@martinayotte
With SoftwareSerial, you have more chance to get troubles with the WiFi stack. But maybe it can still work.
Mehrdad K
@mkeyno
actually I have , sometimes my module reset or my websocket connection severed
Martin Ayotte
@martinayotte
For the module resets, I'm not sure it is related.
Mehrdad K
@mkeyno
@martinayotte I have SIM module connected and close to my ESP-12F, when it get call , make the ESP reset , do you have any suggestion to protect ESP
Martin Ayotte
@martinayotte
@mkeyno , this is usually symptom of bad power supply. Make sure it is strong enough and well regulated and add capacitors nearby.
Shelby Merrick
@forkineye
Is it possible to feed the hardware watchdog?
Ivan Grokhotkov
@igrr
WDT_FEED();
In esp8266_peri.h
Shelby Merrick
@forkineye
thanks @igrr !
Shelby Merrick
@forkineye
@igrr If I need to bitbang a packet for 800us with interrupts disabled, will WDT_FEED() keep me alive or should I expect issues?
Ivan Grokhotkov
@igrr
Disabling wifi interrupt for more than 20us is not recommended. You will likely get wdt reset if you disable them for that long.
Michael Miller
@Makuna
@forkineye What sort of packet are you bit-banging?
Shelby Merrick
@forkineye
@Makuna GECE lights
Shelby Merrick
@forkineye
@Makuna 26 bits @ 30us each, painfully slow - https://github.com/forkineye/ESPixelStick/blob/master/bitbang.c
Michael Miller
@Makuna
@forkineye you could start with my neopixel library and modify the timing; look at the uart or dma methods.
Shelby Merrick
@forkineye
@Makuna I came up with the 6N1 uart method for 2811 you're using in that :)
Tried something similar for GECE, but its glitching. I really need 8N0 to make it clean, but can't have 8 stop bits :(
Michael Miller
@Makuna
(there is now two uart methods, the new one is async like the dma)
Shelby Merrick
@forkineye
I do it 7N1 here, but getting some glitching. have to pull the line low manually - https://github.com/forkineye/ESPixelStick/blob/master/PixelDriver.h#L94
oh yeah, i noticed the async stuff. nice work! i ended up hacking that back into mine after seeing it
did an async DMX-512 output for it too
sticilface
@sticilface

question for esp8266 boffins! PROGMEM what section should it end up in... i've got 3 strings in print

Serial.printf_P( PSTR("hello-pgm")); 
Serial.print("hello-not");
Serial.print( F("hello-F()"));

"hello-pgm" and "hello-F()" both end up in section .irom0.text:
"hello-not" ends up in section .rodata:

as

#define PROGMEM     ICACHE_RODATA_ATTR

should it not all be in .rodata.. I'm not entirely sure which sections are in RAM or not...

Michael Miller
@Makuna
Rodata is still ram on esp8266, it's usually ram on most platforms. Irom0 section is flash on the esp8266, thus saving ram. Most code also resides in flash and is retrieved and cached in ram when run; but code can be marked so it stays on ram for faster access (like ISRs or timing critical code )
Hagai Shatz
@hagai-shatz
Question - with all sort of other things running on the ESP (WiFi, AsyncServer, etc.), is there a way to execute a short HSPI communication every 500ns?
sticilface
@sticilface
@Makuna cheers for clearing that up
Me No Dev
@me-no-dev
@hagai-shatz every 500ns?
I doubt you can do anything even every 2-3us
Hagai Shatz
@hagai-shatz
Sorry, 500us.
Michael Miller
@Makuna
Also, while RAM can be accessed by 8 bits, flash must be read by 32 bits at atime, thus the requirement of using the progmem macros and wrappers. For AVR it's a completely different access method.
Me No Dev
@me-no-dev
sure thing ;) totally doable
Hagai Shatz
@hagai-shatz
How?
Me No Dev
@me-no-dev
timer0 or timer1
or Ticker
Michael Miller
@Makuna
@hagai-shatz how accurate do you need that 500us to be?
Hagai Shatz
@hagai-shatz
20% tolerance will be okay.
About 2000 executions per second.
@me-no-dev - but what if something else is handled in interrupt and it take time to finish? Does the AsyncServer is interrupt based?
Some SPIFFS calls takes >10ms to execute.
Me No Dev
@me-no-dev
@hagai-shatz using timer1 and it's regular ISR will not interrupt the network (that I have tested). Using NMI interrupt will, but I did not see any issues with that. I have not tested timer0 and Ticker, but Ticker should behave the same.
Hagai Shatz
@hagai-shatz
Can you point me to some examples please?
As for Ticker, I use it and it is not reliable even in 20ms intervals. It looks like when the ESP is busy with AsyncWebServer handlers it does not tick.