USART not working on 16F1783

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

USART not working on 16F1783

Mitch-98
I am using a 16F1783 with XC8 trying to get the USART tx/rx to work,
but it is not outputting ANYTHING at ALL!


////////////////////////
void startup(void) {
    TRISB   = 0b00111111;   //All PORTB = input except USART
    ANSELB  = 0b00111111;   //RB0:5 = analog input
    OSCCON  = 0b01110110;   //8MHz
    INTCON  = 0b00000000;   //Disable all interrupts
    OPTION_REG=0b10000000;
    PORTB   = 0b00000000;
}

void init_usart(void) {
    BRGH = 1;
    BRG16 = 0;
    SPBRG = 51; //9600 baud for 8MHz with BRGH = 1
    TXEN = 1;
    SYNC = 0;
    SPEN = 1;
}

void putch(unsigned char byte) {
    while(!TXIF) { continue; }
    TXREG = byte;
}

void main(void) {
    startup();
    init_usart();

    while(1) {
        putch('X'); __delay_ms(500);
        //PULSE AN LED
        //An LED pulses every 500ms so I know it's not getting stuck
in the putch() code
    }

}
////////////////////////

I put a scope on the TX pin (RB6) but nothing changes, it's just stuck
low the whole time.
I also cannot receive on the RX (RB7)
I wrote a software USART that works using the same pin, so I know the
pin isn't broken or something. I also tried multiple chips, same
result.

I'm sure there's just a register that I'm forgetting.

PLEASE HELP!
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
ivp
Reply | Threaded
Open this post in threaded view
|

Re: USART not working on 16F1783

ivp
> but it is not outputting ANYTHING at ALL!

Mitch, are you checking the right pins ?

APFCON: ALTERNATE PIN FUNCTION CONTROL REGISTER

bit 2 TXSEL: TX Pin Selection bit

1 = TX is on pin RB6
0 = TX is on pin RC6

bit 1 RXSEL: RX Pin Selection bit

1 = RX is on pin RB7
0 = RX is on pin RC7

Joe
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: USART not working on 16F1783

Mitch-98
That was totally it. I needed to set TXSEL and RXSEL. Thanks Joe!

On Sun, Sep 30, 2012 at 6:46 PM, IVP <[hidden email]> wrote:

>> but it is not outputting ANYTHING at ALL!
>
> Mitch, are you checking the right pins ?
>
> APFCON: ALTERNATE PIN FUNCTION CONTROL REGISTER
>
> bit 2 TXSEL: TX Pin Selection bit
>
> 1 = TX is on pin RB6
> 0 = TX is on pin RC6
>
> bit 1 RXSEL: RX Pin Selection bit
>
> 1 = RX is on pin RB7
> 0 = RX is on pin RC7
>
> Joe
> --
> http://www.piclist.com PIC/SX FAQ & list archive
> View/change your membership options at
> http://mailman.mit.edu/mailman/listinfo/piclist
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
ivp
Reply | Threaded
Open this post in threaded view
|

Re: USART not working on 16F1783

ivp
> That was totally it. I needed to set TXSEL and RXSEL. Thanks Joe!

You're welcome. Piss you off wouldn't it

Joe
--
http://www.piclist.com PIC/SX FAQ & list archive
View/change your membership options at
http://mailman.mit.edu/mailman/listinfo/piclist
Reply | Threaded
Open this post in threaded view
|

Re: USART not working on 16F1783

Well wisher
This post has NOT been accepted by the mailing list yet.
In reply to this post by Mitch-98
I am not familiar with PIC16F1783,but I think that your program error is checking TXIF flag before putting data into TXREG register.



void putchar(char DATA)
{
TXREG=DATA;       //putting data to TXREG
while(TXIF==0);      //waiting for transmission to complete.(TXIF=1)

}


just check it.It may help you.
Reply | Threaded
Open this post in threaded view
|

Re: USART not working on 16F1783

rparthiban69
This post has NOT been accepted by the mailing list yet.
In reply to this post by ivp
I Have doubt in PIC 16f1527 UART1 selection?

TX1STA bits and Baudxcon bits configuration bit doubt?

I need sample program..