How to use Uart1 communication in JN-AN-1229

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

How to use Uart1 communication in JN-AN-1229

1,214 Views
377086561
Contributor II

I ported the uart.c and uart.h files of JN-AN-1216 to my JN-AN-1229.、Of course, I am using a sleeping end device.

pastedImage_1.png

After I initialized

pastedImage_2.png

But when I call the interface for reading and writing, the device teacher restarts.

I want to ask, how to use reading and writing, it is safer and more convenient. Can you give me a simple code as a reference? And do you have to interrupt processing when reading or writing? Thank you, I hope I can reply to you as soon as possible!mario_castaneda

Labels (2)
0 Kudos
9 Replies

983 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi, I hope you're doing well!

 

To enable functionality for UART 1, you'll need to initialize it first. You can use the function you show in your post, however, you'll have to make sure the macros used are correct for UART 1. When enabling it, you should also consider the pin locations for UART1, as well as baud rate and other configurations specifically for this peripheral.

 

You'll also have to define interrupt priority for UART1, in the PIC SwVectTable in the irq file of your project.

 

For reference, you could check the JN-AN-1069 Application Note, here. This Application Note enables an additional UART for communication.

 

Please let me know if that works.

 

Best regards,

Sebastian

0 Kudos

983 Views
377086561
Contributor II

Hi Sebastian,

thank you for your reply.

I added an interrupt and opened the interrupt

pastedImage_1.png

/*open interrupt*/
OS_eEnableAllInterrupts();
0 Kudos

983 Views
377086561
Contributor II

Interrupt function

OS_ISR(APP_isrUart)
{
unsigned int irq = ((*((volatile uint32 *)(UART_START_ADR + 0x08))) >> 1) & 0x0007;
uint8 u8Byte;

if (irq & E_AHI_UART_INT_RXDATA)
{
uint8 u8Byte = u8AHI_UartReadData(UART);
OS_ePostMessage(APP_msgSerialRx, &u8Byte);
DBG_vPrintf(TRACE_APP, "APP_isrUart %d\n",u8Byte);
}

if (irq & E_AHI_UART_INT_TX)
{
if (OS_E_OK == OS_eCollectMessage(APP_msgSerialTx, &u8Byte))
{
UART_vSetTxInterrupt(TRUE);
vAHI_UartWriteData(UART, u8Byte);
/* decrement activity counter for dequeued data */
PWRM_eFinishActivity();
}
else
{
/* disable tx interrupt as nothing to send */
UART_vSetTxInterrupt(FALSE);
}
}
}

But now I don't know how to send data and receive data to Uart1. I used the following method, but it doesn't seem to work.

pastedImage_1.png

Can you tell me where is the problem? And how to send and receive correctly!thanks

0 Kudos

983 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi,

 

If you want to enable trace, you'll have to look for the macro in the makefile and change it to 1 so it get's enabled, however, if the UART you'll have to change the debug UART if it's already being used for another purpose.

 

Could you please try changing that and see if you get trace information?

 

Please let me know of your findings.

 

Best regards,

Sebastian

0 Kudos

983 Views
377086561
Contributor II

Can you tell me how to communicate well when I wake up? Just like ZPS_eAplZdoPoll() to round the training to get the data

0 Kudos

983 Views
377086561
Contributor II

Yes,

In the makefile, enabled the 

CFLAGS += -DUART=1

CFLAGS += -DDBG_ENABLE

add the APPSRC += uart.c

I can communicate now, but when the terminal device enters sleep mode, it can't accept data and send data. Can you give me a solution?

0 Kudos

983 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi,

 

When the device enters sleep mode, it cannot receive data. This data will be asked for when the device wakes up from sleep, this can be done by the polling method, so that each time the device wakes up, it asks its parent for the data.

 

For information polling, you can check how the JN-AN-1229 does it, as it shows the process for when the device wakes up, asks for new information, and then goes back to sleep for the duration of the specified SLEEP_TIME, so it can then wake up and ask again for information. The ZPS_eAplZdoPoll function is used to perform this polling, and the parent device should know how to handle this data request.

 

Best regards,

Sebastian

0 Kudos

983 Views
377086561
Contributor II

Sorry, I am asking about UART1 communication. When I want to wake up, I want to request data like a information  polling.

0 Kudos

983 Views
Sebastian_Del_Rio
NXP Employee
NXP Employee

Hi,

 

The communication via UART has to be done when the device is running its wake-up routine. You could implement a UART polling method in this routine, asking for the information contained in the UART buffer, however, this implementation might not be the best, as you could lose information if the buffer is rewritten more than once during the device's sleep mode. You could use the UART_bGetChar function to read the contents of the receive buffer of the UART.

 

Please let me know if this works for you.

 

Best regards,

Sebastian

0 Kudos