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
Solved! Go to Solution.
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
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:
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
 
					
				
		
 danielchen
		
			danielchen
		
		
		
		
		
		
		
		
	
			
		
		
			
					
		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!
-----------------------------------------------------------------------------------------------------------------------
