AnsweredAssumed Answered

Using UART to communicate with another board

Question asked by johanandrade on Mar 19, 2018
Latest reply on Mar 29, 2018 by johanandrade

Hey support,

 

Looking to see if someone can point me in the right direction. I have another board that is writing a message via UART when pressing a toggle button on a touchscreen.

 

The function in this board looks like this with the bold lines related to UART sent message:

void homeView::lightToggled()
{
bool new_state = lightSwitch.getState();
uint8_t Message[]="light state changed \n\r";

touchgfx_printf("lightToggled: %d\n", new_state);

g_sf_comms0.p_api->write(g_sf_comms0.p_ctrl, Message,sizeof(Message),5);

//inform Model through presenter
presenter->lightToggled(new_state);
}

 

I'm now trying to apply this to the R41Z board (based on KW41Z) to receive this message and trigger an event to turn on an LED remotely that is connected to another R41Z board.

 

At the moment the R41Z board can turn on/off this LED remotely via the SW4 button.

 

static void APP_AppModeHandleKeyboard
(
uint32_t keyEvent
)
{
switch(keyEvent)
{
case gKBD_EventPB1_c:
/* Data sink create */
(void)NWKU_SendMsg(APP_SendDataSinkCreate, NULL, mpAppThreadMsgQueue);
break;
#if gKBD_KeysCount_c > 1
case gKBD_EventPB2_c:
/* Report temperature */
//(void)NWKU_SendMsg(APP_ReportTemp, NULL, mpAppThreadMsgQueue);
//(void)NWKU_SendMsg(APP_SendExtLedOff, NULL, mpAppThreadMsgQueue);
{
/* Open the damper remotely */
static bool_t isDamperOn = FALSE;
if(isDamperOn) {
(void)NWKU_SendMsg(APP_SendDamperStop, NULL, mpAppThreadMsgQueue);
isDamperOn = FALSE;
} else {
(void)NWKU_SendMsg(APP_SendDamperOpen, NULL, mpAppThreadMsgQueue);
isDamperOn = TRUE;
}
}
break;
case gKBD_EventPB3_c:
/* Remote led RGB - on */
//(void)NWKU_SendMsg(APP_SendLedRgbOn, NULL, mpAppThreadMsgQueue);
//(void)NWKU_SendMsg(APP_SendExtLedOn, NULL, mpAppThreadMsgQueue);
{
/* toggle external LED on/off with same SW4 */
static bool_t isLedOn = FALSE;
if(isLedOn){
(void)NWKU_SendMsg(APP_SendExtLedOff, NULL, mpAppThreadMsgQueue);
isLedOn = FALSE;
} else {
(void)NWKU_SendMsg(APP_SendExtLedOn, NULL, mpAppThreadMsgQueue);
isLedOn = TRUE;
}
}
break;

 

I see that the project (frdmkw41z_wireless_examples_thread_router_eligible_device) has several UART files and functions included already (fsl_lpuart, UART_Adapter, etc.). Which functions should I be using to setup the UART? Do I set it to use the same baudrate as my other device (9600)? Would this serial operation be completely separate from static void APP_AppModeHandleKeyboard? Thanks!

Outcomes