+ Reply to Thread
Results 1 to 18 of 18
  1. #1
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default 18F45K40 Can't set PORTD.1

    For 18F45K40, I can not set PORTD.1

    LATD.1 = 1 does not work.
    PORTD.1 = 1 does not work.
    HIGH PORTD.1 does not work.
    HIGH LATD.1 does not work.
    ASM does not work.

    But if I use another compiler it works.

    So where does it come from?
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  • #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,264

    Default Re: 18F45K40 Can't set PORTD.1

    Are you sure the PIC is running?
    Are you using the deafult CONFIG with PBP and with "the other" compiler? They might be different...
    Can you toggle other pins?

    The output driver/buffer still works when ANSEL is not cleared but it can STILL cause RMW-issues so as far as I can see
    Code:
    ANSELD.1 = 0
    TRISD.1 = 0
    LATD.1 = 1
    should do it.

    /Henrik.

  • #3
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default Re: 18F45K40 Can't set PORTD.1

    Quote Originally Posted by HenrikOlsson View Post
    Are you sure the PIC is running?
    Are you using the deafult CONFIG with PBP and with "the other" compiler? They might be different...
    Can you toggle other pins?

    The output driver/buffer still works when ANSEL is not cleared but it can STILL cause RMW-issues so as far as I can see
    Code:
    ANSELD.1 = 0
    TRISD.1 = 0
    LATD.1 = 1
    should do it.

    /Henrik.

    Thank you Henrik for the return.
    The code works with PBP and the PIC runs for sure; come on .
    I can get everything from what the code does. I send data, receive data, set 7-segment leds etc...,
    Only, my RXLED does not get set by PBP and it is on PORTD.1.


    The exact same code and the exact same config is used with the both compilers.
    That is why I am thinking about the PBP.
    Last edited by sayzer; - 23rd June 2019 at 18:20.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  • #4
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,264

    Default Re: 18F45K40 Can't set PORTD.1

    You know that assumption is the mother of all fuck-ups, don't you? :-)

    You didn't say ANYTHING about what you were doing, that you had "other" code running etc, how could I know that? Besides, you said ASM doesn't work either so then I don't find it likely to be an issue with the compiler since anything ASM is passed right by the compiler to the assembler.

    Anyway, if it was me I'd start with a clean slate and concentrate ONLY on the issue at hand - try getting PortD.1 to toggle. Just a few lines of code. If it works with one compiler and not the other try examining the generated assembly listing to see if you can spot the difference. Post them both here... (and what's that other compiler?).

    /Henrik.

  • #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default Re: 18F45K40 Can't set PORTD.1

    Quote Originally Posted by HenrikOlsson View Post
    You know that assumption is the mother of all fuck-ups, don't you? :-)

    You didn't say ANYTHING about what you were doing, that you had "other" code running etc, how could I know that? Besides, you said ASM doesn't work either so then I don't find it likely to be an issue with the compiler since anything ASM is passed right by the compiler to the assembler.

    Anyway, if it was me I'd start with a clean slate and concentrate ONLY on the issue at hand - try getting PortD.1 to toggle. Just a few lines of code. If it works with one compiler and not the other try examining the generated assembly listing to see if you can spot the difference. Post them both here... (and what's that other compiler?).

    /Henrik.
    I agree with all you said. You are right.

    But after I tried everything to my best knowledge, I finally posted the issue here. Sorry for less information posted.

    I think it may not be ethical to name the other compiler here ??
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  • #6
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,264

    Default Re: 18F45K40 Can't set PORTD.1

    I don't think that would (or should) be a problem but you're the moderator :-)
    I'm afraid, I for one, can't help you without more information, actual code, produced assembly listings and what not (not saying I'll be able to say what the problem is even WITH that but without I'm clueless), I'm not sure I've got an 45K40 around for testing.

    /Henrik.

  • #7
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: 18F45K40 Can't set PORTD.1

    according to my data sheet portd.1 is open drain by default
    This is more entertaining than Free to Air TV

  • #8
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,264

    Default Re: 18F45K40 Can't set PORTD.1

    Nice catch Richard!
    However, looking at the datasheet the ODCOND register defaults to $00 which is push/pull for all pins. Nothing in the errata either.

    Which datasheet are you looking at?

    I suppose trying ODCOND=0 is worth a shot!

  • #9
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: 18F45K40 Can't set PORTD.1

    the wrong one by the looks of it , ODCOND does default to 0 , i have correct one now

    This is more entertaining than Free to Air TV

  • #10
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default Re: 18F45K40 Can't set PORTD.1

    The code below, does not turn on PORTD.1.
    But, when I compile it with "other compiler" which has "delayms" command instead of "pause", it works as expected.
    The settings for both compilers are identical.

    Richard, I already had this odcon in the code.

    This must be coming from somewhere else.

    Code:
    #CONFIG
        CONFIG FEXTOSC = HS	    
        CONFIG RSTOSC = EXTOSC_4PLL
        CONFIG CLKOUTEN = OFF	   
        CONFIG CSWEN = ON	    
        CONFIG FCMEN = OFF	    
        CONFIG MCLRE = INTMCLR
        CONFIG PWRTE = ON	   
        CONFIG LPBOREN = OFF
        CONFIG BOREN = ON	  
        CONFIG BORV = VBOR_285	
        CONFIG ZCD = OFF	   
        CONFIG PPS1WAY = OFF
        CONFIG STVREN = OFF	 
        CONFIG DEBUG = OFF	  
        CONFIG XINST = OFF	  
        CONFIG WDTCPS = WDTCPS_31	
        CONFIG WDTE = ON	    
        CONFIG WDTCWS = WDTCWS_7	
        CONFIG WDTCCS = LFINTOSC
        CONFIG WRT0 = ON	  
        CONFIG WRT1 = ON	  
        CONFIG WRT2 = ON	  
        CONFIG WRT3 = ON	  
        CONFIG WRTC = ON	  
        CONFIG WRTB = ON	  
        CONFIG WRTD = OFF	  
        CONFIG SCANE = OFF	  
        CONFIG LVP = OFF	    
        CONFIG CP = ON	    
        CONFIG CPD = ON	    
        CONFIG EBTR0 = ON
        CONFIG EBTR1 = ON
        CONFIG EBTR2 = ON
        CONFIG EBTR3 = ON
        CONFIG EBTRB = ON
    #ENDCONFIG
    
    Clear
                             
    'OSCCON2 = %00100000   ' Ext+4xPLL
    
    '========================
    DEFINE OSC 64
    
    
    TRISA = 0
    TRISB = 0
    TRISC = 0
    TRISD = 0
    TRISE = 0
    
    PORTA = 0
    PORTB = 0
    PORTC = 0
    PORTD = 0
    PORTE = 0
    
    LATA = 0
    LATB = 0
    LATC = 0
    LATD = 0
    LATE = 0
    
    ANSELA = 0
    ANSELB = 0
    ANSELC = 0
    ANSELD = 0
    ANSELE = 0
    
    ADCON0 = 0
    ADCON1 = 0
    ADCON2 = 0
    ADCON3 = 0
    
    ADREF = 0   ; Vref = Vdd & Vss
    ADPCH = 0   ; select RA0/AN0
    ADACQ = 0   ; software controlled acquisition time
    ADCAP = 0   ; default S&H capacitance
    ADRPT = 0   ; no repeat measurements
    ADACT = 0   ; auto-conversion disabled
    
    CM1CON0 = 0
    CM2CON0 = 0
    
    SSP1CON1 = 0
    SSP2CON1 = 0
    
    SLRCONA = 255
    SLRCONB = 255
    SLRCONC = 255
    SLRCOND = 255
    SLRCONE = 255
    
    INLVLA = 0
    INLVLB = 0
    INLVLC = 0
    INLVLD = 0
    INLVLE = 0
    
    ODCONA = 0
    ODCONB = 0
    ODCONC = 0
    ODCOND = 0
    ODCONE = 0
    
    DigTXLED var LATC.3
    PanTXLED var LATD.0
    RX1LED var LATD.1
    
    
    pause 10
    
    Start:
    
        DigTXLED = 1
        PanTXLED = 1
        RX1LED  = 1
        pause 1000
    
        DigTXLED = 0
        PanTXLED = 0
        RX1LED  = 0
        pause 1000
    
    
    
        goto start
        
    
    END
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  • #11
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,264

    Default Re: 18F45K40 Can't set PORTD.1

    I can't help thinking it's an RMW issue even though you're clearly using LAT instead of PORT registers.

    What happens if you try to toggle ONLY RX1LED?
    What happens if you change the order in which the three outputs are being set/cleared?

  • #12
    Join Date
    May 2013
    Location
    australia
    Posts
    1,729

    Default Re: 18F45K40 Can't set PORTD.1

    better still
    latd = 7
    then
    latd=0

    i don't have 3.1 so if above idea does not work can you post lst file

    ps not a good idea to look at forum whille cooking dinner, can smell burning
    This is more entertaining than Free to Air TV

  • #13

    Default Re: 18F45K40 Can't set PORTD.1

    I had a similar problem a while back with a pic16f946. After going through the hardware, code etc. without result. I contacted Charles at Melabs as it turned out there was a problem with a definition file. He fixed it and the port pin became functional. Worth a try, Charles has always been very helpful.

  • #14
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default Re: 18F45K40 Can't set PORTD.1

    Ladies (if any) and gentleman, I finally found the issue but still not sure how it is mixed up. Anyway issue solved.


    Code:
    RD1PPS = 0   ' pin is LATxy
    It must be getting mixed in somewhere.
    Thanks to everyone.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  • #15
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,915

    Default Re: 18F45K40 Can't set PORTD.1

    What a nightmare this setup bits...

    Congrats Sayzer on your new mayor.

    Ioannis

  • #16
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,264

    Default Re: 18F45K40 Can't set PORTD.1

    Nice, I'm glad you figured it out.
    Strange thing is that, according to the datasheet, RD1PPS defaults to 0 so you shouldn't need to clear that. It would be interesting to HSEROUT[DEC RD1PPS] on POR and again just before you force it to 0 to see if it's in some unknown state. Does it not initialize to the correct state (according to the datasheet) or is there some other code, compiler or programmer generated, that's actually SETTING it to something at one point or another.

    /Henrik.

  • #17
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,236

    Default Re: 18F45K40 Can't set PORTD.1

    Quote Originally Posted by Ioannis View Post
    ...

    Congrats Sayzer on your new mayor.

    Ioannis
    Thank you Ioannis. I hope to see you in Istanbul one day. Unlimited true Turkish sish kebap from me.


    Quote Originally Posted by HenrikOlsson View Post
    Nice, I'm glad you figured it out.
    Strange thing is that, according to the datasheet, RD1PPS defaults to 0 so you shouldn't need to clear that. It would be interesting to HSEROUT[DEC RD1PPS] on POR and again just before you force it to 0 to see if it's in some unknown state. Does it not initialize to the correct state (according to the datasheet) or is there some other code, compiler or programmer generated, that's actually SETTING it to something at one point or another.

    /Henrik.
    I shipped the board out. Now I do not have a board with this chip now.
    And this chip is not included in my simulator program.
    As soon as I get the board back from the customer, I will check some other things.

    And as you said, RD1PPS should be 0 initially. It seems it is getting messed up in somewhere.

    Thank you for the response.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  • #18
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    2,915

    Default Re: 18F45K40 Can't set PORTD.1

    Hope too! I was there 15 years ago and was very impressed. Kebab it is then!

    When you get the board back, the test Henrik suggested would be very informative and interesting.

    Ioannis

  • Similar Threads

    1. init PORTD FOR 16F877A
      By coss_cat in forum General
      Replies: 3
      Last Post: - 19th June 2010, 17:16
    2. PortD mistery
      By vizualizer in forum mel PIC BASIC Pro
      Replies: 3
      Last Post: - 30th March 2009, 13:40
    3. PIC18F8720 PORTD problem
      By nverma in forum mel PIC BASIC Pro
      Replies: 28
      Last Post: - 16th May 2007, 05:30
    4. Problems with PORTD on 18F658
      By blainecf in forum mel PIC BASIC Pro
      Replies: 3
      Last Post: - 13th June 2006, 17:32
    5. 18F6680 and portd problems.
      By jkbh in forum mel PIC BASIC Pro
      Replies: 10
      Last Post: - 6th June 2005, 10:54

    Members who have read this thread : 15

    You do not have permission to view the list of names.

    Posting Permissions

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