I2C Help Pic18F47K40 Please!


+ Reply to Thread
Results 1 to 14 of 14

Thread: I2C Help Pic18F47K40 Please!61 days old

  1. #1
    Member craig's Avatar
    Join Date
    Dec 2010
    Posts
    215
    Thumbs Up
    Received: 10
    Given: 0
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default I2C Help Pic18F47K40 Please!

    Hello I have an existing project working on a Pic 18F47J53 where I Read a VL53L0x Laser which works Perfectly.
    I am porting this project over to a Pic 18F47K40, I have everything working Except I cannot get the VL53L0x to
    work correctly on the 18F47K40 and I cannot understand why, I am using I2CIn, I2COut commands.
    This Code works Perfectly on the 18F47J53 but, I don't get the correct readings on the 18F47K40 device.
    Can someone Please explain to me where I am going wrong or If I need to rather use the
    I2C Libraries For MSSP1 & MSSP2 which Les Wrote! There must be a SFR I am missing to get this to work on the K Devices.
    Any Help Is Very Much Appreciated!

    Kind Regards
    Craig


    '-----------------------------------------------------------------------------------------
    ' Setup the VL53L0x - TOF Lazer Unit "EAST/POLOLU"
    ' VL53L0x Registers Write and Read
    '-----------------------------------------------------------------------------------------
    Device = 18F47K40

    Config_Start
    FEXTOSC = HS ;HS (crystal oscillator) above 8 MHz; PFM set to high power
    RSTOSC = EXTOSC ;EXTOSC operating per FEXTOSC bits (device manufacturing default)
    CLKOUTEN = OFF ;CLKOUT function is disabled
    CSWEN = On ;Writing to NOSC and NDIV is allowed
    FCMEN = On ;Fail-Safe Clock Monitor enabled
    MCLRE = INTMCLR ;If LVP = 0, MCLR pin function is port defined function; If LVP =1, RE3 pin fuction is MCLR
    PWRTE = OFF ;Power up timer disabled
    LPBOREN = OFF ;ULPBOR disabled
    BOREN = OFF ;Brown-out Reset disabled
    BORV = VBOR_2P45 ;Brown-out Reset Voltage (VBOR) set to 2.45V
    ZCD = OFF ;ZCD disabled. ZCD can be enabled by setting the ZCDSEN bit of ZCDCON
    PPS1WAY = On ;PPSLOCK bit can be cleared and set only once; PPS registers remain locked after one clear/set cycle
    STVREN = On ;Stack full/underflow will cause Reset
    Debug = OFF ;Background debugger disabled
    XINST = OFF ;Extended Instruction Set and Indexed Addressing Mode disabled
    WDTCPS = WDTCPS_31 ;Divider ratio 1:65536; software control of WDTPS
    WDTE = OFF ;WDT Disabled
    WDTCWS = WDTCWS_7 ;window always open (100%); software control; keyed access not required
    WDTCCS = SC ;Software Control
    WRT0 = OFF ;Block 0 (000800-003FFFh) not write-protected
    WRT1 = OFF ;Block 1 (004000-007FFFh) not write-protected
    WRT2 = OFF ;Block 2 (008000-00BFFFh) not write-protected
    WRT3 = OFF ;Block 3 (00C000-00FFFFh) not write-protected
    WRT4 = OFF ;Block 4 (010000-013FFFh) not write-protected
    WRT5 = OFF ;Block 5 (014000-017FFFh) not write-protected
    WRT6 = OFF ;Block 6 (018000-01BFFFh) not write-protected
    WRT7 = OFF ;Block 7 (01C000-01FFFFh) not write-protected
    WRTC = OFF ;Configuration registers (300000-30000Bh) not write-protected
    WRTB = OFF ;Boot Block (000000-0007FFh) not write-protected
    WRTD = OFF ;Data EEPROM not write-protected
    SCANE = On ;Scanner module is available for use, SCANMD bit can control the module
    LVP = On ;Low voltage programming enabled. MCLR/VPP pin function is MCLR. MCLRE configuration bit is ignored
    Cp = OFF ;UserNVM code protection disabled
    CPD = OFF ;DataNVM code protection disabled
    EBTR0 = OFF ;Block 0 (000800-003FFFh) not protected from table reads executed in other blocks
    EBTR1 = OFF ;Block 1 (004000-007FFFh) not protected from table reads executed in other blocks
    EBTR2 = OFF ;Block 2 (008000-00BFFFh) not protected from table reads executed in other blocks
    EBTR3 = OFF ;Block 3 (00C000-00FFFFh) not protected from table reads executed in other blocks
    EBTR4 = OFF ;Block 4 (010000-013FFFh) not protected from table reads executed in other blocks
    EBTR5 = OFF ;Block 5 (014000-017FFFh) not protected from table reads executed in other blocks
    EBTR6 = OFF ;Block 6 (018000-01BFFFh) not protected from table reads executed in other blocks
    EBTR7 = OFF ;Block 7 (01C000-01FFFFh) not protected from table reads executed in other blocks
    EBTRB = OFF ;Boot Block (000000-0007FFh) not protected from table reads executed in other blocks
    Config_End

    ;**** End of Fuse Configurator Settings ****
    ;-------------------------------------------------------------------------------

    Declare Xtal 25

    TRISC = %00111000
    ANSELC = %00000000 ' Portc Digital
    LATC = 0x00
    WPUC = 0x00
    ODCONC = 0x00
    INLVLC = 0xFF

    Declare Slow_Bus On ' Slow I2C Bus Down
    Declare Hbus_Bitrate 400 ' SET FOR LAZER = 400KHz Data Rate
    $define I2C_SCL_VLPin PORTC.3 ' PORTD.0 (WHITE) Symbol SCL (OUTPUT)- VL53L0x TOF Sensor
    $define I2C_SDA_VLPin PORTC.4 ' PORTD.1 (BLUE) Symbol SDA (INPUT) - VL53L0x TOF Sensor

    Include "Software_I2C.inc" ' Include Les's I2C File

    Symbol W_ADDRESS = $52
    Symbol R_ADDRESS = $53

    Dim DatoSensor[12] As Byte
    Dim Distance As Word
    '--------------------------------------------------------------------------

    VL53Lx:

    'System Range Start
    I2COut I2C_SDA_VLPin,I2C_SCL_VLPin,W_ADDRESS,[$00,$01]
    DelayMS 5

    'Range status
    I2COut I2C_SDA_VLPin,I2C_SCL_VLPin,W_ADDRESS,[$14]
    DelayMS 5

    ' Read The 12 Bit Raw Data Of The VL53L0x Sensor:
    I2CIn I2C_SDA_VLPin,I2C_SCL_VLPin,R_ADDRESS,[Str DatoSensor]
    Print At 1,1,"Dist: ",Dec DatoSensor[11]
    DelayMS 25 ' Delay to see whats happening
    '--------------------------------------------------------------------------------------------------
    Distance=DatoSensor[10]*256+DatoSensor[11]

    DistFlag = 115 ' Flag Set to Show we have Loaded a Measurement into Distance Variable

    ' Effective SPAD Return Count
    SPAD = DatoSensor[2] + DatoSensor[3]/255

    ' Signal Rate
    Signal = DatoSensor[6]*256+DatoSensor[7]

    ' Ambient Rate
    Ambient= DatoSensor[8]*256+DatoSensor[9]

    ' Print Readings
    Print At 2,1,"D: ",Dec Distance," "
    DelayMS 25
    Click image for larger version

Name:	I2C Test 18F47K40_VL53L0x.jpg
Views:	11
Size:	12.9 KB
ID:	3911
    Return
    End
    '----------------------------------------------------------------------------------------------------

  2. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  3. #2
    Member craig's Avatar
    Join Date
    Dec 2010
    Posts
    215
    Thumbs Up
    Received: 10
    Given: 0
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    PLEASE HELP!! Does anyone know if there are issues with the I2C on the 18F47K40 Device, I have spent hours trying to get this to work
    but, am out of ideas. Has anyone else had problems with the I2C on this device, I have used 5K6 Pull Up Resistors to +5v any help is
    much appreciated!

    Craig

  4. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  5. #3
    Member keytapper's Avatar
    Join Date
    Jun 2019
    Posts
    192
    Thumbs Up
    Received: 8
    Given: 5
    Total Downloaded
    331.75 MB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    I never got to use 18F, but I'd suggest to analyze the I2C connection by the help of a digital analyzer.

  6. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  7. #4
    Member craig's Avatar
    Join Date
    Dec 2010
    Posts
    215
    Thumbs Up
    Received: 10
    Given: 0
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Keytapper as you can see from my original post that is exactly what I have been doing!
    There are obviously huge changes in how the MSSP works in the K devices in relation
    to the J devices.
    Last edited by craig; 29th March 2020 at 07:57.

  8. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  9. #5
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,352
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    If Les wrote libs especially for the k40 I sure he did it for a reason, have you tried them?

    Unfortunately your LA pic is to small to see anything other than the fact that your getting something, which is a good start. Perhaps a bigger picture (attach it if you cant figure out how to embiggen it).

    Way off base. My spell checker changes enbiggen into embiggen - bart strikes)
    George.

  10. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  11. #6
    Member craig's Avatar
    Join Date
    Dec 2010
    Posts
    215
    Thumbs Up
    Received: 10
    Given: 0
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Hi George
    I found under Proton Support Files:
    I2C Libraries For MSSP1 & MSSP2, Are there any other places where the Libraries for the K Devices are Kept?
    I am now going to try using this library and see what happens as I cannot come right using I2Cin & I2Cout Commands.
    I will take another picture with the LA and post the results.
    Thanks for the help.
    Craig

  12. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  13. #7
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    524
    Thumbs Up
    Received: 60
    Given: 0
    Total Downloaded
    408.14 MB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Just for reference, none of these lines has anything to do with I2CIn and I2COut...
    Code:
    Declare Slow_Bus On ' Slow I2C Bus Down
    Declare Hbus_Bitrate 400 ' SET FOR LAZER = 400KHz Data Rate
    
    Include "Software_I2C.inc" ' Include Les's I2C File
    The slow bus setting for the bit-banged I2CIn/I2COut is:
    Code:
    Declare I2C_Slow_Bus On    ' Slow I2C Bus Down
    You might try changing the INLVLC = 0 so that the pins are TTL level instead of ST.

  14. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  15. #8
    Member craig's Avatar
    Join Date
    Dec 2010
    Posts
    215
    Thumbs Up
    Received: 10
    Given: 0
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Thank you Tumbleweed!!
    I cleaned up everything and did some more testing using I2cIn/I2cOut but, It still does Not work so I decided to go back to basics and use
    the HBusIn/HBusOut commands and it works perfectly. I cannot understand why It will not function using the I2CIn/I2COut Commands,
    this remains a mystery to me?

    Kind Regards
    Craig

    Example Working Code 18F47K40 - VL53L0x Laser Sensor:

    VL53Lx:
    HBusOut W_ADDRESS,[$00,$01]
    DelayMS 5

    HBusOut W_ADDRESS,[$14]
    DelayMS 5

    HBusIn R_ADDRESS,[Str DatoSensor]Distance = DatoSensor[10]*256+DatoSensor[11]

    DistFlag = 115 ' Flag Set to Show we have Loaded a Measurement into Distance Variable

    ' Effective SPAD Return Count
    SPAD = DatoSensor[2] + DatoSensor[3]/255

    ' Signal Rate
    Signal = DatoSensor[6]*256+DatoSensor[7]

    ' Ambient Rate
    Ambient = DatoSensor[8]*256+DatoSensor[9]

    ' Print Readings:
    Print At 1,1,"D: ",Dec Distance," ", "mm"
    DelayMS 25

    Return
    Last edited by craig; 29th March 2020 at 22:29.

  16. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  17. #9
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,352
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Has the K40 got slew? Other than that I can't see why bit banged I2C wouldn't work across pretty much any PIC device UNLESS the actual clock is not the same as the declared clock. I see you have a 25MHz clock, are you sure that's really what is happening?

    I'm sure most peeps would say its a waste of time but when I encounter a new device, I figure out how the clock works and write a blinky.

    I also had a play with VL53L0x but got poor results. The problem with ST is that they don't want you to access them directly, they want you to use their lib. To achieve this they make you load a bunch of constants to the device, without which result are pretty sketchy. Look at the code Les created for VL6180x. Even thought the 53 is a superior device you'll get much more accurate results with the 61 with Les's code.

    I found simplified code for the 53 which seems to fit the bill but the C is quite beyond me. The guy has simplifed and converted a Arduino lib. If anyones feeling iso bored https://github.com/bitbank2/VL53L0X
    George.

  18. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  19. #10
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    524
    Thumbs Up
    Received: 60
    Given: 0
    Total Downloaded
    408.14 MB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Has the K40 got slew?
    Yes it does. The current compiler sets it to normal speed as part of the "SetAllDigital" initialization that Les does automatically now.

  20. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  21. #11
    Member craig's Avatar
    Join Date
    Dec 2010
    Posts
    215
    Thumbs Up
    Received: 10
    Given: 0
    Total Downloaded
    1.52 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Hi George & Tumbleweed
    I always run two led's in the background to make sure the clock is running as a start. I ran the clock as External HS @ 25Mhz and also tried using the Internal Clock Running at 64Mhz
    but, the results didn't change. I even used MCC from Mplab to see If I hadn't missed anything but, it stayed the same. The accuracy is Ok but, I will definitely look into Les's Code Examples.
    Thanks again for your help
    kind regards
    Craig

  22. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  23. #12
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,352
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    It's not a matter of if the clock is running rather that the actual clock is the same as the declared XTAL. To be sure create a blinky 500ms on, 500ms off then start a stopwatch and count to 60.

    I see that AllDigit is not given in the posted code.

    I seem to have either lost a post or gone all wibbilly wobbily.
    George.

  24. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  25. #13
    Senior Member tumbleweed's Avatar
    Join Date
    May 2011
    Posts
    524
    Thumbs Up
    Received: 60
    Given: 0
    Total Downloaded
    408.14 MB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Les has the code for "SetAllDigital" included automatically for you now... do nothing and you get it.

  26. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

  27. #14
    Prolific Poster towlerg's Avatar
    Join Date
    Mar 2012
    Posts
    2,352
    Thumbs Up
    Received: 83
    Given: 183
    Total Downloaded
    5.30 GB

    0 Not allowed!

    Default Re: I2C Help Pic18F47K40 Please!

    Sweet, thanks for the info.
    George.

  28. Attention

    This valuable resource relies upon the very small amount of revenue generated by displaying online advertisements to our visitors.

    The advertisements we display are relevant to this web site and your browsing history

    Please consider supporting us by disabling your ad blocker.


    Note: Some users have reported issues related to ad-blockers rendering parts of this wesite unusable,
    where possible we will rectify the issues to enable you to use this resource with adblocking enabled.

    If you can, please report issues in the forum area WebSite / Forum Issues


    Thank you for your attention.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

     

Similar Threads

  1. PIC18F47K40 and Hserout
    By Valter in forum Proton Plus Compiler v3
    Replies: 11
    Last Post: 21st March 2019, 07:05
  2. Hserout2 does not work on PIC18F47K40
    By gtv_pic in forum Proton Plus Compiler v3
    Replies: 5
    Last Post: 6th January 2019, 19:13
  3. Problem with Serial Port 1 on PIC18F47K40
    By gtv_pic in forum Proton Plus Compiler v3
    Replies: 8
    Last Post: 9th December 2018, 16:28
  4. I2C PIC18f47K40
    By krizpin in forum Master Synchronous Serial Port (MSSP) module / 3-wire SPI / I2C / Master and Slave modes
    Replies: 2
    Last Post: 23rd January 2018, 21:27
  5. [SOLVED !] PIC18F47K40 + Proton Devboard
    By Sean_Goddard in forum Proton Development Board
    Replies: 0
    Last Post: 8th October 2017, 14:54

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts