Menu

convert proton basic

Help
2018-03-01
2019-02-21
1 2 > >> (Page 1 of 2)
  • stan cartwright

    stan cartwright - 2018-03-01

    I have a proton basic prog that needs trans lating to gcb. I'm posting the original and my effort at translating.
    The device is a VL53L0X laser range finder. It seems the code works and is commented as much simpler than the un-neccessary c stuff. Any help welcome.

    Device = 16F628A
    
    Config FOSC_INTOSCIO, WDTE_OFF, PWRTE_OFF, MCLRE_OFF, BOREN_OFF, LVP_OFF, CPD_OFF, CP_OFF
    
    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------
    
    Xtal 4
    CMCON = 7
    VRCON = 0
    Declare PortB_Pullups = Off
    Declare Watchdog =Off
    Declare All_Digital On
    
    'VL53L0x Registros
    Symbol W_ADDRESS    = $52
    Symbol R_ADDRESS    = $53
    
    'Puertos
    Symbol SDA = PORTA.0
    Symbol SCL = PORTA.1
    Symbol Data_TX = PORTA.2
    
    'Variables
    Dim DatoVL As Byte
    Dim DataSensor[12] As Byte
    Dim Distancia As Word
    'Comunicacion serie
    Declare Serial_Baud 4800  
    Declare RsOut_Pin Data_TX
    Declare RsOut_Mode TRUE 
    
     DelayMS 100
    
     RsOut "Test sensor VL53L0x V11-12-17 by MTH Argentina",13,10,13,10
    
     GoSub VerVL53
     RsOut "Sensor listo, comenzando lectura...",13,10
     DelayMS 1000
    
    'Loop de programa
    While 1=1
    Clrwdt
    'REG_RESULT_RANGE_STATUS 
    I2COut SDA,SCL,W_ADDRESS,[$00,$01]
    'REG_RESULT_RANGE_STATUS 
    I2COut SDA,SCL,W_ADDRESS,[$14]
    'Lee 12 datos del Sensor:
    I2CIn  SDA,SCL,R_ADDRESS,[Str DataSensor]
    'Si el dato en DataSensor[0] es igual a 0x5E procesa distancia
    If DataSensor[0]=$5E Then Distancia=DataSensor[10]*256+DataSensor[11] '#combine integers
      'Representa distancia:
    RsOut "Distancia: ",Dec Distancia," mm",13,10 
    
      DelayMS 100
     Wend
    'Consulta datos de sensor
    VerVL53:
    'VL53L0X_REG_IDENTIFICATION_REVISION_ID
    I2CIn  SDA,SCL,R_ADDRESS,$C2,[DatoVL]
      RsOut "Revision ID: ",Hex2 DatoVL,13,10
    
    'VL53L0X_REG_IDENTIFICATION_MODEL_ID
    I2CIn  SDA,SCL,R_ADDRESS,$C0,[DatoVL]
      RsOut "Device ID: ",Hex2 DatoVL,13,10
    
    'VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD
    I2CIn  SDA,SCL,R_ADDRESS,$50,[DatoVL]
      RsOut "Pre Range Config Period: ",Hex2 DatoVL,13,10 
    
    'VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD
    I2CIn  SDA,SCL,R_ADDRESS,$70,[DatoVL]
      RsOut "Fina Period: ",Hex2 DatoVL,13,10
    
     Return
    
     
  • stan cartwright

    stan cartwright - 2018-03-01

    I got so far-

    ;in progress VL50L0X range finder
    ;proton basic to gcb
    #chip mega328p, 16
    #option explicit
    #include <lowlevel\hwi2c.h>
    'VL53L0x Regs
    #define  W_ADDRESS    = 0x52
    #define R_ADDRESS    = 0x53
    
    ;#define SDA = PORTA.0
    ;#define SCL = PORTA.1
    ;#define Data_TX = PORTA.2
      ' Define I2C settings - CHANGE PORTS if required
      #define HI2C_BAUD_RATE 400
      #define HI2C_DATA PORTC.5
      #define HI2C_CLOCK PORTC.4
    
      HI2CMode Master
    
    'Variables
    Dim DatoVL,tmp As Byte
    Dim DataSensor(12) As Byte ;1 to 12, NOT! 0 to 11
    Dim Distance As Word
    'Comunicacion serie
    ;Declare Serial_Baud 4800
    ;Declare RsOut_Pin Data_TX
    ;Declare RsOut_Mode TRUE
    
    'Set up hardware serial connection
    #define USART_BAUD_RATE 19200 ;works
    #define USART_BLOCKING
    ;test
    ;do
    ;HSerPrint "Sensor listo, comenzando lectura..." ;terminal test works
    ;HSerPrint 13
    ;HSerPrint 10
    ;wait 100 ms
    ;loop
    
    ; RsOut "Test sensor VL53L0x V11-12-17 by MTH Argentina",13,10,13,10
    VerVL53 ;---no terminal anything from here on :(
     HSerPrint "Sensor listo, comenzando lectura..."
     HSerPrint 13
     HSerPrint 10
     wait 1 s
    
    'Loop de programa
    do
    
    'REG_RESULT_RANGE_STATUS
    ;I2COut SDA,SCL,W_ADDRESS,[$00,$01]
    HI2CSend (0x00):HI2CSend (0x01)
    
    'REG_RESULT_RANGE_STATUS
    ;I2COut SDA,SCL,W_ADDRESS,[$14]
    HI2CSetAddress (W_ADDRESS)
    HI2CSend (0x14)
    'Lee 12 datos del Sensor:
    ;I2CIn  SDA,SCL,R_ADDRESS,[Str DataSensor]
    for tmp=1 to 12 ;datasensor is 12 byte array
      HI2CReceive (DataSensor(tmp))
    next tmp
    
    'Si el dato en DataSensor[0] es igual a 0x5E procesa distancia
    If DataSensor(1)=0x5E Then ;1 NOT 0
      Distance=DataSensor(11)*256+DataSensor(12) ;#combine integers
    end if
      'Representa distancia:
    HSerPrint ("Distance: "+str(Distance)+" mm")
    HSerPrint 13
    HSerPrint 10
    
    wait 100 ms
    
    loop
    ;
    'Consulta datos de sensor
    sub VerVL53
    'VL53L0X_REG_IDENTIFICATION_REVISION_ID
    ;I2CIn  SDA,SCL,R_ADDRESS,$C2,[DatoVL]
    HI2CSetAddress 0xc2
    HI2CReceive DatoVL
    ;  RsOut "Revision ID: ",Hex2 DatoVL,13,10
          'Read value
    HSerPrint ("Revision ID: "+str(DatoVL))
    HSerPrint 13
    HSerPrint 10
    
    'VL53L0X_REG_IDENTIFICATION_MODEL_ID
    ;I2CIn  SDA,SCL,R_ADDRESS,$C0,[DatoVL]
    HI2CSetAddress 0xc0
    HI2CReceive Datovl
    ;  RsOut "Device ID: ",Hex2 DatoVL,13,10
    HSerPrint ("Device ID: "+str(DatoVL))
    HSerPrint 13
    HSerPrint 10
    
    'VL53L0X_REG_PRE_RANGE_CONFIG_VCSEL_PERIOD
    ;I2CIn  SDA,SCL,R_ADDRESS,$50,[DatoVL]
    HI2CSetAddress 0x50
    HI2CReceive Datovl
    ;  RsOut "Pre Range Config Period: ",Hex2 DatoVL,13,10
    HSerPrint ("Pre Range Config Period: "+str(DatoVL))
    HSerPrint 13
    HSerPrint 10
    
    'VL53L0X_REG_FINAL_RANGE_CONFIG_VCSEL_PERIOD
    ;I2CIn  SDA,SCL,R_ADDRESS,$70,[DatoVL]
    HI2CSetAddress 0x70
    HI2CReceive DatoVL
    ;  RsOut "Fina Period: ",Hex2 DatoVL,13,10
    HSerPrint ("Fina Period: "+str(DatoVL))
    HSerPrint 13
    HSerPrint 10
    
    end sub
    
     

    Last edit: stan cartwright 2018-03-04
  • stan cartwright

    stan cartwright - 2018-03-04

    I edited the above code. Downloaded proton basic manual pdf. Not sure about hex2 and dec. The i2c values are strange. It doesn't print anything in the terminal but the commented out test loop works.

     

    Last edit: stan cartwright 2018-03-04
  • Anobium

    Anobium - 2018-03-04

    Suggest an I2C protocol analyser and the datasheet for the device would make this a lot easier.

     
  • stan cartwright

    stan cartwright - 2018-03-05

    data sheet says.
    Clock signal (SCL) generation is performed by the master device. The master device
    initiates data transfer. The I2C bus on the VL53L0X has a maximum speed of 400 kbits/s
    and uses a device address of 0x52.
    Figure 13. Data transfer protocol
    Information is packed in 8-bit packets (bytes) always followed by an acknowledge bit, Ac for
    VL53L0X acknowledge and Am for master acknowledge (host bus master). The internal
    data is produced by sampling SDA at a rising edge of SCL. The external data must be stable
    during the high period of SCL. The exceptions to this are start (S) or stop (P) conditions
    when SDA falls or rises respectively, while SCL is high.
    A message contains a series of bytes preceded by a start condition and followed by either a
    stop or repeated start (another start condition but without a preceding stop condition)
    followed by another message. The first byte contains the device address (0x52) and also
    specifies the data direction. If the least significant bit is low (that is, 0x52) the message is a
    master write to the slave. If the lsb is set (that is, 0x53) then the message is a master read
    from the slave.
    ; The ack thing is needed. I'm no good at this.
    The original proton code is the simplest I've found. The author upgraded it but that uses floats. The device is used through it's own api. 32 bit c stuff.

     
  • Anobium

    Anobium - 2018-03-05

    data sheet says.
    Clock signal (SCL) generation is performed by the master device. The master device
    initiates data transfer. The I2C bus on the VL53L0X has a maximum speed of 400 kbits/s
    and uses a device address of 0x52.

    Yes. So, you have the knowledge to set the baud rate.

    Figure 13. Data transfer protocol
    Information is packed in 8-bit packets (bytes) always followed by an acknowledge bit, Ac for
    VL53L0X acknowledge and Am for master acknowledge (host bus master). The internal
    data is produced by sampling SDA at a rising edge of SCL. The external data must be stable
    during the high period of SCL. The exceptions to this are start (S) or stop (P) conditions
    when SDA falls or rises respectively, while SCL is high.
    A message contains a series of bytes preceded by a start condition and followed by either a
    stop or repeated start (another start condition but without a preceding stop condition)
    followed by another message. The first byte contains the device address (0x52) and also
    specifies the data direction. If the least significant bit is low (that is, 0x52) the message is a
    master write to the slave. If the lsb is set (that is, 0x53) then the message is a master read
    from the slave.
    ; The ack thing is needed. I'm no good at this.

    Yes. So, you have used I2C discovery to proove the device is on address 0x52?

    The original proton code is the simplest I've found. The author upgraded it but that uses floats. The device is used through it's own api. 32 bit c stuff.

    Is the device 32 bit floats? or, is it integer?

     
  • stan cartwright

    stan cartwright - 2018-03-05

    The original proton code is integer.

    Dim DatoVL As Byte
    Dim DataSensor[12] As Byte
    Dim Distancia As Word
    

    Did I translate this ok?

    ;I2CIn  SDA,SCL,R_ADDRESS,[Str DataSensor]
    for tmp=1 to 12 ;datasensor is 12 byte array
      HI2CReceive (DataSensor(tmp))
    next tmp
    

    Str ??
    This line needs converting I2CIn SDA,SCL,R_ADDRESS,$C2,[DatoVL]
    $C2 is a vl53l0x register I'm guessing.
    It's another device sorted in rpi and arduino. Gcb, why not to? Like BMP/E 280 was.

     

    Last edit: stan cartwright 2018-03-05
  • stan cartwright

    stan cartwright - 2018-03-05

    i2c finder didn't find device. oh dear again.

     
    • Anobium

      Anobium - 2018-03-05

      Replace the device with a known working solution like a GLCD. Does that work? In not, make the known device work... resistors..... 101 of I2C.. discovery MUST WORK.

       
  • stan cartwright

    stan cartwright - 2018-05-01

    I need to convert
    'Read 12 raw data of Sensor:
    ;I2CIn SDA,SCL,R_ADDRESS,[Str DatoSensor] - proton basic
    where DatoSensor is dim DatoSensor(12) as byte to gcb.
    Is this correct? 0x52 is devicei2c address.
    for tmp=1 to 12
    I2CSTART
    I2CSEND( 0x52 )
    I2CSTART
    I2CSEND( 0x53 )
    I2CReceive( DatoSensor(tmp) , NACK ) ;read byte
    I2CSTOP
    next tmp

     
  • Anobium

    Anobium - 2018-05-01

    Depends. Depends on the protocol. You need to review the datasheet. Looks to me like you are reading the same location 12 times but I am guessing without the datasheet.

     
  • Anobium

    Anobium - 2019-02-11

    @Stan. I am about to look at this library. How far did you get? Much further?

     
  • Anobium

    Anobium - 2019-02-11

    My research from this morning. There is a good API reference guide and example code.

    Three attachments.

     
  • stan cartwright

    stan cartwright - 2019-02-11

    i2c address finder found r/w addresses.
    A picaxe user got results in picaxe basic. Here's the code and my attempt at converting to gcb. Not working though.

     
    • Anobium

      Anobium - 2019-02-11

      So, the question.

      A quick hack to get it going? or, a proper library?

       
  • stan cartwright

    stan cartwright - 2019-02-11

    The basic writes to inialise and then read the bytes with the distance is all needed to use the device.
    An include .h file is neater. Arduino has several.
    I'll try using it again to get it working.

     
    • Anobium

      Anobium - 2019-02-11

      I ha started.   I will wait for your work.

       
      • Anobium

        Anobium - 2019-02-17

        @Stan. Any progress? I am waiting.

         
        • stan cartwright

          stan cartwright - 2019-02-17

          A new device should arrive Tuesday.

           
  • stan cartwright

    stan cartwright - 2019-02-19

    new device arrived. i2c finder gives write 0x52, read 0x53.
    no luck with converting i2c code.

     
    • Anobium

      Anobium - 2019-02-19

      What have you tried? Share please.

       
      • stan cartwright

        stan cartwright - 2019-02-19

        Just the proton and picaxe code I posted.

         
      • stan cartwright

        stan cartwright - 2019-02-19

        Just the proton and picaxe code I posted.

         
  • Anobium

    Anobium - 2019-02-20

    I have started. I have confirmed I2C discovery using the I2C discovery.

    The I have commenced data read operations between the UNO to the Sensor.

    The datasheet shows the following table as critical reference check - I am not what is at addresses 0xC1, 0x51 and 0x61. I will have to understand, later, why these are important.

    So, the datasheet shows as the default values are show below:

    The little prototype initialises, the reads the bytes and words at the required locations. The results are shown below.

    Test sensor VL53L0x v20/02/19 by Anobium
                  Default      From Device
    Revision ID     0x10           0x10
    Device ID       0xEE           0xEE
    Address 0xC1    0xAA           0xAA
    Address 0x51    0x0099         0x0099
    Address 0x61    0x0000         0x0000
    

    The means that I have the device talking and the default values match the required values in the datasheet. This is a good start. I have readbyte and readword operational.

    :-)

     

    Last edit: Anobium 2019-02-20
  • Anobium

    Anobium - 2019-02-20

    I have been hunting for a table of the registers of this device.

    Then, I found this message from ST Product Support.

    Hello,
    VL53L0X is a complex device.
    Registers description is not possible [to produce a table of the registers] for this device due to complexity.
    It contains hundred of registers with inter-dependance and not straight forward content.
    Then, the choice has been to not provide a register list, but instead develop an friendly API.
    You can download the API and user's manual on st.com/VL53L0X.

    Interesting - they clearly think we are fools.

     
1 2 > >> (Page 1 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.