How to establish Serial Communication between DEVKIT-S12G128 with PC?

cancel
Showing results for 
Search instead for 
Did you mean: 

How to establish Serial Communication between DEVKIT-S12G128 with PC?

549 Views
lukmankurniawan
Contributor II

Hello All,

I just try using DEVKIT-S12G128. On the example that I found, I just got SCI between TXD0 with RXD0 example which is local uart communication. After I check the board, the pins that connect to USBtoSerial is TXD1 & RXD1. So I try changing the PIN number on Processor Expert with the same baudrate and modified the code as well as below, but it still didn't work. The hyperterminal on PC didn't receive any data. What is the problem?

 

void SCI_Send(char *pSendBuff)
{ 
int ptr = 0;

while(pSendBuff[ptr]!='\0')

   {

    SCI1DRL = pSendBuff[ptr]; 
     while(!SCI1SR1_TC);

    ptr++;
   }
}

unsigned char SCI_Read(void)

{

    if(SCI1SR1_RDRF)

   {
     return SCI1DRL;
   }
}

 

 

I appreciate your help.

Best Regards,

 

Lukman

Labels (1)
0 Kudos
4 Replies

312 Views
lama
NXP TechSupport
NXP TechSupport

Bellow is presented simple, tested and working example usng polling communication.

The PC uses com3 set for 9600bps. The channel can be found in the DeviceManager->Ports(COM & LPT), serch for OSBDM/OSJTAG

pastedImage_1.png

I have used hyperterminal for communication on the PC side. What you use is up to you.

//==============================================================================
// very simple polling mode is used
//==============================================================================

#include <hidef.h>      /* common defines and macros */
#include "derivative.h"      /* derivative-specific definitions */
#include <stdio.h>

//==============================================================================
         char str[255];
unsigned char SCI1_RxChar;
unsigned char SCI1_TxChar;
unsigned char SCI1_scisr1;

//==============================================================================
void diodes(void);
void SetPEEmodeBUSCLK(byte _synr, byte _refdv, byte _postdiv);
void SCI0_Init(void);
void SCI1_sendChar(char c);
void SCI0_sendText(char *str);
//==============================================================================
void SCI1_sendText(char *str)
{
  unsigned char i=0;
  while(str[i]!='\0')
    {
      SCI1_sendChar(str[i++]);
    }
}
//==============================================================================
void SCI1_sendChar(char c)
{
  while(!SCI1SR1_TC); // wait for free buf
  SCI1DRL = c;
}
//==============================================================================
void diodes(void)
{
  PTP_PTP3 = 1;    PTP_PTP4 = 1;    PTP_PTP6 = 1; // switch off
  DDRP_DDRP3 = 1; // R connect
  DDRP_DDRP4 = 1; // G connect
  DDRP_DDRP6 = 1; // B  connect
}
//==============================================================================
void SetPEEmodeBUSCLK(byte _synr, byte _refdv, byte _postdiv)
{
 CPMUSYNR    = _synr;
 CPMUREFDIV  = _refdv;
 CPMUPOSTDIV = _postdiv;   
 
 CPMUOSC_OSCE = 1; //enable external oscillator OSCE
    
 while(!CPMUFLG_UPOSC)
  {// you can check for timeot here with error message report
  };    
 while(!CPMUFLG_LOCK)
  {// you can check for timeot here with error message report
  };    
 
  //--- select clocks --------------------
 CPMUCLKS = 0B10000011;                   // bus=fPLL/2; COP is clocked from OSCCLK
 if(CPMUCLKS != 0B10000011)               // After writing CPMUCLKS register, it is strongly recommended to read  
  {                                       // back CPMUCLKS register to make sure that write of PLLSEL,
     asm nop;                             // RTIOSCSEL, COPOSCSEL0 and COPOSCSEL1 was successful.
  }
 //--------------------------------------
}
//==============================================================================
void SCI1_Init(void)
{
 //----- BR = BUSCLK / (16*Baud rate)-------
                                            //------------------------------------------------------
                                            // prescaller value (depends on module clock frequency)
   //SCI1BD  = 0x34;                        // 9600 Bd at  8 MHz bus clock
   //SCI1BD  = 0x68;                        // 9600 Bd at 16 MHz bus clock
   SCI1BD  = 0x9C;                          // 9600 Bd at 24 MHz bus clock
                                            //------------------------------------------------------
   SCI1CR1 = 0x44;                          // Loops sciswai rsrc   m    wake  ilt   pe    pt       
                                            // 0-LOOPS=RSRC=0 => 1 Single-wire mode with Rx input connected to TXD
                                            // 1-SCI0 dis. in wait mode                              
                                            // 0-if RSRC=1-RxTx intern. connected if loops=1                  
                                            // 0-start+8 data+1 stop bit                          
                                            // 0-IDLE mark wake up                                  
                                            // 1-idle char. bit count begins after stop bit         
                                            // 0-parity fction disabled                             
                                            // 0-odd parity                                       
                                            //------------------------------------------------------
   SCI1CR2 = 0x0C;                          // tie   tcie    rie  ilie   te    re   rwu   sbk       
                                            // 0-Tx empty intr disabled                             
                                            // 0-Tx complete intr disabled                          
                                            // 1-Rx full + OverRun interrupts
                                            // 0-idle line intr disabled                            
                                            // 1-transmitter enabled
                                            // 1-receiver enabled
                                            // 0-receiver normal operation                                   
                                            // 0-no break characters                                
}                                                                                        
//==============================================================================

void main(void)
{
 //------------------------------------
  //SetPEEmodeBUSCLK(0x58, 0x07, 0x00);   // 25MHz BUSCLK from 8 MHZ oscclk, PEE mode
  //SetPEEmodeBUSCLK(0x01, 0x80, 0x00);   // 16MHz BUSCLK from 8 MHZ oscclk, PEE mode
  //SetPEEmodeBUSCLK(0x01, 0x80, 0x07);   // 2MHz BUSCLK from 8 MHZ oscclk, PEE mode
  SetPEEmodeBUSCLK(0x02, 0x80, 0x00);     // 24MHz BUSCLK from 8 MHZ oscclk, PEE mode
 //------------------------------------
 SCI1_Init();
 //------------------------------------
 (void) sprintf(str,"\n\r\n\rI am alive\n\r\n\r");
 //------------------------------------
  SCI1_sendText(str);
  SCI1_sendText(str);
  SCI1_sendText(str);
 //------------------------------------
  while(1)
    {
     if((SCI1SR1 & (SCI1SR1_OR_MASK | SCI1SR1_RDRF_MASK))) // check whether char was received
       {
         if(SCI1SR1 & SCI1SR1_OR_MASK)                // if overrun error do nothing/something
           {
            (void)SCI1DRL;                          // clear interrupt flag
            // do something to process error
           }
         else
           {
            SCI1_TxChar = SCI1_RxChar = SCI1DRL;    // read received character + clear interrupt flag
            SCI1_sendChar(SCI1_TxChar);             // echo received character
           }
      }
    
      // PTP_PTP3 = 0; PTP_PTP3 = 1; // R
      // PTP_PTP4 = 0; PTP_PTP4 = 1; // G
      // PTP_PTP6 = 0; PTP_PTP6 = 1; // B
    }
 //------------------------------------
}

Best regards,

Ladislav

0 Kudos

312 Views
lukmankurniawan
Contributor II

Hi Lama,

Thank you for your reply. Btw, on your device manager showing that you have comport1. But why on my PC only showing OSBDM/OSJTAG without any comport? any driver you install?

Best Regards,

Lukman

0 Kudos

312 Views
lama
NXP TechSupport
NXP TechSupport

Hi,

I suppose you are connected to the Devkit by USB cable. In this case CodeWarrior IDE uses OSBDM. The OSBDM is included insiede CW IDE as a default communication protocol for debugging so you should use this one. There is commnication device place onto the board which communicates via the same cable as an UART and BDM.

Why Have I COM1? Because my laptop is docked and the dock contains true RS232 connector so if any devkit or developmnet vboard containd RS232 transceiver and connector I am able to communicate also in this way. However, this board does not contain RS232 transceiver so you have to use described way of connection. I have not installed any driver on laptop. i have only selected COM3 in the hyperterminal.

BTW, hyperterminal .. I have only copied exe version and dll file from older PC. You can use another type of similar software. Docklight,......

Once more, no additional installation. Only select COM port assigned to your OSBDM also to your communication SW. Do not forget to set correct bitrate.

Ladislav

0 Kudos

312 Views
lukmankurniawan
Contributor II

Hi Lama,

I already can have SCI communication with PC.

Thank you for your help.

Best Regards,

Lukman

0 Kudos