Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[PIC] PIC16F627A Use TX Pin as GPIO

Status
Not open for further replies.

s-fr

Newbie
Newbie level 1
Joined
May 13, 2023
Messages
1
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
14
Hey Guys.

I need some help with a project I'm currently working on. Background to the project is, I have to develop a software for a hardware someone else has designed, I need to send chars via UART Communication to a PIC16F627A Microcontroller which should do something after receiving different chars. My problem is that the Guy who designed the hardware tied some transistor circuit onto the TX Pin of the Microcontroller (as you can see in the attachments) and as I use UART I'm not able to use the TX Pin as a commonly GPIO. I think this might be possible though I only have the RX Pin for my UART isn't it?

Please note that the schematic at the attachment is not the original schematic because I'm not allowed to post the original.


Here's my code for UART
C:
#include "UART.h"
#include "main.h"


void UART_Init(const uint32_t BaudRate, const uint8_t BRGH) {
    TRISB1 = 1; // RX Pin set as input
    TRISB2 = 0; // TX Pin set as output

    if (BRGH == 0) {
        SPBRG = _XTAL_FREQ/(64*BaudRate) - 1;
        TXSTAbits.BRGH = 0;
    } else {
        SPBRG = _XTAL_FREQ/(16*BaudRate) - 1;
        TXSTAbits.BRGH = 1;
    }
    
    SYNC  = 0;    // Asynchronous
    SPEN  = 1;    // Enable serial port pins

    TXEN  = 0;    // enable transmission
    CREN  = 1;    // enable reception

    TX9   = 0;    // 8-bit reception selected
    RX9   = 0;    // 8-bit reception mode selected
}


char UART_read_char() {

    if(OERR) { // check for Error
        CREN = 0; //If error -> Reset
        CREN = 1; //If error -> Reset
    }

    while(!RCIF);  // hold the program till RX buffer is free
    return RCREG; //receive the value and send it to main function
}



And here's my main.c

C:
void main(void) {
    pin_config();
    
    UART_Init(9600, 1);

    
    uint8_t UART_BUFFER;

    
    while(1) {
        UART_BUFFER = UART_read_char();
        
        if (UART_BUFFER == 'a') { // LED on
            LED_HANDLER(1);
        }
        
        else if (UART_BUFFER == 'b') { // LED off
            LED_HANDLER(0);
        }
        
        else if (UART_BUFFER == 'c') { // Fan on
            DO_FAN = 1; //TX Pin
        }
      
        else if (UART_BUFFER == 'd') { // Fan off
            DO_FAN = 0; //TX Pin
        }
        
        UART_BUFFER = '\0';
    }
}


The code by itself works pretty well, but as I said I'm not able to control the DO_FAN (wich is the TX Pin).


Hope someone can help.

Best regards
 

Attachments

  • schem1.png
    schem1.png
    49.1 KB · Views: 132

I'm a little confused about which processor is which.
Are you running this code on a 16F627A or are you transmitting it to a 16F627A or is this some other processor and it is receiving from a 16F627A?

If this is code for a 16F627A, if you comment out the line "TXEN = 0; // enable transmission" the pin should be released for general IO use but don't forget to set the TRISB bit to output mode first. The code that configures the pins appears to be in a different code module "pin_config()" which you have not shown us.

Brian.
 

Hi,

The schematic doesn't show much: a transistor connected to TxD / GPIO .... nothing wrong about this.
It's not clear about RxD, it's not clear what's your setup/wiring, it's not clear what's your concern.

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top