Menu

PIC16F17145 not receiving on hardware Usart

mmotte
2024-07-29
2024-07-30
  • mmotte

    mmotte - 2024-07-29

    This is a back burner project. I have a limited supply of 18F26K80 ( need 12 bit analog and dual usart). So I thought I would try a newer chip and selected 16F17145.

    When I first got them I was also trying to get the timer1 external clock osc xtal to work and i noticed the uart Xmit works just fine but the receive would not receive my commands. The program was working fine on the 18F26K80.

    I did some troubleshooting and modified the usart.h file ( usart.h has certained gained a lot of weight since I last worked on it). Usart still does not receive. xmits fine.
    I think it has to do with naming RC1REG or RCREG1.
    I continued to mess with things and changed the 16F17145.dat file .

    Also the pps doesn't have RC1 in nor Rx and it has to be modified outside of pps program.

    Yes I have dug myself a hole and am floudering in it.

    There are other problems but let's figure out first the serial usart. the clock xtal mostly don't work some times it runs. Don't worry I have resigned my self to external DS3231.

     
  • mmotte

    mmotte - 2024-07-29

    I guess it don't do 2 files?

     
  • Anobium

    Anobium - 2024-07-29

    Are there any demos for this specific chipfamily? i cannot tell as i am on my fone.

    If no demos then cut the code down to absolute minimum and then examine the ASM. Repost simple program.

    Advice. Do not change DAT. Changing DAT has huge implications beyond GCBASIC.

    Evan

     
  • mmotte

    mmotte - 2024-07-30

    I see no demos for serial com except in the help. Search nothing of this family.

    Partly solved.

    First the pps program does not have RX1 and RX2. It does have RX but RXpps does not exist.
    default is RX1 on RB5 so did leave the bad line out and that worked.
    additionally I tried just adding the 1 to RX1PPS and that worked too.

    Second , after reading the pdf for PIC16F17xxx it needs some bits set .

    CREN = 1
    SYNC =0
    SPEN =1
    

    This is the test program

    #chip 16F17145, 8
    #option explicit
    
        // PIC PPS Tool version: 0.0.6.5
    
        #startup InitPPS, 85
        #define PPSToolPart 16F17145
    
            // PIC PPS Tool version: 0.0.6.5
    
    Sub InitPPS
        UNLOCKPPS
    
                // Module: Error
                RB6PPS = 0x0013    // TX1 > RB6
                // Module: EUSART
                RX1PPS = 0x000D    // RB5 > RX
    
        LOCKPPS
        End Sub
        // Add this code segment to your GCBASIC source program
    
    
    
    Dim enter as string
    enter = 13, 10          '' create a string to concantenate for CRLF
    'InitUSART
    'USB stick serial comm
    #define USART_BAUD_RATE 9600
    #define USART_DELAY off
    #define USART_TX_BLOCKING
    '#define USART_BLOCKINGj
    'Serial to PC terminal
    
      'Set pin directions
    'USB stick adapter Serial Port
    Dir PORTb.5 in   'USART 1 Rx Pin
    Dir PORTb.6 out   'USART 1 Tx Pin
    Dim comport, inchar as Byte
    
    CREN = 1
    SYNC =0
    SPEN =1
    
    Begin:
    
        If USARTHasData Then
          HSerReceive(InChar)
    
    
            HSerSend HEX(InChar)    'send back char to UART
    
        End if
        wait 50 ms
    Goto begin
    

    So tomorrow, I will try the second usart. Only took months and 2 more hours.

    Problem solved but still needs to be fixed.

    Thanks Evan
    BR
    Mike

     
  • Anobium

    Anobium - 2024-07-30

    Let me resolve the issue in the usart.h before trying USART2. USART2 will not work. So, please wait.

    I know why this is happening. And, it is a silly testing error. The 16F17126 is a chip of this family. However, I have only tested sending data and I have failed to test incoming data.

    The fix will be relatively simply but I need make the change and test.


    The test program we should use should look like your program. This is a clean program using minimal ram. There are two parts to do the same thing ( receive and send byte ). This is required as these use two different methods and both need to be tested.

    When this works without the user program corrections ( your bits! ) then we would change from USART1 to USART2.

    #chip 16F17145, 8
    #option explicit
    
            #startup InitPPS, 85
            #define PPSToolPart 16F17145
            // PPS is specific to this chip
            Sub InitPPS
                UNLOCKPPS
    
                        // Module: Error
                        RB6PPS = 0x0013    // TX1 > RB6
                        // Module: EUSART
                        RX1PPS = 0x000D    // RB5 > RX
    
                LOCKPPS
                End Sub
    
        #define USART_BAUD_RATE 9600
        #define USART_DELAY OFF
        #define USART_BLOCKING
    
    
    // Main program to receive and sent serial bytes 
    
        Do
    
            If USARTHasData Then
                // Using USARTHasData will ensure there is incoming data within the serial incoming buffer
    
                // Send back char to USART
                HSerSend ( (HSerReceive ) )    
    
                // Send back char to USART ensuring that USART1 is selected
                // HSerSend ( (HSerReceive, 1 ), 1 )    
    
            End if
            wait 50 ms
    
        Loop
    

    You can add the following to make this work for you.

    // CREN = 1
    // SYNC =0
    // SPEN =1
    

    I will use this testing approach for all chips in the future.

    Look for a library update soon. :-)

    Evan

     
  • Anobium

    Anobium - 2024-07-30

    You can try this. Remove the additional bits from user program.

    Revert USART.H and then add the following at line 161. ( The USART.H I am using is dated 13/02/2024 on line 100 ).

    #samebit TXEN, TXEN1
    #samebit CREN, CREN1
    #samebit SPEN, SPEN1
    #samebit SYNC, SYNC1, SYNC_TX1STA
    

    All this does is normalise this chip to ensure the naming in the D AT file is consistent with the library.

     

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.