Menu

PIC18F26k22 hex file not sent

2015-10-23
2015-10-30
  • Daniel Lockhead

    Daniel Lockhead - 2015-10-23

    Hi,
    I have a PIC18F26K22 connected to RS485 transceiver. I have modified bootloader for control my RS485 device (place transceiver in receive or transmit mode)

    Check device work fine. When i try to write hex file to the flash, nothing is send from tiny bootloader PC application to my PIC device (i have oscilloscope on PIC receive signal).

    The messages is:

    Check Device...
    Open COM1 serial port at 19200bd
    Device answer: 0x66 0x43='C'
    byte OK, now check ID-code and Family...
    idCode = $66
    family = C
    description = 18F w/64KB flash & 1024B EEPROM
    flash mem = 65536 bytes
    EEPROM mem = 1024 bytes
    Bootloader size = 200 bytes
    Transfert block size = 64 bytes
    Found: 18F w/64KB flash & 1024B EEPROM
    Open HEX file: C:\PIC_18F26k22\Pic_example.hex
    extended address: 0x0000
    :060000003AEF58F0120077
    0x0000: 3A EF 58 F0 12 00
    :020006001200E6
    0x0006: 12 00
    :0800080007EF00F01200DACF4F
    0x0008: 07 EF 00 F0 12 00 DA CF
    :10001000E4FFE2CFDAFFE9CFE4FFEACFE4FFF6CF77
    0x0010: E4 FF E2 CF DA FF E9 CF E4 FF EA CF E4 FF F6 CF
    :10002000E4FFF7CFE4FFF5CFE4FFF3CFE4FFF4CF35
    0x0020: E4 FF F7 CF E4 FF F5 CF E4 FF F3 CF E4 FF F4 CF
    ERROR: problem in writing flash memory!!!
    Close COM1 serial port

    I probaly do something wrong but i can't figure what.

    Why the hex file is not send to my PIC device?

    Thanks

     
  • Dan

    Dan - 2015-10-23

    Hi,Daniel

    Did you make the operation check in RS232C?

    I support if you do not operate in RS232C.

    Changes to the RS485 should be done step by step after confirming the operation in the RS232.

    You can self-resolved If you have an oscilloscope.

    Best regards
    Dan

     
  • Daniel Lockhead

    Daniel Lockhead - 2015-10-24

    Hi,
    After investigation, i don't believe of the error is on the bootloader code. Using Pickit 3 as debugger, i was able to find of the hex file is not received because the byte count sent = 0 a the place of 64.

    I think of i have something wrong with the hex file i want to sent. After searching, i was able to discover of i need to export the hex file in hex32 format for having in a format compatible with
    the bootloader (MPLAB IDE V8.92).

    Now, when i check hex file i receive this message:

    Check Device...
    Open COM1 serial port at 19200bd
    Device answer: 0x66 0x43='C'
    byte OK, now check ID-code and Family...
    idCode = $66
    family = C
    description = 18F w/64KB flash & 1024B EEPROM
    flash mem = 65536 bytes
    EEPROM mem = 1024 bytes
    Bootloader size = 200 bytes
    Transfert block size = 64 bytes
    Found: 18F w/64KB flash & 1024B EEPROM
    Open HEX file: C:\VBProject\PICtest\pictest32b.hex
    Error: Hex file for PIC16F, PIC family mismatch.
    Close COM1 serial port

    I not able to resolve the error of PIC Family mismatch. How i could generate hex file in 18F format from MPLAB IDE?

    Why the tiny bootoader sent a transfer block size = 0 ?

    Thanks
    Best regards
    Daniel

     
  • Daniel Lockhead

    Daniel Lockhead - 2015-10-27

    Hi Dan,

    I was able to figure of because 485 is half duplex, the RXREG need to be cleared when i switch from transmit to receive data.

    Now, I'm able to transfer my program, but my small program do not start.

    I know of i need to add a GOTO at the beginning of my code, but i not sure where and how to do that in C.
    Have you example somewhere?

    My test code is below: (Flashing led)

    void main(void)
    {

    goto Start;

    Start:
    ANSELC = 0x00;
    LATC = 0x00;
    TRISC = 0x00;

    while (1) {
    for (ic = 0; ic <= 0x0256; ic++){
    }
    mLED_1_Toggle()
    }
    mLED_1_On();
    mLED_1_Off();
    mLED_1_On();

    }

    I'm close to complete, but i need help.

    Thanks
    Daniel

     
  • Dan

    Dan - 2015-10-27

    Hi,Daniel

    insertion of "goto" is performed at the time of link.

    To write "goto" in the C program does not make sense.

    In the part of the C language it is also intended to automatically insert the "goto".
    It is part of the C language and can be embedded to the specifying the #pragma "goto".

    Please check the assembler code that is output after the link.

    http://tinypicbootload.sourceforge.net/tested_compilers_pic.html

    Someone had asked the same thing before.

    Please check all of the articles of Discusson. There may be the answer to your ask.

    Best regards,
    Dan

     

    Last edit: Dan 2015-10-31
  • Daniel Lockhead

    Daniel Lockhead - 2015-10-28

    Hi Dan,

    The compiler i use is mplabc18\v3.47 and should work without modification.

    I able to download my program with success, but when i restart the PIC, nothing run.

    I have set a led to turn ON when i on the bootloader and start to flash when i on my regular program, launched by bootloader.

    The booloader led turn ON when i write the device, but do not turn ON when i restart the device.

    The bootloader message is:
    Check Device...
    Open COM1 serial port at 19200bd
    Device answer: 0x66 0x43='C'
    byte OK, now check ID-code and Family...
    idCode = $66
    family = C
    description = 18F w/64KB flash & 1024B EEPROM
    flash mem = 65536 bytes
    EEPROM mem = 1024 bytes
    Bootloader size = 200 bytes
    Transfert block size = 64 bytes
    Found: 18F w/64KB flash & 1024B EEPROM
    Open HEX file: C:\VBProject\PICtest\pictest.hex
    minMemPos=00000000, maxMemPos=0000FF40, blockSize=64
    first 4 words at address 0xFF38:
    0xEFF5
    0xF000
    0x0012
    0x0001
    Transferring flash...
    Transferring program memory...
    write mem pos: 0x00000000(byte)
    send: TBLPTRU=0x00, TBLPTRH=0x00, TBLPTRL=0x00, block=64
    A0 EF 7F F0 12 00 01 00 08 02 00 00 6A 00 00 00 09 00 00 00 00 03 06 09 0C 01 04 07 0A 0D 02 05 08 0B 0E 01 02 04 01 02 04 01 04 03 05 07 06 03 01 02 04 01 02 04 03 05 01 02 04 07 06 DC 00 18
    CRC OK (0x80)

    After loading my test program, if a readback the device with my pickit3, i have now:

    Line Address Opcode Disassembly
    1 0000 EFA0 GOTO 0xff40
    2 0002 F07F NOP
    3 0004 0012 RETURN 0
    4 0006 0001
    5 0008 0208 MULWF 0x8, ACCESS
    6 000A 0000 NOP
    7 000C 006A

    32669 FF38 EFF5 GOTO 0x1ea
    32670 FF3A F000 NOP
    32671 FF3C 0012 RETURN 0
    32672 FF3E 0001
    32673 FF40 0E40 MOVLW 0x40
    32674 FF42 6E89 MOVWF 0xf89, ACCESS
    32675 FF44 D843 RCALL 0xffcc
    32676 FF46 0E43 MOVLW 0x43
    32677 FF48 6E45 MOVWF 0x45, ACCESS
    32678 FF4A 0E40 MOVLW 0x40

    Each program work fine when tested one by one but not work together.

    Any clue for me?

    Daniel

     
  • Daniel Lockhead

    Daniel Lockhead - 2015-10-28

    Dan,

    After make compare program memory before and after i have loaded my device, i found of a section of bootloader code is absent (see below) when my test program is loaded.

    32644 FF06 0000 NOP
    32645 FF08 0000 NOP
    32646 FF0A 0000 NOP
    32647 FF0C 0000 NOP
    32648 FF0E 8CD3 BSF 0xfd3, 0x6, ACCESS
    32649 FF10 010F MOVLB 0xf
    32650 FF12 6B38 CLRF 0x38, BANKED
    32651 FF14 6B3A CLRF 0x3a, BANKED
    32652 FF16 6B3B CLRF 0x3b, BANKED
    32653 FF18 0100 MOVLB 0
    32654 FF1A 0E24 MOVLW 0x24
    32655 FF1C 6EAC MOVWF 0xfac, ACCESS
    32656 FF1E 0E33 MOVLW 0x33
    32657 FF20 6EAF MOVWF 0xfaf, ACCESS
    32658 FF22 0E90 MOVLW 0x90
    32659 FF24 6EAB MOVWF 0xfab, ACCESS
    32660 FF26 6A80 CLRF 0xf80, ACCESS
    32661 FF28 0E3F MOVLW 0x3f
    32662 FF2A 6E92 MOVWF 0xf92, ACCESS
    32663 FF2C 6A82 CLRF 0xf82, ACCESS
    32664 FF2E 0EF8 MOVLW 0xf8
    32665 FF30 6E94 MOVWF 0xf94, ACCESS
    32666 FF32 0E01 MOVLW 0x1
    32667 FF34 6E48 MOVWF 0x48, ACCESS
    32668 FF36 D84F RCALL 0xffd6
    32669 FF38 08C1 SUBLW 0xc1
    32670 FF3A E15C BNZ 0xfff4
    32671 FF3C 0E66 MOVLW 0x66
    32672 FF3E 6E45 MOVWF 0x45, ACCESS

    Now , i need to figure why. Due to RS485 device i'm using, i have changed the size of bootloader
    fro 200 to 244. Could be the problem?

    Thanks

     
  • Dan

    Dan - 2015-10-29

    Hi,Daniel

    If the user program can write successfully,
    It is recommended that you test a simple program such as the first LED flashing.

    Bootloader should be located across the border of the "Erase Page".
    PIC18F26K22's "Erase Page" is "32Words" So 244 is not allowed.
    200 of the next 264

    (32x2)x3+4x2=200 (bytes)
    (32x2)x4+4x2=264 (bytes)

    Best regards,
    Dan

     

    Last edit: Dan 2015-10-29
  • Daniel Lockhead

    Daniel Lockhead - 2015-10-30

    Hi, Dan

    I have changed for #define first_address max_flash-264

    Now, i expect to have to change the piccodes.ini default value for set the new value:

    I have modified the default setup for this one:

    $66, C, 18F w/64KB flash & 1024B EEPROM, $10000, $400, 264, default,

    Look that's working but i would like to have confirmation from you for be sure i will not get
    in trouble later.

    Thanks very much
    Daniel

     

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.