B4R Question Problems with SELECT CASE

Gerardo Tenreiro

Active Member
Licensed User
Hello Forum,
I've been working on an ESP32 application for months, the application has a lot of code, so I was generating the different modules separately and testing them.

Apparently all the modules work correctly separately but now when joining them in an application I see that every certain random time, 10 or 15 minutes, the ESP32 restarts with this error message:
Guru Meditation Error: Core 1 panic'ed (LoadProhibited). Exception was unhandled.

I start to eliminate modules and each time the problem appears in another area of the program without meaning, but it is always where there are SELECT CASE instructions, for example in this program block:

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'
' Gestion del Menu 100 al 199
'
Private Sub Gestion_del_Menu_100_199
Private M1 As Byte ' Memoria Inicial del Menu de Display
Private M2 As Byte ' Memoria Inicial del SubMenu de Display


' Memoriza el Numero de menu
M1 = DISPLAY.Menu_Display
' Memoriza el SubMenu
M2 = DISPLAY.SubMenu_Display
' Segun en la Pantalla que Esta Asi actuan las Teclas
Select Case DISPLAY.Menu_Display
Case 100 ' Inicio Menu Tecnico
If F_T_Mas = True Then
DISPLAY.SubMenu_Display = DISPLAY.SubMenu_Display + 1
End If
If F_T_Menos = True Then
DISPLAY.SubMenu_Display = DISPLAY.SubMenu_Display - 1
End If
' Si Se Pulsa Enter
If F_T_Enter = True Then
' Segun el Sub Menu Seleccionado Asi Actual
Select Case DISPLAY.SubMenu_Display
Case 0 ' Pruebas
DISPLAY.SubMenu_Display = 0
DISPLAY.Menu_Display = 103
Case 1 ' Parametros VF
DISPLAY.SubMenu_Display = 0
DISPLAY.Menu_Display = 113
Case 2 ' PLC
DISPLAY.SubMenu_Display = 0
DISPLAY.Menu_Display = 111
Case 3 ' Mas

Case 4 ' Atras
DISPLAY.SubMenu_Display = 0
DISPLAY.Menu_Display = 3
End Select
End If
Case 104 ' Menu Principal de Pruebas
If F_T_Mas = True Then
DISPLAY.SubMenu_Display = DISPLAY.SubMenu_Display + 1
End If
If F_T_Menos = True Then
DISPLAY.SubMenu_Display = DISPLAY.SubMenu_Display - 1
End If
' Si Se Pulsa Enter
If F_T_Enter = True Then
' Segun el Sub Menu Seleccionado Asi Actual
Select Case DISPLAY.SubMenu_Display
Case 0 ' Pruebas Salidas Digitales
DISPLAY.Aux_BY = 0
DISPLAY.Aux_Bi = 0
DISPLAY.Aux_V = False
DISPLAY.Menu_Display = 107
Case 1 ' Pruebas Salida Analogica 1
DISPLAY.Aux_By = 1
DISPLAY.Menu_Display = 109
Case 2 ' Pruebas Salida Analogica 2
DISPLAY.Aux_By = 2
DISPLAY.Menu_Display = 109
Case 3 ' Mas
'DISPLAY.Aux_BY = 1
'DISPLAY.SubMenu_Display = 0
'DISPLAY.Menu_Display = 21
DISPLAY.SubMenu_Display = 0
DISPLAY.Menu_Display = 121

Case 4 ' Atras
DISPLAY.SubMenu_Display = 0
DISPLAY.Menu_Display = 99
End Select
End If

Case 108 ' Pruebas Salidas Digitales

This piece of code has several SELECT CASE chained inside each other, but the error is not always generated in this module, it is a continuous module but I shorten it.

If I cancel this piece of code the error continues in other code that contains the SELECT CASE statement. it's a random thing.

I can't find an explanation for the malfunction of the code.

Someone is suffering the same problem.

Thank you so much
 

Gerardo Tenreiro

Active Member
Licensed User
At the moment I am in this block that gives an error and I don't know why

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
'
' Lee las Entradas Digitales de los Expandores
'
Public Sub Lee_Entradas_Expansores
Private Dire As Byte ' Direccion
Private Regi(1) As Byte ' Numero de Registro
Private Valor(1) As Byte ' Valor del Registro
Private Algun_Cambio As Boolean = False ' Algun Cambio en las Entradas Digitales
Private Que_Cambio As Int = 0
Private R As Byte = 0 ' Auxiliar Escritura Bus.

Private Meno_E02 As Boolean
Private Meno_E10 As Boolean
Private Meno_E11 As Boolean
Private Meno_E15 As Boolean

' Si Esta en el Menu 54.
If DISPLAY.Menu_Display = 54 Then
Meno_E02 = E02
Meno_E10 = E10
Meno_E11 = E11
Meno_E15 = E15
End If
'
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Primer Expansor, Entradas
Dire = 32 ' 01000000 ' Direccion
Regi(0) = 0 ' 00000000 ' Registro
' Si el Estado del Expansor 32 es Correcto Intenta Leerlo
If Estado32 = True Then
' Lee el Primer Expansor, Todo Entradas
R = Bus.WriteTo(Dire,Regi)
' Lee el Valor del Registro 0
Private V32() As Byte = Bus.RequestFrom(Dire, 1)
' Si la Lectura Fue Correcta V32 Mide de largo un BYTE
If V32.Length > 0 Then
' Asigna Valor de la Lectrura
Valor(0) = V32(0)
' Revisa si hay Cambio en las entradas digitales
If EB(0) <> Valor(0) Then
Algun_Cambio = True
Que_Cambio = Que_Cambio + 1
' Asigna Valor a las entradas digitales
EB(0) = Valor(0)
If Bit.Get(Valor(0),0) = 0 Then E00 = False Else E00 = True
If Bit.Get(Valor(0),1) = 0 Then E01 = False Else E01 = True
If Bit.Get(Valor(0),2) = 0 Then E02 = False Else E02 = True
If Bit.Get(Valor(0),3) = 0 Then E03 = False Else E03 = True
If Bit.Get(Valor(0),4) = 0 Then E04 = False Else E04 = True
If Bit.Get(Valor(0),5) = 0 Then E05 = False Else E05 = True
If Bit.Get(Valor(0),6) = 0 Then E06 = False Else E06 = True
If Bit.Get(Valor(0),7) = 0 Then E07 = False Else E07 = True
End If
Else
If Error_Leer_IO = False Then
Error_Leer_IO = True
DISPLAY.Presenta_Estado_Expansores
End If
If Estado32 = True Then
Estado32 = False ' Error en el Expansor Add = 32
End If
End If
End If

'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Segundo Expansor, Entradas
Dire = 33 ' 01000010 ' Direccion
Regi(0) = 0 ' 00000000 ' Registro
' Si el Estado del Expansor 33 es Correcto Intenta Leerlo
If Estado33 = True Then
' Lee el Segundo Expansor, Todo Entradas
R = Bus.WriteTo(Dire,Regi)
' Lee el Valor del Registro 0
Private V33() As Byte = Bus.RequestFrom(Dire, 1)
' Si la Lectura Fue Correcta V33 Mide de largo un BYTE
If V33.Length > 0 Then
' Asigna Valor de la Lectrura
Valor(0) = V33(0)
' Revisa si hay Cambio en las entradas digitales
If EB(1) <> Valor(0) Then
Algun_Cambio = True
Que_Cambio = Que_Cambio + 2
EB(1) = Valor(0)
' Asigna Valor a las entradas digitales
If Bit.Get(Valor(0),0) = 0 Then E10 = False Else E10 = True
If Bit.Get(Valor(0),1) = 0 Then E11 = False Else E11 = True
If Bit.Get(Valor(0),2) = 0 Then E12 = False Else E12 = True
If Bit.Get(Valor(0),3) = 0 Then E13 = False Else E13 = True
If Bit.Get(Valor(0),4) = 0 Then E14 = False Else E14 = True
If Bit.Get(Valor(0),5) = 0 Then E15 = False Else E15 = True
If Bit.Get(Valor(0),6) = 0 Then E16 = False Else E16 = True
If Bit.Get(Valor(0),7) = 0 Then E17 = False Else E17 = True
End If
Else
If Error_Leer_IO = False Then
Error_Leer_IO = True
DISPLAY.Presenta_Estado_Expansores
End If
If Estado33 = True Then
Estado33 = False ' Error en el Expansor Add = 33
End If
End If
End If
'+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
' Tercer Expansor, Entradas
Dire = 34 ' 01000010 ' Direccion
Regi(0) = 0 ' 00000000 ' Registro
' Si el Estado del Expansor 34 es Correcto Intenta Leerlo
If Estado34 = True Then
' Lee el Tercer Expansor, Todo Entradas
R = Bus.WriteTo(Dire,Regi)
' Lee el Valor del Registro 0
Private V34() As Byte = Bus.RequestFrom(Dire, 1)
' Si la Lectura Fue Correcta V34 Mide de largo un BYTE
If V34.Length > 0 Then
' Asigna Valor de la Lectrura
Valor(0) = V34(0)
' Revisa si hay Cambio en las entradas digitales
If EB(2) <> Valor(0) Then
Algun_Cambio = True
Que_Cambio = Que_Cambio + 4
' Asigna Valor a las entradas digitales
EB(2) = Valor(0)
If Bit.Get(Valor(0),0) = 0 Then E20 = False Else E20 = True
If Bit.Get(Valor(0),1) = 0 Then E21 = False Else E21 = True
If Bit.Get(Valor(0),2) = 0 Then E22 = False Else E22 = True
If Bit.Get(Valor(0),3) = 0 Then E23 = False Else E23 = True
If Bit.Get(Valor(0),4) = 0 Then E24 = False Else E24 = True
If Bit.Get(Valor(0),5) = 0 Then E25 = False Else E25 = True
If Bit.Get(Valor(0),6) = 0 Then E26 = False Else E26 = True
If Bit.Get(Valor(0),7) = 0 Then E27 = False Else E27 = True
End If
Else
If Error_Leer_IO = False Then
Error_Leer_IO = True
DISPLAY.Presenta_Estado_Expansores
End If
If Estado34 = True Then
Estado34 = False ' Error en el Expansor Add = 34
End If
End If
End If

' Si Hay algun Cambio en las entradas Digitales
If Algun_Cambio= True Then
' Si esta en la Pantalla 22. Ver Entradas Digitales
If DISPLAY.Menu_Display = 22 Then
' Actualiza Display
DISPLAY.Menu_22(Que_Cambio)
End If
End If

' Si Esta en el Menu 54 y Hay algun Cambio lo Actualiza
If DISPLAY.Menu_Display = 54 Then
If Meno_E02 <> E02 Then Cambio_E02 = True
If Meno_E10 <> E10 Then Cambio_E10 = True
If Meno_E11 <> E11 Then Cambio_E11 = True
If Meno_E15 <> E15 Then Cambio_E15 = True
End If

End Sub

It is the reading of some TCA9545 expanders

Do you see something strange in it?
I don't see anything that could generate the error, but it is generated approximately every 10 minutes.


Thank you
 
Upvote 0
Top