Menu

picaxe to gcb i2c

Help
2018-05-16
2018-05-17
  • stan cartwright

    stan cartwright - 2018-05-16

    Can any once picaxe users help me convert this picaxe code please?
    hi2csetup I2CMASTER, $52, i2cfast, i2cbyte
    hi2cin $C0,(b0)
    I have

    #chip mega328p, 16
    #define HI2C_BAUD_RATE 400
    #define HI2C_DATA PORTC.5
    #define HI2C_CLOCK PORTC.4
    HI2CMode Master
    #define W_ADDRESS 0x52
      HI2CStart
      HI2CSend W_ADDRESS
      HI2CSend W_ADDRESS+1
      HI2CSend 0xc0
      HI2CReceive tmp
      HI2CStop
    

    This is worse
    hi2cin $14,(da1,da2,da3,da4,da5,da6,da7,da8,da9,da10,da11 ,da12)
    I tried

      HI2CStart
    'Request value
    for ctr=1 to 12
      HI2CSend W_ADDRESS
      HI2CSend W_ADDRESS+1
      HI2CSend 0x14
    'Read value
      HI2CReceive da(ctr)
    next ctr
    HI2CStop
    

    It doesn't work. What is the translation please.

     

    Last edit: stan cartwright 2018-05-16
  • Anobium

    Anobium - 2018-05-16

    be a lot easier ro read the datasheet. what is the device?

     
  • stan cartwright

    stan cartwright - 2018-05-16

    VL50L0X. i2c version
    picaxe guys were asking for info so posted working proton basic code and man buzby changed it to picaxe basic and it worked.
    I'm trying to change it to gcb but proton and picaxe are similar but gcb is totally different.
    Forget the device, it's the translation.
    If the device allows send multiple bytes or words how to recieve them.
    There's i2c recieve in c++ that recieves bytes into an array to.
    I've spent many hours on the spi version and now this i2c version.
    I'm not digging out a picaxe board or using an arduino sketch.
    Also add there's no info of registers just the manufacturers c++ api.

     

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

    stan cartwright - 2018-05-16

    I could adapt this bmp280 code but can't see where BME280Address is defined. It's not BME280_I2C_ADDRESS.

    BME280_ReadData ( in BME280Address,  in BME280GetByteData as byte, out BME280_DataBuffer() ) 
    HI2CStart
    HI2CSend(BME280_I2C_ADDRESS)
    HI2CSend(BME280Address)
    HI2CReStart
    HI2CSend(BME280_I2C_ADDRESS+1)               ;indicate a read operation
    
    For BME280_DataBuffer_Pointer = 0 to (BME280GetByteData -1)
      HI2CReceive BME280_DataBuffer( BME280_DataBuffer_Pointer ), ACK
    next
    HI2CReceive BME280_DataBuffer( BME280GetByteData  ), NACK
    HI2CStop
    ;
    BME280_ReadByte ( in BME280Address,  out BME280OutByteData )
    HI2CStart
    HI2CSend(BME280_I2C_ADDRESS)
    HI2CSend(BME280Address)
    HI2CReStart
    HI2CSend(BME280_I2C_ADDRESS+1)               ;indicate a read operation
    HI2CReceive BME280OutByteData, NACK
    HI2CStop
    ;
    BME280_WriteData ( in BME280Address,  in BME280SendByte as byte )
    HI2CStart
    HI2CSend(BME280_I2C_ADDRESS)
    HI2CSend(BME280Address)
    HI2CSend(BME280SendByte)
    HI2CStop
    
     
  • mmotte

    mmotte - 2018-05-17

    Look on line 52 of the BME280.h file

    #define BME280_I2C_ADDRESS  0xEC
    

    This was the default on all the little BME280 modules that i practiced on.

     
  • stan cartwright

    stan cartwright - 2018-05-17

    It does not get to first hserprint.

    do
    ;  hi2cin $C0,(b0)
    HI2CStart
    HI2CSend(W_ADDRESS)
    HI2CSend(0xc0)
    HI2CReStart
    HI2CSend(W_ADDRESS+1)               ;indicate a read operation
    HI2CReceive tmp, NACK
    HI2CStop
    ;  sertxd (b0,cr,lf) ' EE
    hserprint str(tmp)
    
     
  • mmotte

    mmotte - 2018-05-17

    VL50L0X looks interesting. I could have used one 4 years ago to figure bulk density in a drum of dry material.

    I do not have a .pdf for the module. Flying blind. Brief look at arduino code looks like the address is 0x29 and if the read bit is attached ion the same way then 0x52 seems right for w_address.

    Your first post sent the 0xc0 after the read request? need data sheet.

    Code doesn't look like your problem. Check your hook ups.
    Get a data sheet and read.

     
  • stan cartwright

    stan cartwright - 2018-05-17

    The data sheet tells me nothing. There's a c and python api you're supposed to use. Not much info about registers. Some code where the author has gleaned info and link to more code which I'm trying to convert. http://www.protonbasic.co.uk/showthread.php/76045-VL53L0X-laser-ranging-sensor

     
  • Anobium

    Anobium - 2018-05-17

    This is very good. This explains APIs

     
  • stan cartwright

    stan cartwright - 2018-05-17

    Thanks. I've had one since last year and spent too much time looking at c code.
    The first one I could find the i2c address but later couldn't. I bought a replacement and that has done the same.
    The unbranded ones are cheap but don't seem reliable.
    There are other laser range finders but ott for a simple robot project.
    I got a few £1 red laser units and a £1 laser sensor to play with.

     

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.