Menu

[FIXED] Hardware Serial Not Working on PIC Microcontrollers

2024-09-14
2024-09-24
  • William Roth

    William Roth - 2024-09-14

    Not getting any serial output on 18F46K42, 18F47Q43, etc. Seems to be an issue with usart.h. I swapped out the current usart.h with an older version ( Dec 2022) and it works OK.

    Attached is my ASM and GCB Code.

    2024.08.18 (Windows 64 bit) : Build 1411

     
  • Anobium

    Anobium - 2024-09-15

    Looks OK in build 1417+

    I did update USART.H to support AVRDx and I had to revert an error I made in initialisation of PIC.

    Try the attached this is the same as the current release in SourceForge/SVN.

    Good of you to spot this!

     
  • William Roth

    William Roth - 2024-09-15

    This seemed to have resolved the problem. The USARTs now initialize and the ASM looks good.

    Thanks

     
    • Anobium

      Anobium - 2024-09-15

      A silly mistake by me. It was easy to spot after I made the error.

      Tha

       
  • Angel Mier

    Angel Mier - 2024-09-16

    By the way, I think I spotted a small bug on usart.h, on several pic’s the BRG16 bit is not set, this is caused by a #ifndef that points to TXEN1 bit, this bit is not present on some chips but a #samebit in the library define it, causing the code flow by other path and set wrong configs, resulting on an incorrect baud rate at any speed.

    At least I found the problem on 18F14K50 and 18F4550, other parts may be affected.

    Can other devs more experienced in the library assert if my approach to the solution is viable?
    It works for me, but I don’t want to make troubles for other people 😊

    Angel

     

    Last edit: Angel Mier 2024-09-16
    • Anobium

      Anobium - 2024-09-16

      Download and loaded into the Gold build.

       
  • Fabrice Engel

    Fabrice Engel - 2024-09-18

    Had another issue with wrong data transmission. Evan fixed the issue today in usart.h and provided new one. Now it is working fine for me. The new corrected file is available in the repository;
    https://sourceforge.net/p/gcbasic/code/HEAD/tree/GCBASIC/trunk/include/lowlevel/usart.h?format=raw
    Many thank for quick help

     

    Last edit: Fabrice Engel 2024-09-18
  • Angel Mier

    Angel Mier - 2024-09-20

    I have a good one and a bad one; let me start by the good one: as I’m writing a library for the LIN Bus using the auto-baud rate synchronization feature available in the Enhanced USART, I needed a way to use the USART_BLOCKING but while being able to define a certain time out (as the frame window is known), so it can wait for bytes at slightly different times and don’t hang out the program in case one device doesn’t respond.

    I added the capability to the usart.h by only adding USART_BLOCKING_TIMEOUT 125 (where 125 is the time in ms) when using USART_BLOCKING; the code is only added when the new define is present (Code that doesn’t use it will end with the same code as previous library). The objective is to have a very responsive until loop by just timing the loop instructions without using timed waits; this sacrifices timing precision but gets excellent communication performance. (Currently only for pics, but can be added also to AVR, it is just needed to measure the instructions time and test, but I don’t have some AVR’s to do it)
    Attached library.

    Now the bad one: I found 3 more chips that doesn’t work correctly even with the latest corrections:
    18F47Q10 – Chip transmits but doesn’t receive, RX flags or interrupts doesn’t get set.
    16F15276 – Chip transmits but doesn’t receive, RX flags or interrupts doesn’t get set.
    16F15245 – Nothing, doesn’t transmit and doesn’t receive.

    All chips need to set the TX pin thru pps.
    Attached example code with asm.

    Angel

     

    Last edit: Angel Mier 2024-09-20
  • Anobium

    Anobium - 2024-09-20

    Nice new addition!!!


    Your assessment is correct. Again this is because we removed a lot of duplicate code, however, in the case of the 16F a register.bit set was not being set.


    I have updated USART.H and committed to SVN. I also updated the Help to add the new capability.

     
  • Anobium

    Anobium - 2024-09-20

    I tested using your zip and I posted all these to GitHub.

    I did not test receive and send back when I verified chips, I will in the future.

    If Microchip ever release another PIC :-)

     
  • Fabrice Engel

    Fabrice Engel - 2024-09-21

    I just get latest GCBASIC version, with a PIC161825, usart is (still) working. Terminal get the right information. I am using only TX to send debug values on screen. Cannot tell anything about RX by PIC as far I not use it. Thank a lot

     
    👍
    2

Log in to post a comment.