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.

Reception in software UART

Status
Not open for further replies.

soft_learn

Newbie level 5
Joined
May 22, 2014
Messages
10
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
69
Hi,

I m trying to interface a software UART in which while receiving characters single's are received very well but when i try to receive a string it shows up out somne characters while receiving are overflowed bt being a new to this i m not getting where my problem is..???

My code for MikroC 6.0.1 is


Code C - [expand]
1
2
3
4
5
6
7
8
9
10
char error, byte_read;
void main()
{
 Soft_UART_Init(&PORTC,5,4,19200,0);      // RX Pin => PORTC.F5   TX Pin => PORTC.F4
 while(1)
 {
    byte_read = Soft_UART_Read (&error);   // Read byte, then test error flag
    Soft_UART_Write(byte_read);
 }
}



if any body knows about the reception in software plz help me out.
 
Last edited by a moderator:

I think you answered your own question: you're getting an overflow. You are not reading your UART fast enough. Is this interrupt driven? If not, then your loop time is too long. You could use handshaking.

Without seeing your actual code it's IMPOSSIBLE to tell you what's wrong.
 

as Barry says you are getting overruns which means you are loosing data - probably while you are writing out the last character received you are missing bits of the next character being received.

I would use a timer interrupting at at least 8 times the baud rate - the timer interrupt service routine would receive characters and put them in a ring buffer. The main program would be a loop - when a new character appears in the buffer it can be transmitted while the next character is being received
 

can u please help me out with this timer interrupting or if u have any program related to continous reception using software uart.
 

m using PIC16f877A and compiler is mikroc 6.0.0
 

m using PIC16f877A and compiler is mikroc 6.0.0

here is some code for the Microchip PICDEM mechatronics PIC16F917 board using the HiTech compiler - the timer is using interrupts - it may give you some ideas
Code:
// timerTest.c - simple test program for the  Microchip PICDEM mechatronics board
//
// interrupts 0.1mSec blinks a LED

// connect terminal emulator program to COMM port at 57600 baud

#include <htc.h>
#include "uart.h"


// Setup configuration bits
__CONFIG (EC & WDTDIS & PWRTDIS  & UNPROTECT &  MCLREN & BORDIS & FCMEN & IESOEN);

volatile int tenthMillSecCounter=0;               // incremented every 10mSec

// Timer 0 is programmed to interrupt every 0.1mSeconds
//  T0 clock is FOSC/4 = 200000
//  with 1:2 prescaler decrements 2000000/2 times / second
//  to get an interrupt every  0.1 mSec the calculation for TMR0 overflow from 0xFF to 0 is
//    count = 255 - 1000000/10000 = 255 - 100
//    i.e. for 0.1mSec counter is
#define tenthMillSec 155
static void interrupt isr(void)
{
    if (T0IF)                           // A TMR0 interupt occurred
    {
        TMR0=tenthMillSec;                // increment counters every .1 mSec
        tenthMillSecCounter++;
    }
    T0IF=0;                             // clear TMR0 interrupt flag
}

// delay for count tenths of a second
void tenthMilliSecondDelay(int count)
{
    tenthMillSecCounter=0;                         // zero counter
    while( tenthMillSecCounter  < count) ;    // wait
}
        
        
// initalise clock, set port A for digital input, set up timer 0, etc
void systemInitialise(void)
{
        OSCCON=0x70;             // Fosc use oscillator 8MHz
        ANSEL=0;                 // set digital inputs
        OPTION=0x80;             // TMR0 RATE 1:2
        TMR0=tenthMillSec;       // initialise timer 0 counter
        T0IE = 1;                // enable interrupt on TMR0 overflow from 0xFF to 0
        GIE = 1;                 // Global interrupt enable
 }



//extern int tenMillSecCounter, second, tenthsSecond;
// test program 
void main(void)
{
        int i=0, t, adc;
        char ch='0';
        systemInitialise();
        UARTInitialise();       // initalise UART for rS232 serial output
        TRISA1=1;               // RA1 is switch input
        TRISD6=0;               // RD6 is LED output
        TRISD5=0;               // RD5 is LED output
        RD6=1;                  // set LED
        putString("\n\rTest program for Microchp PICDEM mechatronics board\n\r\n\r");
        putString("\n\r");
        while(1)
        {                                        
             putchar(ch);
             if(ch++ == '9') ch='0';
             RD6=!RD6;                                     // invert LED to blink it
             tenthMilliSecondDelay(10000);
       }
}
 

Regarding original posted code.

Performing Soft_UART_Read() and Soft_UART_Write() alternatingly will necessarily fail with continuous (more than one) data bytes received because RX is blocked during TX.

A timer interrupt driven software UART can be a solution. More easily, if the data is received packet-wise, you may try to buffer the packet and then resend it.
 

as i am newbie to software uart. I want continuous reception of bytes using software UART if u guys know about something please help me out. after a lot help from u guys i am still not able to get about the timer interrupts.
 

as i am newbie to software uart. I want continuous reception of bytes using software UART if u guys know about something please help me out. after a lot help from u guys i am still not able to get about the timer interrupts.
have a look at this thread discussing timer interrupts with MicroC
https://www.edaboard.com/threads/296631/
 

using timer interrupts it doesn't work. it seems some error is still there i can't get continuous reception using soft uart.
 

post your code and what results you are getting, e.g. are you loosing all data or a few bits of character?
 

Thanks all for your kind support . I got my problem cleared.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top