Hello,
I want to send a data through uart communication and see it in a terminal on my computer.
How can I do this? What functions of uart communication should I use?
I will use the same windows terminal program to view the sent data.
Thank you!
This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hello,
I want to send a data through uart communication and see it in a terminal on my computer.
How can I do this? What functions of uart communication should I use?
I will use the same windows terminal program to view the sent data.
Thank you!
Hello, thank you very much.
I have a few more questions.
1- Just setting hal_uart to true and using the function HalUARTWrite with the parameters already can send the data?
2- Can I have the code I develop in the Genericapp.c part?
3- Where can I find documents for APIs and functions such as HalUARTWrite, for example?
Thank you
If HAL_UART is defined and set to TRUE then HalUARTInit is automatically called from HalDriverInit, which then leads to UART1 being initialized on PA1/TX and PA0/RX. You still have to call HalUARTOpen to initialize the UART1 peripheral itself (if not using MT). There shouldn't be any issues when integrating with your application. Please refer to SWRA193 for the HAL Drivers API, the functions can be found in C:\Texas Instruments\Z-Stack Mesh 1.0.0\Components\hal\target\CC2538\_hal_uart_isr.c
Regards,
Ryan
Hello!
Thank you very much
Now I'm going to start testing to see if it's working.
I just wanted to know what the above code snippet is for.
Hello!
I'm trying to send, but no data is being sent.
I put the function HalUARTWrite (HAL_UART_PORT_0, "ABCD", 8); in GenericApp_ProcessEvent().
Not sending because of message format? Or some misconfiguration?
Thank you!
I notice that you're opening UART1 and writing to UART0 so this is an immediate issue. This hardware will use PA1/TX and PA0/RX as default for UART1. If you define ZAPP_P1/P2 then HAL_UART_PORT_0/1, respectively, is initialized through MT control, MT_UartInit inside MT_UART.c is a good reference. I also recommend evaluating Z-Stack 3.0 as compared to an archived stack.
Regards,
Ryan
And yet based on your hardware initialization you may need to use UART1, this is the case for HalUARTInitIsr by default. Probing the communication lines will help with debugging.
Regards,
Ryan
Hi Ryan!
Yes, I'm using a SmartRF voltage divider for the Arduino.
So the arduino should not be receiving because the voltage is too low?
How do I know if smartRF is sending?
Thank you!
Hugs.
Okay. But even without the pin it is not sending. I wonder why?
Below are the codes that I modified and the preprocessor suddenly has something wrong.
Thank you!
My GenericApp_Init:
void GenericApp_Init( uint8 task_id )
{
GenericApp_TaskID = task_id;
GenericApp_NwkState = DEV_INIT;
GenericApp_TransID = 0;
// Device hardware initialization can be added here or in main() (Zmain.c).
// If the hardware is application specific - add it here.
// If the hardware is other parts of the device add it in main().
GenericApp_DstAddr.addrMode = (afAddrMode_t)AddrNotPresent;
GenericApp_DstAddr.endPoint = 0;
GenericApp_DstAddr.addr.shortAddr = 0;
// Fill out the endpoint description.
GenericApp_epDesc.endPoint = GENERICAPP_ENDPOINT;
GenericApp_epDesc.task_id = &GenericApp_TaskID;
GenericApp_epDesc.simpleDesc
= (SimpleDescriptionFormat_t *)&GenericApp_SimpleDesc;
GenericApp_epDesc.latencyReq = noLatencyReqs;
// Register the endpoint description with the AF
afRegister( &GenericApp_epDesc );
// Register for all key events - This app will handle all key events
RegisterForKeys( GenericApp_TaskID );
// Update the display
#if defined ( LCD_SUPPORTED )
HalLcdWriteString( "GenericApp", HAL_LCD_LINE_1 );
#endif
ZDO_RegisterForZDOMsg( GenericApp_TaskID, End_Device_Bind_rsp );
ZDO_RegisterForZDOMsg( GenericApp_TaskID, Match_Desc_rsp );
ZDO_RegisterForZDOMsg(GenericApp_TaskID, Device_annce); // busca ieee do enddevice
ZDO_RegisterForZDOMsg(GenericApp_TaskID, Mgmt_Leave_rsp);
#if defined( IAR_ARMCM3_LM )
// Register this task with RTOS task initiator
RTOS_RegisterApp( task_id, GENERICAPP_RTOS_MSG_EVT );
#endif
/* uart configuration*/
halUARTCfg_t uartConfig;
uartConfig.configured = TRUE;
uartConfig.baudRate = HAL_UART_BR_115200;
uartConfig.flowControl = FALSE;
uartConfig.flowControlThreshold = 48;
uartConfig.rx.maxBufSize = 128;
uartConfig.tx.maxBufSize = 128;
uartConfig.idleTimeout = 6;
uartConfig.intEnable = TRUE;
uartConfig.callBackFunc = uart0RxCb;
HalUARTOpen (HAL_UART_PORT_0, &uartConfig);
}
My ProcessEvent:
uint16 GenericApp_ProcessEvent( uint8 task_id, uint16 events )
{
afIncomingMSGPacket_t *MSGpkt;
afDataConfirm_t *afDataConfirm;
// Data Confirmation message fields
byte sentEP;
ZStatus_t sentStatus;
byte sentTransID; // This should match the value sent
(void)task_id; // Intentionally unreferenced parameter
HalUARTWrite( HAL_UART_PORT_0, "UART0 output test", (byte)osal_strlen("UART0 output test"));
HalLedSet ( HAL_LED_4, HAL_LED_MODE_BLINK ); // Blink an LED
if ( events & SYS_EVENT_MSG )
{
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
while ( MSGpkt )
{
switch ( MSGpkt->hdr.event )
{
case ZDO_CB_MSG:
GenericApp_ProcessZDOMsgs( (zdoIncomingMsg_t *)MSGpkt );
break;
case KEY_CHANGE:
GenericApp_HandleKeys( ((keyChange_t *)MSGpkt)->state, ((keyChange_t *)MSGpkt)->keys );
break;
case AF_DATA_CONFIRM_CMD:
// This message is received as a confirmation of a data packet sent.
// The status is of ZStatus_t type [defined in ZComDef.h]
// The message fields are defined in AF.h
afDataConfirm = (afDataConfirm_t *)MSGpkt;
sentEP = afDataConfirm->endpoint;
(void)sentEP; // This info not used now
sentTransID = afDataConfirm->transID;
(void)sentTransID; // This info not used now
sentStatus = afDataConfirm->hdr.status;
// Action taken when confirmation is received.
if ( sentStatus != ZSuccess )
{
// The data wasn't delivered -- Do something
}
break;
case AF_INCOMING_MSG_CMD:
GenericApp_MessageMSGCB( MSGpkt );
break;
case ZDO_STATE_CHANGE:
GenericApp_NwkState = (devStates_t)(MSGpkt->hdr.status);
if ( (GenericApp_NwkState == DEV_ZB_COORD) ||
(GenericApp_NwkState == DEV_ROUTER) ||
(GenericApp_NwkState == DEV_END_DEVICE) )
{
// Start sending "the" message in a regular interval.
osal_start_timerEx( GenericApp_TaskID,
GENERICAPP_SEND_MSG_EVT,
txMsgDelay );
}
break;
default:
break;
}
// Release the memory
osal_msg_deallocate( (uint8 *)MSGpkt );
// Next
MSGpkt = (afIncomingMSGPacket_t *)osal_msg_receive( GenericApp_TaskID );
}
// return unprocessed events
return (events ^ SYS_EVENT_MSG);
}
// Send a message out - This event is generated by a timer
// (setup in GenericApp_Init()).
if ( events & GENERICAPP_SEND_MSG_EVT )
{
// Send "the" message
GenericApp_SendTheMessage();
// Setup to send message again
osal_start_timerEx( GenericApp_TaskID,
GENERICAPP_SEND_MSG_EVT,
txMsgDelay );
// return unprocessed events
return (events ^ GENERICAPP_SEND_MSG_EVT);
}
My GenericApp.c:
/* uart configuration*/
void uart0RxCb( uint8 port, uint8 event )
{
uint8 ch;
while (Hal_UART_RxBufLen(port))
{
// Read one byte from UART to ch
HalUARTRead (port, &ch, 1);
}
}
My preprocessor:
NV_RESTORE
FEATURE_RESET_MACRO
ewarm
ZTOOL_P1
MT_TASK
MT_SYS_FUNC
CC2538_USE_ALTERNATE_INTERRUPT_MAP=1
MT_ZDO_FUNC
LCD_SUPPORTED=DEBUG
HAL_UART=TRUE
Thank you!
I have not yet been able to send using the code I previously reported.
I used this example cc2538_foundation_firmware_1_0_1_0 that I found on the site, this example worked correctly.
So in the hardware part everything is correct, what I want to understand is because I am not able to send with the code that I have developed.
Thank you!
So if you have an interrupt function on the call function will it work?
Hello!
To use the interrupt, should I put some function in the callback function?
Or how do I have UART interrupt?
Thank you!
Interrupts are not necessary, YK explained callbacks at the beginning of this thread.
YiKai Chen said:You can implement your own UART RX callback like the followings.
void uart0RxCb( uint8 port, uint8 event )
{
uint8 ch;
while (Hal_UART_RxBufLen(port))
{
// Read one byte from UART to ch
HalUARTRead (port, &ch, 1);
}
}
Regards, Ryan