Menu

picaxe conversion

Help
2020-12-04
2021-02-18
<< < 1 2 3 4 5 6 7 > >> (Page 4 of 7)
  • stan cartwright

    stan cartwright - 2021-01-25

    Whoa! hold on!
    In the photos of nano and uno boards I've posted,
    portc.5 (a5) is hardware scl and portc.4 (a4) is hardware sda.
    Dunno what's going on now!

    William sir, I'm taking +5 and ground tof supply to the 6 pin header only as other pins are spi.
    I tried with and without 3.8K i2c pullups.
    If i2c finder found anything it was F4,F5.
    The finder version did seem to loop but the terminal wouls show no device and scroll then find it,,,then lose it...like it was to fast/slow dunno.

    Where is code for testing serial out to terminal.
    suppose have to number usarts...again not sure how from help.
    terminal would be default..usart0? and device usart1?
    doh. not seen serial to terminal for this device that works.
    serial is 5 bytes and linefeed or summat.

     

    Last edit: stan cartwright 2021-01-25
  • stan cartwright

    stan cartwright - 2021-01-25

    Evan- I will give reading serial 1 more try then post it to you...with a return stamp if 50p
    so you can get pissed off like me....I'm that considerate :)

     
  • stan cartwright

    stan cartwright - 2021-01-25

    The new i2c finder for 328 I tested with ssd1306 on a nano

     

    Last edit: stan cartwright 2021-01-25
    • Anobium

      Anobium - 2021-01-25

      Looks good to me.

       
  • stan cartwright

    stan cartwright - 2021-01-25

    I had the same results off another "328" i2c finder from your github but this latest seems
    specific for 328...although the other had a #chip 328 header.
    Unfortunately I tested with ssd1306 as it's i2c and r/w addresses found
    but tried tof10120 and nothing found.
    this was using same circuit as ssd1306 with 3.8K pullups.

    Evan, I'll post you the device to enjoy it....I've had enough joy using this device.
    I can do i2c nano and lgtnano https://www.youtube.com/watch?v=UB3nEY3Jt_w&feature=youtu.be

    I unplug the ssd1306 and try the tof10120 but not found.

     

    Last edit: stan cartwright 2021-01-25
  • stan cartwright

    stan cartwright - 2021-01-26

    Tried with uno and after 16 not found screens gave F4.
    This is at 100 or 400 with or without 4K7 resistors

     
  • stan cartwright

    stan cartwright - 2021-01-26

    In the i2c finder there's

            for DeviceID = 0 to 255
              DisplayNewLine = DeviceID % 16
              if DisplayNewLine = 0 Then
                HSerPrintCRLF
                HserPrint hex(DeviceID)
                HSerPrint ": "
              end if
              HSerPrint " "
              HI2CStart
              if HI2CWaitMSSPTimeout <> True then
    
                HI2CSend ( deviceID )
    
                if HI2CAckPollState = false then
                  HSerPrint   hex(deviceID)
                  HI2CSend ( 0)
                Else
                  HSerPrint "--"
                end if
    

    why isn't it

    if HI2CWaitMSSPTimeout = false then
    

    what's the difference?

     
  • Haroen

    Haroen - 2021-01-26

    Anobium: I have posted a revised I2C Discovery program for the UNO.
    Please review https://github.com/Anobium/Great-Cow-BASIC-Demonstration-Sources/blob/master/I2C_Solutions/I2C_Discovery/i2cHardwareDiscovery_to_Terminal_mega328p.gcb

    Works great!

    William: It would seem based upon your measurement that the TO1020 has no pullup on the SCL line (Pin6) . Is the measurement on PIN 5 to V+ the same?

    Yes, both are around 10M.

    William: Originally i2c was intended as a communication protocol between devices on a PCB where traces were relatively short. 10K Pullups were usually sufficient. Adding external leads requires increased source current (lower resistance Pullups) to overcome the added parasitic capacitance and therefore to produce a cleaner waveform.

    What can then (with lower resistance Pullups) be the maximum distance ?
    When there are even longer leads we should use serial instead?

    Stan: Where is code for testing serial out to terminal.

    I only have PICAXE working code that could be tranlated to GCB.
    https://picaxeforum.co.uk/threads/tof10120-laser-range-sensor-module.32191/post-335283

     
    • William Roth

      William Roth - 2021-01-26
      What can then (with lower resistance Pullups) be the maximum distance ?
      When there are even longer leads we should use serial instead?
      

      The max distance for an unbuffered I2c Bus is no more than around 2 or 3 meters and then the signal will look pretty rough. Greater distances can be achieved if a Buffer IC is used.

      RS232 is generally ok for up to 20 or 30ft. Depending on voltage levels.

      For distances over 30 ft or so the industrial standard is RS485/MODBUS.

       
  • Haroen

    Haroen - 2021-01-26

    Anobium: I have posted a revised I2C Discovery program for the UNO.

    This upgraded code with function comments should give a I2C discovery status, but the options 0 and 2 freezes the terminal and only sometimes work:
    0=NON_FOUND: Incorrect I2C ports selected!
    1=SUCCESFUL
    2=ERROR: Missing PullUp resistors or Check your connnections!

    '''A demonstration program for GCGB and GCB.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program searches for I2C devices and display their adresses to the attached PC terminal.
    '''This program uses the hardware implementation of I2C and TWI for the Microchip and ATMEL microprocessors.
    '''The microprocessor must have a suitable I2C or TWI module.
    '''The hardware serial connections are shown in the program.
    '''@author  TheoL plus works of EvanV
    '''@licence GPL
    '''@version 1.2a
    '''@date    25.01.2021
    '''********************************************************************************
    '''
    '''
    /*
    
    If you get this...NOTHING... but -- and you have the I2C data and clock connected... you may have them connected to the incorrect port.
    
        Show Hardware I2C Bus
    
             00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
        00:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        10:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        20:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        30:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        40:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        50:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        60:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        70:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        80:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        90:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        A0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        B0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        C0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        D0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        E0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
        F0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    
        End of Search
    ------------------------------------------------------------------------------------
    
    Example Serial display show the addresses of 0x78 and 0x79
    
    Show Hardware I2C Bus
    
         00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
    00:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    10:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    20:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    30:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    40:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    50:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    60:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    70:  -- -- -- -- -- -- -- -- 78 79 -- -- -- -- -- --
    80:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    90:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    A0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    B0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    C0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    D0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    E0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    F0:  -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
    
    End of Search
    ------------------------------------------------------------------------------------
    
    If you get this... then, check your connnections - you have NOT connected anything, or, you are missing the pullup resistors.
    
    
        Show Hardware I2C Bus
    
             00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
        00:
    ------------------------------------------------------------------------------------
    */
    
    ; ----- Configuration
    #chip mega328p,16
    #option Explicit
    ;Great Cow BASIC simplifies the configuration by setting the frequency and the configuration for you.
    
        'USART settings for USART1 on the chip which is sent via the USB to the PC
        #DEFINE USART_BAUD_RATE 9600
        #DEFINE USART_TX_BLOCKING
        #DEFINE USART_DELAY 0
    
        ; ----- Define Hardware settings for hwi2c
        ; Define I2C settings
        #define HI2C_BAUD_RATE 100
        #define HI2C_DATA PORTC.4   'William Roth: It should be sufficient to simply use "#Define HI2C Data", gcb doesn't need "PORTC.4".  Anobium: However, the two constants(HI2C_DATA&CLOCK) are used for documentation and should be retained.
        #define HI2C_CLOCK PORTC.5  'William Roth: "#Define HI2C_Clock" does nothing at all except use up space.                           Anobium: However, the two constants(HI2C_DATA&CLOCK) are used for documentation and should be retained.
        'I2C pins need to be input for SSP module when used on Microchip device
        Dir HI2C_DATA in
        Dir HI2C_CLOCK in
        HI2CMode Master
    
      ; ----- Main body of program commences here.
        ' Now assumes Serial Terminal is operational
        Dim DeviceID as byte
        Dim DisplayNewLine as Byte
        Dim I2CsearchStatus as Byte               'Pseudo-boolean variable(0=NonFound_Incorrect I2C ports selected, 1=Found, 2=Error_Missing PullUp resistors or Check your connnections).
    
        Do
            HSerPrintCRLF 2
            HSerPrint "Show Hardware I2C Bus"
            HSerPrintCRLF 2
            HSerPrint "     "
            for DeviceID = 0 to 15
              HSerPrint hex(deviceID)             'First row: "00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F".
              HSerPrint " "
            next
            for DeviceID = 0 to 255
              DisplayNewLine = DeviceID % 16
              if DisplayNewLine = 0 Then
                HSerPrintCRLF
                HserPrint hex(DeviceID)           'First column: "00" t/m "F0".
                HSerPrint ": "
              end if
              HSerPrint " "
              HI2CStart
              if HI2CWaitMSSPTimeout <> True then 'I2C timeout?
                HI2CSend (DeviceID)               'Found I2Caddress.
                if HI2CAckPollState = false then
                  I2CsearchStatus=1               'Found something! But can also be "Error_Missing PullUp resistors or Check your connnections".
                  HSerPrint hex(DeviceID)       'Display found I2Caddress in table.
                  HI2CSend (0)
                Else
                  HSerPrint "--"
                end if
              Else
                'Check and Save for "Error_Missing PullUp resistors or Check your connnections"!
                I2CsearchStatus=2
                HSerPrintCRLF
                hserprint "ERROR: Missing PullUp resistors or Check your connnections!"
                HSerPrintCRLF
              end if
              HI2CStop
            Next
            HSerPrintCRLF 2
            HSerPrint   "End of Search"           'Search end.
            HSerPrintCRLF 2
            Select Case I2CsearchStatus           'Analyse I2C search.
              Case 0
                hserprint "NON_FOUND: Incorrect I2C ports selected!"
                HSerPrintCRLF
              Case 1
                hserprint "SUCCESFUL"
                HSerPrintCRLF
              Case 2
                hserprint "ERROR: Missing PullUp resistors or Check your connnections!"
                HSerPrintCRLF
            End Select
            HSerPrintCRLF 2
            I2CsearchStatus=0                     'Reset variable.
            Wait 3 s
        Loop
    END
    
     
  • Haroen

    Haroen - 2021-01-26

    Checked, was OK.

    Would be great if someone could find and fix the problem in the code that the options 0 and 2 freezes the terminal and only sometimes work.

    Thanks.

     
    • Anobium

      Anobium - 2021-01-26

      OK. I see.
      You need to change the code. Now that you mention the issue..... :-)

      Essentially, do all the HI2C code in a block, capturing the status is appropriate variables. Then, after the HI2C code block has completed do the examination of the HI2C status variables.

      Why? You are: 1) Holding the IC2 Clock - not good practice. 2) Changing the status the registers and (I think) there is a register shared between HI2C and USART.

      Evan

       
  • stan cartwright

    stan cartwright - 2021-01-26

    It took a few scans to show results for tof10120.
    I just posted it to you. 2nd class post.

     

    Last edit: stan cartwright 2021-01-26
  • Haroen

    Haroen - 2021-01-27

    1) Holding the IC2 Clock...

    By using these 3x "HSerPrint" in the HI2CWaitMSSPTimeout?

    HSerPrintCRLF
    hserprint "ERROR: Missing PullUp resistors or Check your connnections!"
    HSerPrintCRLF
    

    It should be sufficient with only I2CsearchStatus=2.

    2) Changing the status the registers and (I think) there is a register shared between HI2C and USART.

    I can't find any I2C code different with your original.
    It also acts the same in both this and the original code seen in the terminal window when I remove the scl or sda wire.

     
    • Anobium

      Anobium - 2021-01-27

      OK. Try using Putty as the terminal. Is it the terminal software?

       
  • Haroen

    Haroen - 2021-01-27

    I installed Putty but it doen't want to open the connection.

     

    Last edit: Haroen 2021-01-27
  • Anobium

    Anobium - 2021-01-27

    You have to close the other terminal software.

     
  • Haroen

    Haroen - 2021-01-27

    I did close gcb terminal and now the Great Cow BASIC too.
    But it doen't want to open the connection.

     
    • Chris Roper

      Chris Roper - 2021-01-27

      Windows has locked the Port.
      Unplug the USB cable, wait a few seconds and Plug plug it back in.

       
      • stan cartwright

        stan cartwright - 2021-01-27

        yes

         
  • Haroen

    Haroen - 2021-01-28

    Sorry, I just get an Windows error ping sound plug-in and plug-out USB.
    I tried every option of the tree menu with only response the ping sound.
    No error messages at all.

    Uninstalled this 64bits version (putty-64bit-0.74-installer.msi) and now installed the putty-0.74-installer.msi.
    But still the same ping sound.

    Putty doesn't like my pc :-)

     

    Last edit: Haroen 2021-01-28
  • William Roth

    William Roth - 2021-01-28

    Verify the com Port in Device Manager. Working ?

    Open Putty . At the top click on Session.
    Connection Type >>> Serial
    Manually Enter "COM7"
    Manually Enter the Baud Rate

    Click on OPEN at the bottom.

    The terminal should open.

    Putty is odd and somewhat clunky. You cannot open the terminal from the Serial page
    It must be opened from the Session Page.

     
  • Haroen

    Haroen - 2021-01-28

    Yes William, that's it!
    I chose the wrong Connection>Serial in the left tree window.
    It's the same result as the gcb terminal.
    Top section of the jpg is with correct I2C wire connections,
    Bottom section is when I removed a I2C wire.

     

    Last edit: Haroen 2021-01-28
  • Anobium

    Anobium - 2021-01-28

    @Haroen

    I think we will need an analysis of the I2C bus.

    Did you buy a $7 analyser from Amazon?

     
<< < 1 2 3 4 5 6 7 > >> (Page 4 of 7)

Log in to post a comment.