GETCHAR() non blocking?

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

GETCHAR() non blocking?

Jump to solution
2,623 Views
dougbaker
Contributor III

Is there a function that gets a char from the RS232 port like GETCHAR() that's non blocking?  I'm using a KL17 and SDK 2.0.  I would like to get char from the debug port if if there is one in the buffer but if there's not a char there I would like to not block and continue.

Thanks,

Doug

0 Kudos
1 Solution
1,992 Views
dougbaker
Contributor III

If this helps anyone, here is some code that does what I am looking for:

#define LPUART0_DATA    0x4005400C  //Address of the data register for the LPUART on the KL17 
#define HW_REG_32(addr) (*((volatile unsigned long *) (addr))) //a macro to access the register or any 32 bit register.
unsigned int reg32; //a place to put the register reading

reg32 =    HW_REG_32(LPUART0_DATA);   //Read the register (non blocking)
if(!(reg32 & 0x1000)) // look at the bit "receive Buffer Empty" from the register at address 0x4005400C
{
       ch = (reg32 & 0xff);  //mask off what's not needed.
       PRINTF("got a char %c\r\n", ch);
}

Doug

View solution in original post

0 Kudos
3 Replies
1,992 Views
dougbaker
Contributor III

GETCHAR() is blocking. 

I want to use a call that's non blocking so the main can do other things.  Since I am not running an RTOS, if I do a blocking call in main, nothing else will run in main unless I enter a char.

Here is an example of what I am looking for:

C Board 

0 Kudos
1,993 Views
dougbaker
Contributor III

If this helps anyone, here is some code that does what I am looking for:

#define LPUART0_DATA    0x4005400C  //Address of the data register for the LPUART on the KL17 
#define HW_REG_32(addr) (*((volatile unsigned long *) (addr))) //a macro to access the register or any 32 bit register.
unsigned int reg32; //a place to put the register reading

reg32 =    HW_REG_32(LPUART0_DATA);   //Read the register (non blocking)
if(!(reg32 & 0x1000)) // look at the bit "receive Buffer Empty" from the register at address 0x4005400C
{
       ch = (reg32 & 0xff);  //mask off what's not needed.
       PRINTF("got a char %c\r\n", ch);
}

Doug

0 Kudos
1,992 Views
danielchen
NXP TechSupport
NXP TechSupport

Hi Doug :

Please refer to the GETCHAR usage from the hello world example,

SDK_2.0_MKL17Z256xxx4\boards\frdmkl43z\demo_apps\hello_world

int main(void)
{
    char ch;

    /* Init board hardware. */
    BOARD_InitPins();
    BOARD_BootClockRUN();
    BOARD_InitDebugConsole();

    PRINTF("hello world.\r\n");

    while (1)
    {
        ch = GETCHAR();
        PUTCHAR(ch);
    }
}

Please also check the Kinetis SDK API Reference Manual for more details.

Chater 32. Debug console


Have a great day,
Daniel

-----------------------------------------------------------------------------------------------------------------------
Note: If this post answers your question, please click the Correct Answer button. Thank you!
-----------------------------------------------------------------------------------------------------------------------

0 Kudos