• AVR Freaks

Hot!PIC16F15323 UART sending only null

Author
chrischristian
Starting Member
  • Total Posts : 38
  • Reward points : 0
  • Joined: 2008/03/21 00:29:13
  • Location: 0
  • Status: offline
2020/03/29 03:34:53 (permalink)
0

PIC16F15323 UART sending only null

/*
 * File: main.c
 * Author: christopher
 *
 * Created on 29 March 2020, 2:22 PM
 */


#include <xc.h>


// CONFIG1
#pragma config FEXTOSC = OFF // External Oscillator mode selection bits (Oscillator not enabled)
#pragma config RSTOSC = HFINT1 // Power-up default value for COSC bits (HFINTOSC (1MHz))
#pragma config CLKOUTEN = OFF // Clock Out Enable bit (CLKOUT function is disabled; i/o or oscillator function on OSC2)
#pragma config CSWEN = ON // Clock Switch Enable bit (Writing to NOSC and NDIV is allowed)
#pragma config FCMEN = ON // Fail-Safe Clock Monitor Enable bit (FSCM timer enabled)
#define _XTAL_FREQ 8000000



void main(void)

{
    OSCCON1bits.NDIV = 0; // necessary
  // OSCCON1bits.NOSC=0b110;
    OSCFRQbits.HFFRQ = 0b011; // 8MHz
    BRGH =0;
    BRG16 =0;
    SPBRGH = 0; SPBRGL = 12; //9600 baud
   // SPBRG =12;
    TRISC4=0; // TX is output
    TRISC5=1; // Rx is input
    
        // TXSTA register
    TXSTAbits.TX9 = 0; // 8-bit transmission
    TXSTAbits.TXEN = 1; // Enable transmission
    TXSTAbits.SYNC = 0; // Asynchronous mode
    
    // RCSTA register
    RCSTAbits.SPEN = 1; // Enable serial port
    RCSTAbits.RX9 = 0; // 8-bit reception
    RCSTAbits.CREN = 1; // Enable continuous reception
    RCSTAbits.FERR = 0; // Disable framing error
    RCSTAbits.OERR = 0; // Disable overrun error
    TRISC4 =0;
    TRISC5 =1;
    WUE =1 ;
    
    while(1)
    {
   while(!TX1IF) // hold the program till TX buffer is free
         TX1REG = 0x55; //Load the transmitter buffer with the received value
   __delay_us(1000);
   __delay_us(1000);
   __delay_us(1000);
   
   
    }
    
    return;
}

 
All I am getting for above code is 0x00 on the terminal, even if I comment the below line 
while(!TX1IF) // hold the program till TX buffer is free
         TX1REG = 0x55; //Load the transmitter buffer with the received value

I still continue to get 0x00, I am using a TTL to USB serial converter which works fine on other PIC 16F628 . Also If I power off the PIC the 0x00 stops coming through, so it is definitely not the TTL to USB converter that is spitting out those NULL chars. 
Can anyone please point me into right direction ?
Thanks,
Chris C
#1

4 Replies Related Threads

    pcbbc
    Super Member
    • Total Posts : 1687
    • Reward points : 0
    • Joined: 2014/03/27 07:04:41
    • Location: 0
    • Status: offline
    Re: PIC16F15323 UART sending only null 2020/03/29 04:28:30 (permalink)
    +3 (3)
    Missing semicolon at the end of this line...
    while(!TX1IF) // hold the program till TX buffer is free

    So your code never actually sends anything.
     
    As to why this is resulting in 0 at the RX end I do not know.
     
    #2
    ric
    Super Member
    • Total Posts : 26943
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: PIC16F15323 UART sending only null 2020/03/29 04:35:22 (permalink)
    +1 (1)
    pcbbc
    Missing semicolon at the end of this line...
    while(!TX1IF) // hold the program till TX buffer is free
    So your code never actually sends anything.

    Well spotted!
     

    As to why this is resulting in 0 at the RX end I do not know. 

    I don't see any config settings disabling the Watchdog Timer, so I suspect it is kicking in regularly.
    It's probably just a glitch during initialisation causing those null chars.
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #3
    davekw7x
    Entropy++
    • Total Posts : 1870
    • Reward points : 0
    • Joined: 2012/01/16 12:01:07
    • Location: Second star on the right, straight on till morning
    • Status: offline
    Re: PIC16F15323 UART sending only null 2020/03/29 06:58:15 (permalink)
    +2 (2)
    chrischristian
     
    All I am getting for above code is 0x00 on the termina
    ...please point me into right direction ?
     

    In addition to correcting the "missing semicolon" bug...

    You need to map EUSART1:TX1 to the output pin.
    Ref: Section 15.0, Table 15-5 in the Data Sheet DS40001897B
     
    RC4PPS = ????; // <---Must map TX1 to the output pin.  There is no default output!

     
     
    Also: As ric pointed out, you need to disable the Watchdog Timer (or "kick the dog" periodically), otherwise it resets every 2+ seconds.
     
    Regards,

    Dave
     
    post edited by davekw7x - 2020/03/29 07:33:00

    Attached Image(s)


    Sometimes I just can't help myself...
    #4
    chrischristian
    Starting Member
    • Total Posts : 38
    • Reward points : 0
    • Joined: 2008/03/21 00:29:13
    • Location: 0
    • Status: offline
    Re: PIC16F15323 UART sending only null 2020/03/29 16:07:39 (permalink)
    0
    Thank you guys, 
    The semicolon was not missing in my first few tries but when I copied some other code from google I missed it. 
    WDT was off on my 16F628 code and even on 16F15323 but later I got frustrated and started trying code from google which caused it. 
    The real culprit was RC4PPS (thanks davekw7x), would have never found it. 
     
    Cheers!
    Chris
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5