UART COMMUNICATION BETWEEN K64F AND KV31F

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

UART COMMUNICATION BETWEEN K64F AND KV31F

1,184 Views
vallisanghamish
Contributor II

I am trying to control the PMSM motor connected to KV31F based on trigger I receive from FRDM-K64F via UART using Kinetis Motor Suite (KMS). UART0 in KV31F is being used for PMSM motor control and I'm using UART1 to establish communication between the 2 boards. After generating state flow diagram on KMS ,I have added the below code to motionsequence.c in KDS.Though there are no errors,I am unable to run the motor.

/* ACTIONS */

InitUserPlanVariables();

uint8_t rxInt = 0;
uint32_t byteCountBuff = 0;
uint32_t uartSourceClock = 0;
UART_Type * baseAddr = BOARD_DEBUG_UART_BASEADDR;

// Enable clock for PORTs, setup board clock source, config pin
PINS_init();

BOARD_ClockInit();

configure_uart_pins(0);

// Initialize the uart module with base address and config structure
CLOCK_SYS_EnableUartClock(BOARD_DEBUG_UART_INSTANCE);

// Get working uart clock
uartSourceClock = CLOCK_SYS_GetUartFreq(BOARD_DEBUG_UART_INSTANCE);

// Initialize UART baud rate, bit count, parity and stop bit
UART_HAL_SetBaudRate(baseAddr, uartSourceClock, BOARD_DEBUG_UART_BAUD);
UART_HAL_SetBitCountPerChar(baseAddr, kUart8BitsPerChar);
UART_HAL_SetParityMode(baseAddr, kUartParityDisabled);
#if FSL_FEATURE_UART_HAS_STOP_BIT_CONFIG_SUPPORT
UART_HAL_SetStopBitCount(baseAddr, kUartOneStopBit);
#endif

// Enable the UART transmitter and receiver
UART_HAL_EnableTransmitter(baseAddr);-
UART_HAL_EnableReceiver(baseAddr);

while(true)
{
// Wait to receive input data
if (kStatus_UART_Success == UART_HAL_ReceiveDataPolling(baseAddr, &rxInt, 1u))
//if(GPIO_DRV_ReadPinInput(PTE1)==1)
{
//input to state variable of kms

userPlanVariables.FRDMBoardInput = 1;

}
}

Labels (1)
Tags (3)
0 Kudos
2 Replies

741 Views
philip_drake
NXP Employee
NXP Employee

Hello, 

I take it from the code above you downloaded KMS a while back. This code is from a release of KMS, 1.0.1.  It is using the Kinetis SDK 1.3 which has been replaced with MCUXpresso SDK 2.x. 

I recommend that you upgrade to the latest release and tool chain if you can.  

There are a number of advantages to the new release KMS 1.2.0 that you can realize.  First, the wider breadth of MCUs supported, KV31, KV11, KV46. Next is the ease of use of the MCUXpresso tools, the IDE, the pins and clocks config tools.  There were a few important issues fixed and features added with the KMS 1.2.0 release as well (like protection of the KMS library from mass erase).  The KMS 1.2.0 also included support for ACIM motor control with KMS. 

You are correct that KMS is using UART0 during KMS motor commissioning. The use of this UART is not permanent and can be replaced with a motor control interface once the motor is parameterized and ready for production. If you want to keep the KMS GUI interface and add another UART or other interface for control that is OK as well. 

To the specific question. 

It tough not to first direct you to the MCU Reference manual where there is all of the documentation on the UART implementation as well as a function description. Here is the section 3.9.3.1 of the RM.

3.9.3.1 UART configuration information This chip contains three UART modules. This section describes how each module is configured on this device.

1. Standard features of all UARTs: • RS-485 support • Hardware flow control (RTS/CTS) • 9-bit UART to support address mark with parity • MSB/LSB configuration on data

2. UART0 and UART1 are clocked from the core clock, the remaining UARTs are clocked on the bus clock. The maximum baud rate is 1/16 of related source clock frequency.

3. IrDA is available on all UARTs

4. UART0 contains the standard features plus ISO7816

5. UART0 contains 8-entry transmit and 8-entry receive FIFOs

6. All other UARTs contain a 1-entry transmit and receive FIFOs

Another source of help might be the KQRUG

The use of a UART channel to control the motor is a good way of communicating between MCUs. 

The steps to take must include the pin_mux assignment changes to route the pins to the UART.  I cannot tell from just the call to PINS_init() above whether this additional setting were included.

Next it to know the specifics of the UARTS on the Kinetis part.  The clocks, and features.  For instance UART1 does not have a FIFO like UART0.

The next place to go for examples is the SDK driver examples or demo_apps folder (...\KSDK_1.3.0\examples\frdmkv31f\driver_examples)

I often use an Oscilloscope and test loop-backs driving the capitol letter '"U"  to check the baud rate match up. 

I hope this helps.

Regards,

Philip Drake

0 Kudos

741 Views
vallisanghamish
Contributor II

Hi Philip,

Thanks for your response. The documents were helpful and I did try to run the example in the demo_app folder. 

On the other hand, I have tried creating the state diagram for a simple fan speed application on KMS. 

From the above 2 examples that I implemented, I would like to know if I can use a flag (to confirm if the data from K64F board has been received on KV31F) to change the value of UserPlanVariable in the watch window from 0 to 1,to run the motor, instead of manually changing it. 

Below are the two code snippets I have changed in my code on KDS:

1) rda_uart_fsl_sdk.c

void RDA_UART1_ISR(void) {      uint8_t data;     uint32_t rx_head = uart_rx_head;     uint32_t tx_tail = uart_tx_tail;       if(data)      {     flagValue = true; //to know if the data has been received from K64F.      }  }
If my flag value is true, I want my UserPlanVariable value to be updated to 1 
for the motor to run without any manual intervention.


2)main.c
void UART1_RX_TX_IRQHandler(void) {     timestamp_t startCycleCount = GetProfilerCycles();      RDA_UART1_ISR();      CpuUtilization.UartIsrCycles = GetProfilerCycles() - startCycleCount; }

 Please let me know if I am in the right track.

0 Kudos