Menu

Hardware serial question

viscomjim
2015-01-01
2015-04-11
  • viscomjim

    viscomjim - 2015-01-01

    This was posted in wrong area and has been moved to the help area... sorry.

    Hi, I am working with a pic12f1840. I am trying to simply send a text string out of the tx line to a terminal program (teraterm). According to the data sheet, eusart uses pin 7 (RA0) for TX and pin 6 (RA1) for RX. However, it also shows pin 3 (RA4) for TX and pin 2 (RA5) for RX. In the attached code I tried both TX lines to test transmitting some data. I know my set up for teraterm and my ttl serial to usb is working fine as I use it all the time for other serial projects. I am not getting any data out that I can tell. I am using a known good pic and have programmed it successfully to flash an led. I used the help files to get the commands I am using to send data without success. Can anyone tell me what I am doing wrong.

    Also a quick note that the data sheet (referring to the 2 rx and tx pins) says "pin function is selectable via the APFCON register". Is this somehow handled by GCBasic, or is it something I need to configure somehow?

    CHIP 12F1840, 32

    DEFINE USART_BAUD_RATE 9600

    DEFINE SEROUTPORT PORTA.4 'PIN 3 TX

    DIR SEROUTPORT OUT

    DO
    HSERPRINT "THIS IS A TEST"
    WAIT 100 MS
    HSERPRINTCRLF
    WAIT 100 MS
    LOOP

    Thanks for any and all help!!!!

     

    Last edit: viscomjim 2015-01-07
  • tony_g

    tony_g - 2015-04-11

    hi viscomjim,

    i have used the apfcon settings for changing the uart to alternate pins as well as shifting the pwm steering to different pins.

    this is what i had at the start of my program that let me send data out the uart also on a 12f1840

    'set uart TX/RX pins to RA4 and RA5 alternate pin locations:
     set APFCON.7 = 1
     set APFCON.2 = 1
    
     'Set the pin directions:
     Dir PORTA.4 Out  'send on Pin 3
     Dir PORTA.5 In   'receive on Pin 2
    
     'Config Hardware-UART:
     #define USART_BLOCKING
     #define USART_BAUD_RATE 9600
    

    this allowed me to use the uart on its alternate location with success,

    not sure if you did get this working for you in the end so i thought i would share what worked for me.

     

Log in to post a comment.