EngineersGarage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise
You are here: Home / Topics / More than four character Rx and Tx through UART

More than four character Rx and Tx through UART

|

Microcontroller › PIC › More than four character Rx and Tx through UART

  • This topic has 2 replies, 2 voices, and was last updated 12 years, 6 months ago by varma.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • August 6, 2013 at 11:56 am #4831
    varma
    Participant

    I am trying to transmit a string and raised receive interrupt as  
    taking buf[20] 
      
    void _attribute__((__interrupt__,no_auto_psv)) _U1RXInterrupt(void){  // This is UART1 receive ISR 
              IFS0bits.U1RXIF = 0; 
              for(i=0;i<20;i++) 
                buf = ReadUART1(); 
              putsUART1((unsigned int*)buf); 
    } 
      
    I used  
    U1MODEbits.LPBACK = 0;    // Disable Loop Back 
      
    U1STAbits.URXISEL = 2;    // Interrupt flag bit is set when Receive Buffer is 3/4 full (i.e., has 3 data characters) 
      
    when i am using value 2 here , the loop discontinues when 3 data characters are filled and remaining array is replaced by 3 char. 
    when i am using value 3 here, the loop discontinues when 4 data char are filled  
    when i am using value 0 or 1 , it prints the same what typed ,with out filling the char array. 
      
      
    where does my logic go wrong ? I want to print a string of length for example ” this is test”. 
    I want to get  
    [TX] : this is test 
    [RX] : this is test 
      
      
    In the case if I want to add a big paragraph, i cannot mention a particular size like buf[20], then how to initialize ? 

    August 7, 2013 at 5:33 am #10291
    AJISH ALFRED
    Participant

    Hi Varma,

    You could have make the query more simple rather than talking about the working of a piece of code first up. You haven’t mentioned anything about your project that you are doing, which microcontroller, which IDE, where you want to show the output, your circuit etc. 

    Since you know that your are getting unexpected results, the reasons should be also unexpected. 

    Please post the details and explain the trouble your are facing in such a way that it will be easy for others to understand.

     

    August 7, 2013 at 6:12 am #10292
    varma
    Participant
    dsPIC30F5011 / MPLAB8.8
     
     
    HI, 
     
    I have initilized a buffer array , char buf[24];
     
    wrote an ISR.
    configured bits as 
     
    <code>
     
    U1STAbits.UTXISEL = 1;    // Interrupt when a character is transferred to the Transmit Shift register
        U1STAbits.UTXBRK = 0;    // Operate U1Tx Normally on Transmit Break Bit
        U1STAbits.UTXEN   = 1;    // Enable U1 Tranmission   
       
        U1STAbits.URXISEL = 0;    // Interrupt flag bit is set when Receive Buffer is 3/4 full (i.e., has 1 data characters)
                                             //  b00 or b01 for 1 letter buffer size, b10 for 3 letter buffer , 11 for 4 letter buffer size
    </code>
     
    I could absolutely send and receive 1,3,4 chars respectively. And I can now understand that bufarray is being over written in last digits as I shown in the picture. 
     
    Now my problem is I want to transmit more than 4 letters at once and then receive.So for an example I have randomly chosen 24 chars . 
    If I write value for U1STAbits.URXISEL , the interrupt automatically breaks up when the buffer is full with 1 or 3 or 4 chars, as mentioned in the data sheet of the processor. 
     
    how do I write for a 24 char similarly ? Do I need to write a seperate ISR for this ? then how ? but I cannot use _U1TXInterrupt vector then. 
    Suggest me a way to do it ?
     
     
    code for UART.c
    <code>
     
    #include<P30F5011.h>
    #include”UART1.h”
    char buf[24];
    int j;
     
    void  init_UART1()                    // Initialization function.
    {                                                      
     
    TRISFbits.TRISF3 = 0;      // Configure RF3 as Output for UART1 Tx .
    TRISFbits.TRISF2 = 1;  // Configure RF2 as Input for UART1 Rx.
     
       /********************* CONFIGURE UART1 Baud Rate Generator Register *********************
            *                       *
            * FCY : 8 MHz, *
          * Desired Baud Rate : 9600    / 19200   * 
          * Desired U1BRG = 25 or 0x19h / 0x33 *
          *                       *
       ****************************************************************************************/
        U1BRG    = 51;  //XT /w PLL 4x
     
        /************************* CONFIGURE UART1MODE Register********************************/
        U1MODEbits.USIDL = 0;    // Continue operation in Idle mode
        U1MODEbits.ALTIO = 0;    // UART communicates usingalternate UxTX and UxRX I/O pins
        U1MODEbits.WAKE = 1;    // Enable Wake up
        U1MODEbits.LPBACK = 0;    // Disable Loop Back
        U1MODEbits.ABAUD = 0;    // Disable Auto Baud
        U1MODEbits.PDSEL = 0;    // 8 Bit Data, No Parity
        U1MODEbits.STSEL = 0;    // 1 Stop Bit
        
        IPC2bits.U1TXIP = 7;    // Tx priority level.
        IPC2bits.U1RXIP = 7; // Rx priority level.
        
        U1MODEbits.UARTEN = 1;    // Enable UART
        
        IEC0bits.U1TXIE = 1;    // Enabling TX interrupt.
        IEC0bits.U1RXIE = 1;    // Enabling Rx interrupt.
     
        
             
        /********************* CONFIGURE UART1 STATUS & CONTROL Register ***********************/
        U1STAbits.UTXISEL = 1;    // Interrupt when a character is transferred to the Transmit Shift register
        U1STAbits.UTXBRK = 0;    // Operate U1Tx Normally on Transmit Break Bit
        U1STAbits.UTXEN   = 1;    // Enable U1 Tranmission   
       
        U1STAbits.URXISEL = 0;    // Interrupt flag bit is set when Receive Buffer is 3/4 full (i.e., has 1 data characters)
      // putsUART1((unsigned int *)”UART Ready”);
     
     } 
     
     
     
    void putsUART1(unsigned int *buffer)
    {
    char * temp_ptr = (char *) buffer;         // transmit till NULL character is encountered      
    if(U1MODEbits.PDSEL == 3)                  // check if TX is 8bits or 9bits
    {      
    while(*buffer != ‘’)
    {
            while(U1STAbits.UTXBF); // wait if the buffer is full
                     U1TXREG = *buffer++;     // transfer data word to TX reg
            }
        }
        else 
    {
                 while(*temp_ptr != ‘’) 
            {
                     while(U1STAbits.UTXBF);   // wait if the buffer is full 
                     U1TXREG = *temp_ptr++;    // transfer data byte to TX reg 
                 }
        }
    }
     
     
    void __attribute__((__interrupt__,no_auto_psv)) _U1TXInterrupt(void) // This is UART1 transmit ISR
    {
        IFS0bits.U1TXIF = 0;
        
        
    }
     
    void __attribute__((__interrupt__,no_auto_psv)) _U1RXInterrupt(void) // This is UART1 receive ISR
    {
         IFS0bits.U1RXIF = 0;
         for(j=0;j<=24;j++)
             buf[j]=ReadUART1();
             
                  putsUART1((unsigned int*)buf);
            
    } 
     
    </code>
  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.
Log In

RSS Recent Posts

  • To couple or decouple February 10, 2026
  • ANOTHER OLD PROJECT REDO February 10, 2026
  • analog logic of shmidt trigger bjt circuit February 10, 2026
  • Buffer design? February 10, 2026
  • XLR splitter to mono. February 10, 2026

Stay Up To Date

Newsletter Signup
EngineersGarage

Copyright © 2026 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Engineers Garage Main Site
  • Visit our active EE Forums
    • EDABoard.com
    • Electro-Tech-Online
  • Projects & Tutorials
    • Circuits
    • Electronic Projects
    • Tutorials
    • Components
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • Advertise