Randall Hinton

MC9S12DP256  D-Bug12  SCI with NSC200 motorcontroller

Discussion created by Randall Hinton on May 26, 2006
Latest reply on Jun 5, 2006 by Jeff Smith
I am trying to initiate communication between a NSC200 (motorcontroller) and a MC9S12DP256 (HC12 microcontroller) using D-Bug12 4.0.0b29 in EVB mode.
The NSC200 manual states that I need to use CTS/RTS hardware handshake protocol. Do I need to accomadate that in my code?
Below I describe what works and what does not.

Connection 1
Description:
HC12 SCI0 --> Desktop (AsmIDE) 9600 8-N-1
HC12 SCI1 --> Laptop (Hyperterminal) 19200 8-N-1

Purpose: Verify HC12 has correct settings and is sending and receiving data from SCI1

Using the following code

Code:
#include /* derivative information */#include "pll.h" /* defines _BUSCLOCK, sets bus frequency to _BUSCLOCK MHz */#include "sci0.h" /* support for SCI0 */#include "sci1.h" /* support for SCI1 */void main(void) {char myString0[32];/* set system clock frequency to _BUSCLOCK MHz (24 or 4) */PLL_Init();/* initialise serial communication interface SCI0 */SCI0_Init(BAUD_9600);/* initialise serial communication interface SCI1 */SCI1_Init(BAUD_19200);SCI1_OutString("Enter string\n\r");SCI1_InString(myString0, 10);SCI0_OutString("\n\rYou have entered: ");SCI0_OutString(myString0);SCI0_OutString("\n\r\n\r");}

 

Hyperterminal screen:

Enter string
Hello desktop

AsmIDE screen:
You have entered: Hello desktop

Conclusion: Communication settings are correct. C code and serial commands are correct.
**********************************************************************************************

CONNECTION 1
Description: Same
Purpose: Send a motorcontrol command to Hyperterminal

using the following command
SCI1_OutString("1TE?\r");

Hyperterminal screen:
1TE?

Conclusion: It appears that the motorcontrol command is being sent correctly.
**********************************************************************************************
CONNECTION 2
Description:
Laptop (Hyperterminal) 19200 8-N-1 --> NSC200 19200 8-N-1
Purpose:

Send known motorcontrol command to NSC200 and verify output.

using echo and hitting after the command
Hyperterminal:
1VE? 3.5 NSC200
1TE? 0
1OR

1OR sends the motor unit to the "home" position

Conclusion:
Motor works. Commands work. Commucation settings are correct.
**********************************************************************************************

CONNECTION 3 (Trial 1)
Description:
HC12 SCI0 --> Desktop (AsmIDE) 9600 8-N-1
HC12 ScI1 --> NSC200 19200 8-N-1

Using the following code

Code:
#include /* derivative information */#include "pll.h" /* defines _BUSCLOCK, sets bus frequency to _BUSCLOCK MHz */#include "sci0.h" /* support for SCI0 */#include "sci1.h" /* support for SCI1 */void main(void) {char myString0[32];/* set system clock frequency to _BUSCLOCK MHz (24 or 4) */PLL_Init();/* initialise serial communication interface SCI0 */SCI0_Init(BAUD_9600);/* initialise serial communication interface SCI1 */SCI1_Init(BAUD_19200);SCI1_OutString("1OR\r");SCI1_OutString("1VE—\r");SCI1_InString(myString0, 10);SCI0_OutString("\n\rYou have entered: ");SCI0_OutString(myString0);SCI0_OutString("\n\r\n\r");}

 

Only on rare occasions of resetting and unplugging the board and controller will the motor actually move, but it has never sent data back to the board.
One more question what do the RX and TX LED's correspond to?

Here is the relevent code from sci1.c

Code:
// filename *************** sci1.c ******************************// Simple I/O routines to 9S12C32 serial port// Jonathan W. Valvano 1/29/04// Copyright 2004 by Jonathan W. Valvano, valvano@mail.utexas.edu// You may use, edit, run or distribute this file// as long as the above copyright notice remains// Modified by EE345L students Charlie Gough && Matt Hawk// Modified by EE345M students Agustinus Darmawan + Mingjie Qiu//// adapted to the Dragon12 board using SCI1 -- fw-07-04// allows for 24 MHz bus (PLL) and 4 MHz bus (no PLL) -- fw-07-04#include /* derivative information */#include "sci1.h"#include "pll.h" /* macro _SYSCLOCK */#define RDRF 0x20 // Receive Data Register Full Bit#define TDRE 0x80 // Transmit Data Register Empty Bit//-------------------------SCI1_Init------------------------// Initialize Serial port SCI1// Input: baudRate is tha baud rate in bits/secvoid SCI1_Init(unsigned short baudRate) {SCI1BDH=0;SCI1BDL=78;SCI1CR1 = 0;SCI1CR2 = 0x0C;}//-------------------------SCI1_InChar------------------------// Wait for new serial port input, busy-waiting synchronization// Output: ASCII code for key typedchar SCI1_InChar(void) {while((SCI1SR1 & RDRF) == 0){};return(SCI1DRL);}//-------------------------SCI1_OutChar------------------------// Wait for buffer to be empty, output 8-bit to serial port// busy-waiting synchronization// Input: 8-bit data to be transferredvoid SCI1_OutChar(char data) {while((SCI1SR1 & TDRE) == 0){};SCI1DRL = data;}

 
Alban shaped code for lisibility & re-use

Message Edited by Alban on 06-06-2006 01:02 PM

Outcomes