Ryan Schwingle

Interfacing a MC9S12DG256 with a Parallax GPS module

Discussion created by Ryan Schwingle on Aug 5, 2010
Latest reply on Aug 15, 2010 by kef

Hello all,

 

I am attempting to interface my Microdragon to a Parallax GPS unit, I have already referenced the aforementioned section in the SCI users manual and here is the code that I have come up with:

 

void SCI1_init (void)
{
//SCI 1 (Used to interface with GPS)
//Baud Rate registers. Baud rate is determined by bus clock / (16*baud registers)
SCI1BDH = 0x01;
SCI1BDL = 0x38;// 4800 Baud with 24 Mhz clock
//Control registers
SCI1CR1 = 0xA0;//    A   |   0
               // 10100000
               // | | | | | | | |
               // | | | | | | | \ PT        = 0 => Even parity
               // | | | | | | \__ PE        = 0 => Parity function disabled
               // | | | | | \____ ILT          = 0 => Idle character bit count begins after start bit
               // | | | | \______ WAKE      = 0 => Idle Line wakeup
               // | | | \________ M          = 0 => One start bit, eight data bits, one stop bit
               // | | \__________ RSRC      = 1 => Single wire mode with Rx input connected to TXD
               // | \____________ SCISWAI    = 0 => SCI Enabled in wait mode
               // \______________ LOOPS   = 1 => Loop Operation
SCI1CR2 = 0x2C;//    2   |   C
               // 0 0 1 0 1 1 0 1
               // | | | | | | | |
               // | | | | | | | \ SBK        = 0 => No break characters
               // | | | | | | \__ RWU        = 0 => Normal Operation
               // | | | | | \____ RE          = 0 => Reviever Enabled
               // | | | | \______ TE        = 0 => Transmitter Enabled
               // | | | \________ ILIE    = 0 => IDLE interrupt requests disabled
               // | | \__________ RIE       = 0 => Revieve data register full flag and overrun flag interrupt requests enabled
               // | \____________ TCIE      = 0 => Transmission Complete interrupt requests disabled
               // \______________ TIE     = 0 => Transmit Data Register Empty interrupt requests disabled

//SCI1SR1 READ ONLY register containing flags
SCI1SR2 = 0x00;//    X   |   0
          // x x x x x 0 0 x
               //           | | |
               //           | | \ RAF        = 0 => reception in progress / not in progress. READ ONLY
               //           | \__ TXDIR   = 0 => TXD pin to be used as an input in single-wire mode
               //           \____ BK13      = 0 => Break character is 10 or 11 bits long
//SCI1DRH = 0x00;
//SCI1DRL = 0x00; // Recieve / transmit bits 7-0
}



void SCI1_TX      (char data)
{
SCI1SR2 = SCI1SR2 | BIT1;       // sets TX mode
SCI1DRL = data;                 // Send data
while ((SCI1SR1 & 0x80) == 0);  // Wait for TDRE flag
}



void SCI1_RX      (void)
{
int i;
// Note: To clear receiver interrupt, need to read
// SCI1SR1, then read SCI1DRL.
// The following code does that
SCI1SR2 = SCI1SR2 & ~BIT1;           //Sets RX mode
if ((SCI1SR1 & 0x20) == 0) return; // Not receiver interrrupt
sci1data[i] = SCI1DRL;
i = i+1;
}

 

 

void Send_to_GPS (char *ptr)
{
while (*ptr) // While character to send
  {
  SCI1_TX(*ptr);                  // Transmit characters
  ptr++; // Go to next character
  }

}

void GPS_info     (void)
{
  char serialdata[5];
  sprintf(serialdata,"!GPS%X", GetInfo);
  Send_to_GPS(serialdata);
  SCI1_RX();
  ver_hw = sci1data[1];
  ver_fw = sci1data[2];
}

 

 

It seems to hang while I wait for the TDRE flag. Are there any other approaches or a better way of doing this?

 

Any help would be greatly appreciated! Thanks!

Outcomes