Menu

Hsersend on 16F15376 = dead(?)

2021-02-28
2021-02-28
  • Roger Jönsson

    Roger Jönsson - 2021-02-28

    Hi,
    I can not get anything out of USART with Hsersend on PIC 16F15376 (Mplab Xpress card)
    I tested both USART 1, RC6 and USART 2, RB6
    Updating GCB with the latest full package download did not help.
    Am I doing something wrong or is there a compiler error?

    Here a very basic test program. Led blinks on RA0, but the RC6 stays low.

    ;Chip Settings
    #chip 16F15376,16
    
    #define USART_BAUD_RATE 115200 
    
    Dir PORTA.0 Out
    'Dir PORTC.6 Out
    
    Do
    
    HSerSend 0
    wait 100 ms
    PORTA.0 = OFF
    wait 100 ms
    
    HSerSend 1
    wait 100 ms
    PORTA.0 = ON
    wait 100 ms
    
    Loop
    
     

    Last edit: Roger Jönsson 2021-02-28
  • mmotte

    mmotte - 2021-02-28

    try HSerPrint which will convert the 1 and 0 to ascii and you can see it on the terminal.

     
  • Roger Jönsson

    Roger Jönsson - 2021-02-28

    No difference. RC6 still does not ouput anything. There are no bits at all sent. (I am measuring the RC6 pin directly to an oscilloscope and an amp+speaker is also connected which should produce a "tick" every 200ms).

     

    Last edit: Roger Jönsson 2021-02-28
  • Anobium

    Anobium - 2021-02-28

    I used the 16F15376 yesterday. Serial was working.

    Please install the latest release candidate.

     
  • Anobium

    Anobium - 2021-02-28

    I just looked at your code.... this is a pps chip!

    See the demos in .. \GreatCowBasic\Demos\vendor_boards\mplab_xpress_board_pic16f15376 folder - you need to look at demo 10_board_status_to_serial.gcb

     
  • Anobium

    Anobium - 2021-02-28

    I just looked at your code.... this is a pps chip!

    See the demos in .. \GreatCowBasic\Demos\vendor_boards\mplab_xpress_board_pic16f15376 folder - you need to look at demo 10_board_status_to_serial.gcb

     
  • William Roth

    William Roth - 2021-02-28

    The 16F15376 is a PPS enabled chip. While the TX1 Output defaults to PortC.6 per the datasheet I have found that the PPS must be set for proper operation on this family of chips.

    Try this code with the PPS set up.

    ;Chip Settings
    #chip 16F15376,16
    #OPTION EXPLICIT
    #STARTUP InitPPS, 85
    
    #define USART_BAUD_RATE 115200
    #define USART_TX_BLOCKING
    
    DIR PORTA.0 OUT  'LED?
    DIM COUNTER as BYTE
    COUNTER = 0
    
    Do
         HserPrint COUNTER
         HserSend 32         // Space
         HserPrint "Great Cow BASIC"
         HserPrintCRLF   
         PORTA.0 = NOT PORTA.0  // Toggle LED
         Wait 500 ms
         COUNTER++  // increment counter by 1
    Loop
    
    Sub InitPPS
          'Module: EUSART1
           RC6PPS = 0x000F    'TX1 > RC6
    End Sub
    
     

    Last edit: William Roth 2021-02-28
  • Roger Jönsson

    Roger Jönsson - 2021-02-28

    Thanks. That works.
    Why do I need to assign TX1 to a new pin? Why is it not by default RC6 as in the PIC16F15376 datasheet?

     
  • William Roth

    William Roth - 2021-02-28

    I have confirmed that the RC6PPS register defaults to a value of 0 (unmapped) on Power On Reset.

    Therefore TX1 is not mapped to RC6 unless it is setup via PPS. This seems to be the case with all PIC microcontrollers. The RX1 Defaults to RC7 as expected, however TX1 output does not.

    I think it should be standard good practice to always setup the PPS when using the USART on a PPS enabled PIC. GCB has a built in PPS tool to make this very easy.

     
  • William Roth

    William Roth - 2021-02-28

    Why do I need to assign TX1 to a new pin? Why is it not by default RC6 as in the PIC16F15376 datasheet?

    Because the Datasheet is wrong in this case.

     
  • Roger Jönsson

    Roger Jönsson - 2021-02-28

    Yes, I used the built in PPS tool (good thing to have hady!) while Anobium was editing the last message above and got it to work with the pin that was supposed to be default according to the data sheet.

    As RX1 was working, it was extra weird that TX1 wasn't. Pretty bad that the datasheet that I downloaded again today is still wrong (it isn't exactly a new chip).

    Anyway. I appreciate the help and is happy that I got it sorted out!

     
  • William Roth

    William Roth - 2021-02-28

    The Pin Allocation Tables for 16F153xx chips are incorrect in the datasheet where they show TX1/TX2 as allocated to RC6/RB6 respectively. No peripheral outputs are initially allocated on PPS chips at POR.

    However the Register 15-2 RxyPPS Table on Page 243 of the datasheet shows that ALL RxyPPS registers default to 0 at POR. This means that these are all initially set up as standard I/O pins and not mapped to any specific peripheral output.

    Rxy is defined where "x" is the Port and y is the Bit. eg. RC5 or PORTC.5

     

    Last edit: William Roth 2021-02-28

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.