Hope someone will help me with the problem I face.
Now I'm working on Modbus RTU tests and faced that sometimes time.sleep_us provides a wrong sleep period.
Please look at code and diagram from my Logic.
The idea of the test example is to send via UART 255 symbols and rise up an additional pin during the transmission.
If you look at the diagram you will see that time to time my UPes pin going Down with the delay (marked red).
I do not understand what is the reason.
I'm testing it on esp32-20190529-v1.11.bin
Will be glad for any ideas.
Thank you.
Code: Select all
import machine
import time
tx = 17
rx = 2
ctrl = 23
baudrate = 300
ctrlPin = machine.Pin(ctrl, mode=machine.Pin.OUT)
symbol_us = (10 * 1000000) / baudrate # time we need to send 1 symbol
bin_arr = bytearray(b'') # Payload for test
for i in range(1,256):
bin_arr.append(i)
ctl_up_us = int( symbol_us * len(bin_arr) ) # Time of expected TX
print ('Length of payload: {}'.format(len(bin_arr)))
print ('Ctl Pin UP, us: {}'.format(ctl_up_us))
# timeout_char=10
uart = machine.UART( 0x02, baudrate=baudrate, bits=8, parity=None, stop=1, tx=tx, rx=rx)
while True:
ctrlPin(1)
uart.write(bin_arr)
time.sleep_us( ctl_up_us ) # !!! Problematic place
ctrlPin(0)
time.sleep_us(300000)