B4R Question Strange behavior of serial port 2

Gerardo Tenreiro

Active Member
Licensed User
Hello again.
This time there is a problem that I expose:
I am using the second port of an ESP32, it seems to work correctly, I can send and receive data as normal.
When analyzing the times of the ESP32, I observe that this block of instructions take between 4 and 5 ms in each program cycle of the ESP32, which is not normal.
TX2.Initialize(17,TX2.MODE_OUTPUT) ' Pin de TX
RX2.Initialize(16,RX2.MODE_INPUT_PULLUP) ' Pin de RX
RunNative("SerialNative2", Null) ' Puerto Serie del VF
PS2.Initialize(SerialNative2, "VF_Newdata","VF_Error") ' Inicializa Puerto Serie 2

#if C
void SerialNative2(B4R::Object* unused)
{
::Serial2.begin(115200);
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#End If

This piece of code is executed once at the start of the program.
Since I run this code, the program stops for about 4ms every time I activate port forwarding.
The electronic schematic is very simple.
Pin 17.TX
Pin 16.RX
Pin 18. Enable transmission
Interestingly every time I activate the transmit pin the ESP32 stops doing things for about 4ms
I am attaching the parser plot. It is as if it were waiting for characters to enter through the serial port.

1686048656740.png

Just by commenting on this instruction, the ESP32 times return to normal, but of course I do not receive the communications from the port.
attached image
TX2.Initialize(17,TX2.MODE_OUTPUT) ' Pin de TX
RX2.Initialize(16,RX2.MODE_INPUT_PULLUP) ' Pin de RX
RunNative("SerialNative2", Null) ' Puerto Serie del VF
'PS2.Initialize(SerialNative2, "VF_Newdata","VF_Error") ' Inicializa Puerto Serie 2


1686048940606.png


It's like the serial port is started by software not hardware.
I clarify that the upper signals are oscillating once per cycle of the program
As always any help is welcome.
Thank you so much
 

Gerardo Tenreiro

Active Member
Licensed User
Hello again.
This time there is a problem that I expose:
I am using the second port of an ESP32, it seems to work correctly, I can send and receive data as normal.
When analyzing the times of the ESP32, I observe that this block of instructions take between 4 and 5 ms in each program cycle of the ESP32, which is not normal.




This piece of code is executed once at the start of the program.
Since I run this code, the program stops for about 4ms every time I activate port forwarding.
The electronic schematic is very simple.
Pin 17.TX
Pin 16.RX
Pin 18. Enable transmission
Interestingly every time I activate the transmit pin the ESP32 stops doing things for about 4ms
I am attaching the parser plot. It is as if it were waiting for characters to enter through the serial port.

View attachment 142649
Just by commenting on this instruction, the ESP32 times return to normal, but of course I do not receive the communications from the port.
attached image



View attachment 142650

It's like the serial port is started by software not hardware.
I clarify that the upper signals are oscillating once per cycle of the program
As always any help is welcome.
Thank you so much

Hello again.
I provide some more information regarding the problem that I observe
I attach a very simple sample program. It would be necessary to have an oscilloscope or analyzer to verify the problem that I summarize.
GPIO17 and GPIO27 pins are used.
The GPIO27 PIN changes its value from FALSE to TRUE in each cycle of the ESP32
The GPIO17 PIN turns on every 2100us and turns off every 1100us.
I am attaching an image that shows that without the instruction being active, this works correctly.

1686125364147.png



As you can see the changes in the GPIO 27 PIN are continuous and stable, they do not stop and work regularly. The GPIO 17 PIN changes its value regularly every 2100us and 1100us approximately. All of this is normal and correct.
The instruction is commented.
Without further ado I delete the instruction comment and everything changes, the ESP is lost for approximately 4700us and I don't know what it is doing.
The serial port pins are not connected to anything.

1686125195001.png


1686125241639.png



I know it is very difficult to detect but I am sure that the problem is in the instruction
PS2.Initialize(SerialNative2, "VF_Newdata","VF_Error")

This means that during the time that the ESP32 is lost, it stops doing other program things.
This also prevents the CALLSUBPLUS statements from executing normally.
Please, does anyone have any idea where to look or what to do to solve this serious problem.
If anyone needs any further clarification, feel free to ask.
thank you so much


#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region

Sub Process_Globals
Dim T1 As ULong = 0
Dim M_T1 As Byte = 0

Public Serial1 As Serial ' Puerto Serie 1
Public brate1 As ULong = 115200
Public SerialNative2 As Stream ' Puerto Serie 2
Public brate2 As ULong = 115200
Private PS2 As AsyncStreams ' Entrada de Datos del Puerto Seria
Public EN_TX1 As Pin ' Pin Habilita Transmision Puerto Serie 2
Private EN_TX2 As Pin ' Pin de Habilitacion Transmision del Encoder

End Sub

Private Sub AppStart

Serial1.Initialize(brate1)
Log("Arranque...")

' Inicializa el Pin de EN_TX2
EN_TX1.Initialize(18,EN_TX1.MODE_OUTPUT)
EN_TX1.DigitalWrite(False)
' Pin de Habilitacion de Transmision
EN_TX2.Initialize(27,EN_TX2.MODE_OUTPUT)
EN_TX2.DigitalWrite (False)

' Inicializa Puerto Serie 2
RunNative("SerialNative2", Null) ' Puerto Serie del VF
' Inicializa Puerto Serie 2
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'PS2.Initialize(SerialNative2, "VF_Newdata","VF_Error")
'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Log("Lanza Tarea")
AddLooper("Tarea")

End Sub

Sub Tarea
Dim Va1 As ULong

If EN_TX2.DigitalRead = False Then
EN_TX2.DigitalWrite(True)
Else
EN_TX2.DigitalWrite(False)
End If

Va1 = Micros - T1

If M_T1 = 0 Then
If Va1 > 1100 Then
T1 = Micros
Va1 = 0
M_T1 = 1
EN_TX1.DigitalWrite(True)
End If
Else
If Va1 > 2100 Then
T1 = Micros
Va1 = 0
M_T1 = 0
EN_TX1.DigitalWrite(False)
End If
End If

End Sub

Private Sub VF_Newdata (Buffer() As Byte)

End Sub

public Sub VF_Error

End Sub

'++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

' Configuracion puerto Serie 2
#if C
void SerialNative2(B4R::Object* unused)
{
::Serial2.begin(115200,SERIAL_8N1);
b4r_main::_serialnative2->wrappedStream = &::Serial2;
}
#End If
 

Attachments

  • ERROR TIEMPOS.zip
    1.3 KB · Views: 55
Upvote 0
Top