Reading Soft_Uart & Hardware Uart @ same time

General discussion on mikroC PRO for FT90x.
Post Reply
Author
Message
AnumSheraz
Posts: 7
Joined: 12 Apr 2015 20:43

Reading Soft_Uart & Hardware Uart @ same time

#1 Post by AnumSheraz » 13 Apr 2015 06:56

OK, so i have accomplished creating a software and hardware UART on PIC18f8680 in MikroC compiler. The Soft_Uart uses timer0 for interrupt and breaks the Soft_UART_read() line by a function called Soft_uart_Break().

everything is working fine, when i read a single character from both uart. but when i send a string on hardware uart, the string doesn't gets reads properly by these lines;

UART1_Read_Text(buffer, "OK", 100);
UART1_Write_Text(buffer);

I've found out whats causing this problem. that is, my main while loop gets stuck in Soft_UART_read() until it gets break by an interrupt. while its stuck over there, the hardware uart doesn't gets proper time to read the whole string, so as a result it displays some of the characters of that string.

how can i overcome this ? do i need to use a separate interrupt for hardware uart aswel ? or what ? any help would be highly appreciated. here is a snip of my code;

Code: Select all

  void main() {

  INTCON.GIE=1;         //globle interrupt enable
  INTCON.PEIE=1;        //peripharel interrupt enable
  INTCON.TMR0IF = 0x0;  //Clear timer0 overflow interrupt flag
  INTCON.TMR0IE = 1;    //enable the timer0 by setting TRM0IE flag
  T0CON.TMR0ON = 1;  // Timer0 On/Off Control bit: 1=Enables Timer0 / 0=Stops Timer0
  T0CON.T08BIT = 0;  // Timer0 8-bit/16-bit Control bit: 1=8-bit timer/counter / 0=16-bit timer/counter
  T0CON.T0CS   = 0;  // TMR0 Clock Source Select bit: 0=Internal Clock (CLKO) / 1=Transition on T0CKI pin
  T0CON.T0SE   = 0;  // TMR0 Source Edge Select bit: 0=low/high / 1=high/low
  T0CON.PSA    = 1;  // Prescaler Assignment bit: 0=Prescaler is assigned; 1=NOT assigned/bypassed
  T0CON.T0PS2  = 0;  // bits 2-0  PS2:PS0: Prescaler Select bits
  T0CON.T0PS1  = 1;
  T0CON.T0PS0  = 1;
  TMR0H = 0xBD;        // preset for Timer0 MSB register
  TMR0L = 0xCD;       // preset for Timer0 LSB register

 while(1) {
 data1 = Soft_UART_Read(&error);
   Soft_UART_Write(data1);
  if   (data1 == 'b') {
      for(x = 0; x <= strlen(alive); x++) {
          Soft_UART_Write(alive[x]);
       }
   }

  if (UART1_Data_Ready()) {     // If data is received,
   UART1_Read_Text(buffer, "OK", 100);    // reads text until 'OK' is found
   UART1_Write_Text(buffer);             // sends back text
  /*if   (uart_rd == 'a') {
      UART1_Write_Text("\rSensor 1 data\r");

  }*/
  //else
  //UART1_Write(uart_rd);      // and send data via UART

    }

  }
 } 


User avatar
petar.timotijevic
mikroElektronika team
Posts: 1739
Joined: 19 Feb 2014 13:46
Location: Serbia
Contact:

Re: Reading Soft_Uart & Hardware Uart @ same time

#2 Post by petar.timotijevic » 16 Apr 2015 23:02

Hi,

In Help you can see important note for Software UART Library that the Software UART library implements time-based activities, so interrupts need to be disabled when using it.


Best regards,
Peter

jpc
Posts: 1986
Joined: 22 Apr 2005 17:40
Location: France 87

Re: Reading Soft_Uart & Hardware Uart @ same time

#3 Post by jpc » 27 Apr 2015 11:12

you might have a look here http://www.mikroe.com/forum/viewtopic.p ... t=softuart
the softuart as provided with the compiler is a rather primitive one, pics can definitely do better if you give them a chance
Au royaume des aveugles, les borgnes sont rois.

User avatar
petar.timotijevic
mikroElektronika team
Posts: 1739
Joined: 19 Feb 2014 13:46
Location: Serbia
Contact:

Re: Reading Soft_Uart & Hardware Uart @ same time

#4 Post by petar.timotijevic » 27 Apr 2015 11:22

Hi,
jpc wrote:you might have a look here http://www.mikroe.com/forum/viewtopic.p ... t=softuart
the softuart as provided with the compiler is a rather primitive one, pics can definitely do better if you give them a chance
Very interesting codes. Thank you for sharing this with other users.

If you want you can publish project files on LibStock web site at http://www.libstock.com


Best regards,
Peter

Post Reply

Return to “mikroC PRO for FT90x General”