with software uart i am able to write data but not read data

General discussion on mikroC.
Post Reply
Author
Message
try4ajay
Posts: 2
Joined: 18 Mar 2011 10:52

with software uart i am able to write data but not read data

#1 Post by try4ajay » 18 Mar 2011 11:02

Code: Select all

unsigned short data = 0, ro = 0;
unsigned short *rec;

void main() {
  er = &ro;

  // Init (8 bit, 2400 baud rate, no parity bit..)
  Soft_Uart_Init(PORTB, 1, 2, 2400, 0);

  do {
    do {
      data = Soft_Uart_Read(rec); // Receive data
    } while (!*rec);
    Soft_Uart_Write(data);        // Send data via UART
  } while (1);
}//~!


this program given in Qhelp is not working ,please help

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: with software uart i am able to write data but not read

#2 Post by tihomir.losic » 18 Mar 2011 11:37

Hello,

please, tell me which version of our mikroC compiler are you using?

Thanks.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

try4ajay
Posts: 2
Joined: 18 Mar 2011 10:52

Re: with software uart i am able to write data but not read

#3 Post by try4ajay » 19 Mar 2011 16:12

version 8.2.0.0

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: with software uart i am able to write data but not read

#4 Post by tihomir.losic » 21 Mar 2011 13:46

Hello

We warmly suggest you to switch to mikroC PRO for PIC compiler.
If you're a registered user you'll receive PRO license key free of charge.
PRO version is in so many ways better than the version you have.

Download link:
http://www.mikroe.com/eng/products/view ... o-for-pic/

Also, I am giving you code which works (EasyPIC6, PIC16F887):

Code: Select all

char i, error, byte_read;                 // Auxiliary variables

void main(){

  ANSEL  = 0;                             // Configure AN pins as digital I/O
  ANSELH = 0;
  
  TRISB = 0x00;                           // Set PORTB as output (error signalization)
  PORTB = 0;                              // No error

  error = Soft_UART_Init(&PORTC, 7, 6, 14400, 0); // Initialize Soft UART at 14400 bps
  if (error > 0) {
    PORTB = error;                        // Signalize Init error
    while(1) ;                            // Stop program
  }
  Delay_ms(100);

  for (i = 'z'; i >= 'A'; i--) {          // Send bytes from 'z' downto 'A'
    Soft_UART_Write(i);
    Delay_ms(100);
  }
   
  while(1) {                              // Endless loop
    byte_read = Soft_UART_Read(&error);   // Read byte, then test error flag
    if (error)                            // If error was detected
      PORTB = error;                      //   signal it on PORTB
    else
      Soft_UART_Write(byte_read);         // If error was not detected, return byte read
    }      
}
For any further assistance, feel free to contact us.

Best regards,

Losic Tihomir
mikroElektronika [Support team]

Post Reply

Return to “mikroC General”