# PIC16F1718 UART not working

I am currently trying to port the functionality of one of my projects from an Arduino to a PIC µC. To begin I wanted to establish a UART communication to my computer but I cannot get it to work. I tried with an TTL to USB converter and now with a logic analyzer to see if anything happens on the wire but there is nothing. I read in the datasheet the tx pin should be RC6 and I set all registers mentioned in the datasheet or in many tutorials and tried to understand them but I seem to forget something. Has anyone of you an idea?

main.c

#define _XTAL_FREQ 16000000
#include <stdio.h>
#include <stdlib.h>
#include <xc.h>

#include "uart.h"

int main(void)
{

OSCCON = 0x7B;
UART_Init(9600);

while(1){
UART_Write('c');
UART_Write('w');

}
}


uart.h

char UART_Init(const long int baudrate)
{
unsigned int x;
x = _XTAL_FREQ/(64*baudrate)-1;
if(x>255){
x = _XTAL_FREQ/(16*baudrate)-1;
TX1STAbits.BRGH = 1;
}
if(x<256){
TX1STAbits.TXEN = 1;
TX1STAbits.SYNC = 0;
RC1STAbits.SPEN = 1;
SP1BRG = x;

return 1;
}
return 0;
}

void UART_Write(char data)
{
while(!TX1STAbits.TRMT);
TX1REG = data;
}

• You might need pull-up or pull-down resistors on the UART line. Did you try analysing the ports with a scope? – Rick van Schijndel Sep 24 '17 at 21:29
• I don't think that a standard UART connection needs any pull-up or pull-down resistors to operate. I observed the pin with my logic analyzer (like a cheap oscilloscope to keep track of the logic levels) and nothing happened. – moessi774 Sep 24 '17 at 21:36
• Are you familiar with the configuration bits on PICs? If not, read about them (google "PIC configuration bits"). And find the configuration bits registers in the datasheet. Each PIC had it's own unique settings. In your case, it's most likely the watchdog timer is resetting the processor before it can send any data. – Dan Laks Sep 24 '17 at 21:44
• PICs do not need pull-up or down resistors on the UART lines. – Dan Laks Sep 24 '17 at 21:45
• The configuration bits transcend any one specific peripheral, so it would be tedious to describe how every individual configuration setting affects each peripheral in the datasheet. It's just part of the learning curve of using PICs. Every PIC uses them and you just get used to adding the code at the top of every new program. MPLAB provides an easy way to generate the necessary code. – Dan Laks Sep 24 '17 at 22:09