KV31P128 UART RDRF Flag

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

KV31P128 UART RDRF Flag

1,153 Views
seanmccartan
Contributor II

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

Tags (1)
0 Kudos
Reply
2 Replies

854 Views
mjbcswitzerland
Specialist V


Hi Sean

This may be a debugging issue. If you step the code with a UART register view open it will read the data register at each step, and reset the receive flag in the process, so that any code checking this to decide to call a user function will then never see it.

Try repeating but after closing a the UART register view. Use the disassemble mode instead to see which values have been read from UART registers as the code steps (disassemble mode is more reliable than C source view since it won't optimise away variables and such that one would like to see).

Regards

Mark


Kinetis: http://www.utasker.com/kinetis.html
Kinetis KV31:
- http://www.utasker.com/kinetis/TWR-KV31F120M.html

FreeMaster: http://www.utasker.com/kinetis/FreeMASTER.html


Free Open Source solution: https://github.com/uTasker/uTasker-Kinetis
Working project in 15 minutes video: https://youtu.be/K8ScSgpgQ6M

Professional Kinetis support, one-on-one training and complete fast-track project solutions: http://www.utasker.com/support.html

0 Kudos
Reply

854 Views
seanmccartan
Contributor II

Hi Mark,

Thanks for the help, but unfortunately that doesn't seem to be the issue. I added some 'traps' into my 'callback' function and ran the application without any break points. Modified 'callback' function:

//-----------------------------------------------------------------------------------------------------------------------------------------------------------

   switch(status)
    {
        case kStatus_UART_TxBusy: ch = '1'; break;
        case kStatus_UART_RxBusy: ch = '2'; break;
        case kStatus_UART_TxIdle: ch = '3'; break;
        case kStatus_UART_RxIdle: ch = '4'; break;
        case kStatus_UART_TxWatermarkTooLarge: ch = '5'; break;
        case kStatus_UART_RxWatermarkTooLarge: ch = '6'; break;
        case kStatus_UART_FlagCannotClearManually: ch = '7'; break;
        case kStatus_UART_Error: ch = '8'; break;
        case kStatus_UART_RxRingBufferOverrun: ch = '9'; break;
        case kStatus_UART_RxHardwareOverrun: ch = 'A'; break;
        case kStatus_UART_NoiseError: ch = 'B'; break;
        case kStatus_UART_FramingError: ch = 'C'; break;
        case kStatus_UART_ParityError: ch = 'D'; break;
        case kStatus_UART_BaudrateNotSupport: ch = 'E'; break;
        default: ch = 'F'; break;
    }
    UART_WriteBlocking(UART1, &ch, 1);

//-----------------------------------------------------------------------------------------------------------------------------------------------------------

The results were as follows:

UART0<CR><LF>

3

The '3' Indicates the UART TX status returning to IDLE after transmitting - expected result.

I then sent individual bytes (0xAA): After sending the 9th byte I received the character 'A'  indicting a UART RX Hardware Overrun error status. 8 byte receive buffer in UART0?

I then switched to using UART 1 and received the same results as above, except that I received the 'A' character after sending only 2 bytes.

Regards,

Sean

0 Kudos
Reply