Current Lua downloadable firmware will be posted here

User avatar
By rom
#50965 Hello I'm new here and got a problem with a basic UART to WIFI Connection.
I have an STM32 Microcontroller sending 40 bytes every 10ms via UART to ESP8266, baudrate is 115200.
So I need 250us per byte---> 31,25us per bit. A baudrate of 1/31,25us is needed(30000bps) at minimum...

It's not an issue of the UART Speed, I even tested the microcontroller output to serial/usb Interface on my laptop.

When I run this code on ESP8266 though, every 247 bytes there is a loss in information of approx. 2 table strings:

Code: Select all--CREATE SERVER AND LISTEN
srv=net.createServer(net.TCP)
srv:listen(80,function(conn)
    conn:on("receive",function(sck,payload)
   
    local response = {}
    for k,v in pairs(send_buf) do
        response[k] = v
    end

    local max = table.maxn(send_buf)
    while max > 1 do
   table.remove(send_buf,max)
        max = max - 1
    end

    local function send(sk)
   if #response > 0 then
       sk:send(table.remove(response,1))
   else
       sk:close()
       response = nil
   end
    end

  sck:on("sent",send)
  send(sck)
  end)
end)

--LISTEN TO UART
uart.on("data", "$",
  function(data)
    send_buf[#send_buf + 1] = data
    if data=="quit$" then
      uart.on("data") -- unregister callback function
    end
end, 0)


The Microcontroller sends something like this:
$#00000018,8,00 00 00 00 00 00 00 00
$#00000019,8,00 00 00 00 00 00 00 00
$#00000019,8,00 00 00 00 00 00 00 00
$#0000001A,8,00 00 00 00 00 00 00 00
$#0000001B,8,00 00 00 00 00 00 00 00
$#0000001C,8,00 00 00 00 00 00 00 00

The HTTP request gets me:
$#00000018,8,00 00 00 00 00 00 00 00
$#00000019,8,00 00 00 00 00 00 00 00
$#00000 00 00 00
$#0000001C,8,00 00 00 00 00 00 00 00

Problem dissapears if I send every 20ms instead of 10 but I need 10.
Help would be greatly appreciated.

greetings

UPDATE 20.07.2016:
I have now tested the whole thing with a string concatenation into a list of max 200 characters, still the same problem.
It seems to be an issue of speed or interfaces.
When I send the string lines one by one via uart(by hand) and make a get request, I get everything without loss in the right order.
2 possibilities:

1. The UART Buffer needs time to be transfered from the uart event handler to a place in ram. This takes too much time to take place simultaneously.

2. The GET Request interrupts the UART Event and cut offs the bytes on transmission. I already tested a gpio pin from ESP8266 which pauses the transmission while the get request being served. Nothing.

UPDATE 21.07.2016:
I've tried to set up a timer of 25ms in the microcontroller, which marks the uart send timing. It sends all until then received frames at once(in this case 2-3) to the esp8266. Every second Frame is missing now.

UPDATE 28.07.2016:
Now moving to RTOS SDK since a week and I get up to 38 characters every 2ms at 921600bps. At 1ms the process seems to get interrupted by the long interrupt routine itself or slowed down by sending of 25kbytes worth of data every 600ms.
Tried 2x16kbytes buffer and now 6x5kbyte buffer. The next will be even more buffer space and optimization of the interrupt routine. I would like to get nonstop uart data but that doesn't seem possible I think...except with a DMA Channel. This will be tried out and I report for improvements on this.

UPDATE 30.07.2016:
Testing is finished and I now stuck with 2x18kbyte buffers and a get request every 100ms.
The UART Speed is 2.25Mbit/sec and there are no errors, works flawless at 1.680.000bits/sec--->168000 bytes/second.
Information gets transmitted without error. The maximum speed of UART is almost reached and the Interface can't be pushed over apporximatly 80% of the UART Baudrate, after this there is a transmission of unknown false signs like "?". So if greater transmission speeds are required, then someone should move to SPI.

I haven't tried less than 100ms get request speed. The next thing is to push this to the limit to empty the 18k buffers even faster. I try faster ones soon.