This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Can send serial data but not receive

When I try to use getchar, the program just hangs. It seems as though the bit in the U0LSR register that says data is in the RDR register is not being set.

printf works just fine as I can see everything I need to see in hyperterminal. So I know data is being transmitted, I'm just not sure if data is being received.
Heres the modified getchar function.

int getchar (void)
{              /* Read character from Serial Port   */

  while (!(UART0_LSR & 0x01));

  return (UART0_RBR);
}

Parents
  • Hi the code fragment you posted looks fine, are you sure the RX is enabled. Here follows code that works, for none interupt use I think you only need to set PINSEL0, U0LCR, U0DLL, U0LCR. Just use the simulator to check things are working.

    void serial_init (void) {
      PINSEL0 = 0x00000005; // Enable RxD0 and TxD0
      U0LCR = 0x83;        // 8 bits, no Parity, 1 Stop bit
      U0DLL = 8;    // 115200 Baud Rate @ 15MHz VPB Clock
      U0LCR = 0x03; // DLAB = 0
      U0FCR = 0x87; // RX interrupt at 8 chars
      U0IER = 0x03; // Enable RDA and THRE interrupts
      VICVectAddr14  = (U32)int_serial;
      VICVectCntl14 |= 0x20 | 0x06; // Enable VIC with index 7
      VICIntEnable  |= 0x40; // VIC Chnl#7
      sendstop = __FALSE;    // CtrlQ not received
      ridx = widx = 0;          // clear buffer indexes
    }
    

Reply
  • Hi the code fragment you posted looks fine, are you sure the RX is enabled. Here follows code that works, for none interupt use I think you only need to set PINSEL0, U0LCR, U0DLL, U0LCR. Just use the simulator to check things are working.

    void serial_init (void) {
      PINSEL0 = 0x00000005; // Enable RxD0 and TxD0
      U0LCR = 0x83;        // 8 bits, no Parity, 1 Stop bit
      U0DLL = 8;    // 115200 Baud Rate @ 15MHz VPB Clock
      U0LCR = 0x03; // DLAB = 0
      U0FCR = 0x87; // RX interrupt at 8 chars
      U0IER = 0x03; // Enable RDA and THRE interrupts
      VICVectAddr14  = (U32)int_serial;
      VICVectCntl14 |= 0x20 | 0x06; // Enable VIC with index 7
      VICIntEnable  |= 0x40; // VIC Chnl#7
      sendstop = __FALSE;    // CtrlQ not received
      ridx = widx = 0;          // clear buffer indexes
    }
    

Children
No data