18F87J50 I/O problems
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Oct 2005

    Default 18F87J50 I/O problems

    After spending two fruitless nights on this I ask for help.
    After weeks of developing code on a PIC Clicker 2 with 18F87J50 I received the actual hardware on which the code is supposed to run on (which is using the same device (PIC18F87J50 running at the same speed (although derived from a different x-tal frequency) and I'm sort of dead in the water.

    On the board there's an RTC (an MCP79510 from Microchip). Reading/writing this works perfectly (using MSSP1 module) on the PIC Clicker but not at all on the actual hardware using the same code and same pins (except for #CS) so tonight I resorted to using SHIFOUT/SHIFTIN but that doesn't work either.

    Using a logic analyzer I can see the correct commands being sent and the RTC chip responding with data but the PIC just reads all zeros as if the input buffer was dead or the pin disconnected (but it's not because I can read its state, high/low without problems). The logic analyzer probes are attached right on the PIC legs.

    Here's my basic testcode:
        CONFIG  WDTEN = ON            ; WDT enabled
        CONFIG  PLLDIV = 5            ; Divide by 5 (20 MHz oscillator input)
        CONFIG  STVREN = ON           ; Reset on stack overflow/underflow enabled
        CONFIG  XINST = OFF           ; Instruction set extension and Indexed Addressing mode disabled (Legacy mode)
        CONFIG  DEBUG = OFF           ; Background debugger disabled; RB6 and RB7 configured as general purpose I/O pins
        CONFIG  CPUDIV = OSC1         ; No CPU system clock divide
        CONFIG  CP0 = OFF             ; Program memory is not code-protected
        CONFIG  FOSC = HSPLL          ; HS oscillator, PLL enabled, HSPLL used by USB
        CONFIG  FCMEN = OFF           ; Fail-Safe Clock Monitor disabled
        CONFIG  IESO = OFF            ; Two-Speed Start-up disabled
        CONFIG  WDTPS = 512           ; 1:512
        CONFIG  EASHFT = ON           ; Address shifting enabled, address on external bus is offset to start at 000000h
        CONFIG  MODE = MM             ; Microcontroller mode - External bus disabled
        CONFIG  BW = 16               ; 16-bit external bus mode
        CONFIG  WAIT = OFF            ; Wait states on the external bus are disabled
        CONFIG  CCP2MX = DEFAULT      ; ECCP2/P2A is multiplexed with RC1
        CONFIG  ECCPMX = DEFAULT      ; ECCP1 outputs (P1B/P1C) are multiplexed with RE6 and RE5; ECCP3 outputs (P3B/P3C) are multiplexed with RE4 and RE3
        CONFIG  PMPMX = DEFAULT       ; PMP pins placed on EMB
        CONFIG  MSSPMSK = MSK7        ; 7-Bit Address Masking mode enable
    DEFINE DEBUG_REG PORTH              ' Set Debug pin port 
    DEFINE DEBUG_BIT 1                  ' Set Debug pin bit 
    DEFINE DEBUG_BAUD 38400             ' Set Debug baud rate 
    DEFINE DEBUG_MODE 0                 ' Set Debug mode: 0 = true, 1 = inverted
    Temp VAR BYTE    
    OSCTUNE.6 = 1                       ' PPLEN
    WDTCON.4 = 1                        ' Select alternate SFR
    ADCON0 = 255                        ' Access ANCON thru ADCON SFR
    ADCON1 = 255
    WDTCON.4 = 0                        ' Back to standard SFT
    TRISE.0 = 1                         ' On board button no. 1
    TRISE.1 = 1                         ' On board button no. 2
    TRISC.5 = 0                         ' Data output
    TRISC.4 = 1                         ' Data input
    TRISC.3 = 0                         ' Clock output
    TRISD.3 = 0                         ' #CS-pin
    PAUSE 100
    DEBUG "Start", 13
    IF PortE.0 = 0 THEN                                 ' Button no. 1 pressed
        Temp = 255                                      ' Init variable
        LATD.3 = 0                                      ' Drive #CS low
        SHIFTOUT PortC.5, PortC.3, 1, [$13, $04]        ' Send command for reading RTC Weekday register
        SHIFTIN PortC.4, PortC.3, 0, [Temp]             ' Clock in response 
        LATD.3 = 1                                      ' Drive #CS high
        DEBUG "Data read: ", DEC Temp, 13               ' Show response
        WHILE PortE.0 = 0 : WEND                        ' Wait for button to be released
    IF PortE.1 = 0 THEN                                 ' Button no. 2 pressed
        DEBUG "State of RC4: ", BIN PortC.4, 13         ' Read state of RC4 and output
        WHILE PortE.1 = 0 : WEND                        ' Wait for button to be released
    Goto Main

    Here's a screenshot of the logic analyzer capturing one of the SPI transactions:

    As you can see the RTC responds with the value $19 (which is a completely sensible value at this point) but the PIC reads all zeros, yet it reads and report the logic state of RC4 just fine:

    Debug out.PNG

    Can anyone PLEASE tell me what the hell is going on here? It's most likely something stupid on my behalf but I just can't figure it out and I need to get past this.
    Why doesn't SHIFTIN (or the MSSP module for that matter) read the pin properly when the pins state is readable just fine "manually"?

    Thank you in advance!


  2. #2

    Default Re: 18F87J50 I/O problems

    Are you sure you are using the correct mode?

  3. #3
    Join Date
    Oct 2005

    Default Re: 18F87J50 I/O problems

    For the original code using the MSSP module, yes because it works on the development hardware. For the SHIFTOUT/SHIFTIN no, but if you look at the logic analyzer trace you'll see that part of the MISO signal is high for the duration of two complete clock cycles so even if I had the wrong mode it should've read "something".

    But I woke up this morning thinking how I've just looked at the logic analyzer trace without thinking about logic level thresholds or anything. Put the scope probe on the MISO signal and the "high level" was just under 2V (on a 3.3V system). This was apparently enough for the logic analyzer (genuine Saleae) to be interpreted as a '1' but not for the PIC. Turns out that the RN42 module which sits on the same SPI bus is, for whatever reason, loading down the bus. Cut the PCB trace and the signal level went to 3.3.V.

    There are other devices on the SPI bus but the RN42 is not present on the development board so once I realised I hadn't actually looked at the actual voltage levels the RN42 was my first "target". Seems I was right.

    Now back to where I left of on this tangent. Damn, at least 8 hours spent on this, I feel good and embarressed at the same time.


  4. #4

    Default Re: 18F87J50 I/O problems

    Nice save, I'd never of thought of that, the assumptions we make. Can I suggest that was 8 hours wisley used. you'll never get caught like that again.

  5. #5

    Default Re: 18F87J50 I/O problems

    what is the RN42 module, resistor network?

  6. #6
    Join Date
    Oct 2005

    Default Re: 18F87J50 I/O problems

    It's a Bluetooth module.

Similar Threads

  1. 18F87J50 as a webserver
    By Christopher4187 in forum Ethernet
    Replies: 9
    Last Post: - 12th February 2014, 20:21
  2. Using EEPROM on 18F87J50
    By Christopher4187 in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 2nd June 2013, 19:57
  3. Frustrated with 18F87J50
    By Christopher4187 in forum General
    Replies: 7
    Last Post: - 31st March 2013, 21:21
  4. Two questions - 18F87J50
    By Christopher4187 in forum General
    Replies: 3
    Last Post: - 25th March 2013, 15:11
  5. 18F87J50 Success
    By GeoJoe in forum General
    Replies: 0
    Last Post: - 28th October 2007, 01:52

Members who have read this thread : 24

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