0

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;

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

    }

  }
 } 

1 Answers1

0

I had the same issue. Some of the example code and documentation in the MikroC manual seems to contradict itself.

The prototype is:

void UARTx_Read_Text(char *Output, char *Delimiter, char Attempts);

Your delimiter should be:

char delimit[] = "OK";

UART1_Read_Text(&dataIn,&delimit,attempts);

If you know the size of the data being received attempts should correspond to this.