Microcontroller: Kinetis KV31P128
IDE: MCUXpresso
SDK: SDK_2.2_MKV31F128xxx10
I am needing to communicate with the micro using UART0. I have setup the UART0 interrupt to be triggered when a single byte of data is received.
If I set a break-point at "void UART0_DriverIRQHandler(void)" routine, the break-point is triggered as soon as I write a byte of data to UART0.
The peripheral registers are set as follows:
- UART0_S1: IDLE = 1, RDRF = 1, TC = 1, TDRE = 1, others = 0
- UART0_S2: RXEDGIF = 1, others = 0
- UART0_D: 0x55 (the byte I sent to UART0)
The problem I am having is as follows:
As soon as I step into the IRQ handler: "void UART_TransferHandleIRQ(UART_Type *base, uart_handle_t *handle)" the RDRF and IDLE flags in UART0_S1 and the value in UART0_D are cleared. UART0_S2 remains unchanged. As a result of this, my callback function is never triggered.
Source code as follows:
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
#include "board_init.h"
#include <stdio.h>
#include "board.h"
#include "fsl_uart.h"
#include "clock_config.h"
#include "MKV31F12810.h"
#include "fsl_gpio.h"
#define UART0_CLKSRC kCLOCK_PllFllSelClk
#define UART0_CLK_FREQ CLOCK_GetFreq(kCLOCK_PllFllSelClk)
uart_handle_t g_uartHandle;
uart_transfer_t sendXfer;
uart_transfer_t receiveXfer;
uint8_t g_tipString[] = "UART0\r\n";
volatile bool txFinished;
volatile bool rxFinished;
uint8_t receiveData[32];
void UART0_UserCallback(UART_Type *base, uart_handle_t *handle, status_t status, void *userData)
{
userData = userData;
if (kStatus_UART_TxIdle == status)
{
txFinished = true;
}
if (kStatus_UART_RxIdle == status)
{
rxFinished = true;
}
}
int main(void) {
uart_transfer_t xfer;
uint8_t ch;
uart_config_t config;
BOARD_InitBootPins();
BOARD_InitBootClocks();
BOARD_InitDebugConsole();
BOARD_InitPeripherals();
UART_GetDefaultConfig(&config);
config.baudRate_Bps = 115200;
config.enableTx = true;
config.enableRx = true;
config.rxFifoWatermark = 1;
UART_Init(UART0, &config, UART0_CLK_FREQ);
printf("Hello World\n");
xfer.data = g_tipString;
xfer.dataSize = sizeof(g_tipString) - 1;
UART_TransferCreateHandle(UART0, &g_uartHandle, UART0_UserCallback, NULL);
UART_EnableInterrupts(UART0, kUART_RxDataRegFullInterruptEnable | kUART_IdleLineInterruptEnable);
UART_TransferSendNonBlocking(UART0, &g_uartHandle, &xfer);
while(1)
{
if(rxFinished == true)
{
// Do Stuff........
rxFinished = false;
}
}
return 0 ;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks for the help in advance.
Regards,
Sean