B4R Library rSPI32 - A port of rSPI for ESP32 boards

Good evening everyone,

this library was created by @Gerardo Tenreiro and me. It is a port of the rSPI library for ESP32 boards. I cannot test this library because I don't have (yet) an ESP32 board but it has been tested by @Gerardo Tenreiro and I take his word for it that it works. Due to several on-going projects and limited time I had completely forgot it and I am posting it now @Gerardo Tenreiro, sorry for the delay.


Core for using it:


B4X:
Sub Process_Globals
    Public Serial1 As Serial
 
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
 
 
 
    SPI.CheckIfThisBoardIsSupported

    '===========================================================================================
    '===========================================================================================
    '===========================================================================================
    '       CHANGE HERE THE PIN NUMBERS (SCK, MISO, MOSI, CS)
    '===========================================================================================
    '===========================================================================================
    SPI.ESP32_SPI_Set_Pins(18,19,23,27)
    SPI.CSPinDeActivate(SPI.CS__SPI)    
    '===========================================================================================
    '===========================================================================================
    '===========================================================================================

 
    AddLooper("CommunicateThroughSPI")

 
End Sub


Private Sub CommunicateThroughSPI
    Dim D0_V        As Byte
    Dim D1_V        As Byte
    Dim D2_V        As Byte
    Dim Valor_V        As Double
 
    SPI.Begin_Transaction(1000000, SPI.MSBFIRST, SPI.SPI_MODE1)  

    SPI.CSPinActivate(SPI.CS__SPI)
 
    SPI.Transfer_Byte(81)
    SPI.Transfer_Byte(3)
    SPI.Transfer_Byte(1)
    SPI.Transfer_Byte(0)
    SPI.Transfer_Byte(240)
    SPI.Transfer_Byte(1)
 
    SPI.Transfer_Byte(1)
   

    SPI.End_Transaction
 

    SPI.Begin_Transaction(1000000, SPI.MSBFIRST, SPI.SPI_MODE2)
 
 
    D0_V = SPI.Transfer_Byte(0)
    D1_V = SPI.Transfer_Byte(0)
    D2_V = SPI.Transfer_Byte(0)
 

    SPI.CSPinDeActivate(SPI.CS__SPI)
 

    SPI.End_Transaction
 
    ' Calcula el Valor en Bruto de Tension
    Valor_V =(D0_V * 65536) + (D1_V * 256) + D2_V
    ' Si es un numero Negativo Realiza el Complemento a 2
    If (D0_V > 128) Then
        Valor_V = 16777215 - Valor_V
        Valor_V = Valor_V * -1
    End If
    ' Aplica la Escala de Medida
    Valor_V = Valor_V * SPI.FET
 
    Log("V=",Valor_V)
 
    Delay(500)
 
End Sub
 

Attachments

  • rSPI32.b4xlib
    1.9 KB · Views: 316
Last edited:

sasetcolombia

Member
Licensed User
Longtime User
Is it possible to adapt it to record data on sdcard?
SPI1.begin(MY_SCLK, MY_MISO, MY_MOSI, MY_CS);

I'm trying to use an sd card module with the TTGO T-call SIM800L.
I can't use the SPI pins because I need to use also the SIM800L module.
the TTGO TCAL SIM800L V1.4 uses pin23 as PWR and this same pin is MOSI for SDCARD
In version 1.3 it would conflict with pin 5. RST to SIM800L and VPPI_SS (CP)

https://user-images.githubusercontent.com/53688337/85398433-d9036900-b572-11ea-99ec-04e912b5fd72.JPG
The rSD library uses by default the MOSI(23),MISO(19),SLK(18) and CS(5) pins.
I need to configure other pins for SDCARD (or 23)
 
Last edited:
Top