gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > Help! A little help with the UART

#161682 - enliteneer - Sun Aug 10, 2008 7:00 am

I'm trying to get the GBA and PC to talk to each other, but I can only get data into the gba.. nothing ever gets transmitted back out!

I'm using the application found here:
http://web.archive.org/web/20060603002957/http://www.fivemouse.com/gba/ . The application is supposed to echo any serial data received.

I've setup hyperterm for hardware handshaking and wired the level shifter according to this:
http://darkfader.net/gba/files/UART.gif (BTW the "GBA UART" cable from http://one-stop-china.com/ has been discontinued)

The keys I press on the computer are received and displayed correctly on the GBA, but the echo, and the hello world output from the console never occur. I also tried shorting the CTS and RTS lines together so that the GBA can send without hardware handshaking, but no luck.

I get the same results on two different gameboys, and with two different flash carts, so I'm thinking it has to be the code. The cable, works in one direction so Im assuming thats ok. But what could be wrong??

Code:
void InitUART(unsigned short UART)
{
  // The user should only be choosing the speed
  // Stick a character in the data register. This stops the GBA transmitting a
  // Character as soon as it goes into UART mode (?!?)
  REG_SIODATA8 = 'A';

  // Now to go into UART mode
  REG_RCNT = 0;
  REG_SIOCNT = 0;
  REG_SIOCNT = UART | SIO_CTS | SIO_LENGTH_8 | SIO_SEND_ENABLE
             | SIO_RECV_ENABLE | SIO_USE_UART;
}


void sndChar(unsigned char Character)
{
  // Wait until we have a CTS signal
  while(REG_RCNT & 0x0010);
  // Bung our byte into the data register
  REG_SIODATA8 = Character;
}

void AgbMain(void)
{
  unsigned char InChar[2];

  // Set to UART mode
  InitUART(SIO_BAUD_115200);

    sndChar('H');sndChar('e');sndChar('l');sndChar('l');sndChar('o');
    sndChar('W');sndChar('o');sndChar('r');sndChar('l');sndChar('d');

  // Just keep on looping...
  while(1) {
    // Read in a character
    InChar[0] = rcvChar();
    InChar[1] = 0;

    // If it's a CR, shift up the screen
    if(InChar[0] == 13) {
      ShiftScreen();
      ResetCursor();
    } else {
      // Otherwise, display it on teh screen
      Print(InChar);
    }

    // Echo it back as well
    sndChar(InChar[0]);
  }
}