Hi Johan :smileyhappy:,
I assume that the serial communication will be via J11 connector (pins - PTC6, PTC7) of the R41Z evaluation board.
Considering that on the USB connection, you already have a shell communication (THREAD_USE_SHELL define enabled), the easiest way is to switch from USB connection to J11 connector. This could be done by updating the Board_InitLPUART (pin_mux.c file) function like below:
void BOARD_InitLPUART(void)
{
CLOCK_EnableClock(kCLOCK_PortC); /* Port C Clock Gate Control: Clock enabled */
PORT_SetPinMux(PORTC, PIN6_IDX, kPORT_MuxAlt4); /* PORTC6 (pin 42) is configured as UART0_RX */
PORT_SetPinMux(PORTC, PIN7_IDX, kPORT_MuxAlt4); /* PORTC7 (pin 43) is configured as UART0_TX */
SIM->SOPT5 = ((SIM->SOPT5 &
(~(SIM_SOPT5_LPUART0RXSRC_MASK))) /* Mask bits to zero which are setting */
| SIM_SOPT5_LPUART0RXSRC(SOPT5_LPUART0RXSRC_LPUART_RX)
);
}
The shell module contains a list of commands located in shell_ip.c file (aShellCommands structure). You can update this structure by adding your command and registering a callback, something like:
const cmd_tbl_t aShellCommands[] =
{
....
{
"light", SHELL_CMD_MAX_ARGS, 0, SHELL_LightCb
#if SHELL_USE_HELP
,"Light Commands",
"Commands for Light \r\n"
" light state changed\r\n"
#endif /* SHELL_USE_HELP */
#if SHELL_USE_AUTO_COMPLETE
,NULL
#endif /* SHELL_USE_AUTO_COMPLETE */
},
...
}
where SHELL_LightCb looks like:
static int8_t SHELL_LightCb ( uint8_t argc, char *argv[] )
{
if(!strcmp(argv[1], "state"))
{
if(!strcmp(argv[2], "changed"))
{
/* put you code here to handle the event */
}
}
}
If you are using a baud rate of 9600, we will have to set the same on KW41. This could be done by updating mFsciSerials structure (from app_init.c) -> .baudrate = gUARTBaudRate9600_c,
Please consider that by default, from our stack, will be also some data events sent from KW41 via shell interface (like some status events - "joining..., node joined ..."-). You can handle or drop these events on the second microcontroller (the one with touch display associated).
The second approach is to init a second uart interface. My recommendation is to look at UART_Adapter.c file. This file contains the API required for initializing and controlling the UART instance.
Regards,
Ovidiu