Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not able to send/receive proper data from UART driver #5

Open
koratshail opened this issue Jul 22, 2019 · 13 comments
Open

Not able to send/receive proper data from UART driver #5

koratshail opened this issue Jul 22, 2019 · 13 comments

Comments

@koratshail
Copy link

koratshail commented Jul 22, 2019

Hi @yachen ,
We are working on Nuvoton NUC472 and taken BSP version: 3.03.000 (Downloaded from https://github.com/OpenNuvoton/NUC472_442BSP) as per our project requirement.
We are using Tool-chain Version : arm-none-eabi-gcc (GNU Tools for ARM Embedded Processors 6-2017-q2-update) 6.3.1 20170620 (release).

I am using UART at 9600 Baudrate communication mode for transferring data between two devices. For this, I have taken reference code from below sample driver code provided in BSP.
https://github.com/OpenNuvoton/NUC472_442BSP/blob/master/SampleCode/StdDriver/UART_TxRx_Function/main.c

The problem we are facing is we are getting only 16 Bytes to be received over debug console and not getting remaining bytes means data is not exchanging properly over 16 bytes.
We have checked the return value of UART_Write() which gives a maximum 16 bytes even if we give string more than 16 bytes.

@yachen
We have also tried your suggestion as per given in below link.
https://github.com/OpenNuvoton/NUC472_442BSP/issues/3
For example,
while (remain) { local_size = UART_Write((UART_T *)(UART_BASE + uart * (UART_OFFSET)),src, remain); src += local_size; remain -= local_size; }

But Still, we are facing communication error on the UART interface.
We have shown some other Nuvoton BSP's like M2351/ NUC121_125/M480 and shown that only NUC472 has different UART_write and UART_read code and all others have the same definition. Link for NUC472, M2351, NUC121_125, M480 UART driver provided below.
https://github.com/OpenNuvoton/NUC472_442BSP/blob/master/Library/StdDriver/src/uart.c
https://github.com/OpenNuvoton/M2351BSP/blob/master/Library/StdDriver/src/uart.c
[https://github.com/OpenNuvoton/NUC121_125BSP/blob/master/Library/StdDriver/src/uart.c]
(url)
https://github.com/OpenNuvoton/M480BSP/blob/master/Library/StdDriver/src/uart.c
If we tried M480/NUC121_125, M2351 solution then UART driver is working fine for us.
Is this genuine bug in NUC472 UART driver?
Why UART driver is different than this other Nuvoton variants?

@yachen
Copy link

yachen commented Jul 22, 2019

Hi @koratshail,

The difference between NUC472 and M480 UART driver is NUC472 write function return if UART FIFO is full while other drivers adds a big retry loop so the write function will actually return until all data are sent.

What communication error are you seeing after added the remain count check?

Sincerely,

Yi-An Chen

@koratshail
Copy link
Author

koratshail commented Jul 22, 2019

@yachen Thanks for quick replay.

I am testing UART interface with two Nuvton custom board which are communicating with each other.

What I mean to say communication error is that when one board sends data to other board then we have shown data corruption on receiving end with existing UART driver as well as with adding remain count logic.

If we add that delay logic, for example, if(u32delayno >= 0x40000000ul) which is given in other drivers then communication working fine.

Should we change UART driver for write and read call as written for other chipsets?

@yachen
Copy link

yachen commented Jul 22, 2019

Hi @koratshail ,

We'll check what may goes wrong w.o. the big loop. At the meantime, you can add the delay loop to your driver and develop/test other feature of your system. Thanks.

Sincerely,

Yi-An Chen

@koratshail
Copy link
Author

koratshail commented Jul 22, 2019

Thanks. @yachen
Your help will be really appreciated.

Sincerely,
Shailesh Korat

@yachen
Copy link

yachen commented Jul 22, 2019

Hi @koratshail ,

One question, how do you trigger Rx function? By interrupt?

Sincerely,

Yi-An Chen

@koratshail
Copy link
Author

Dear @yachen,
Yes, Whenever data comes into RX line of UART interface, Interrupt subroutine is called.
For transmission of data from UART, No need to wait for any Interrupt.

@mjchen1
Copy link
Contributor

mjchen1 commented Jul 24, 2019

Hi @koratshail,

Do you have printf any message in interrupt handle?
If yes, please remove them, like as below

image

@koratshail
Copy link
Author

@yachen ,
By default, printf function is not working in SDK. Thus, we are not using it.
For debugging purpose, we have made our own printf_degug function on other UART.

@mjchen1
Copy link
Contributor

mjchen1 commented Jul 25, 2019

main.zip

Hi @koratshail,
I write a sample code to test tx/rx function.
and the result look like ok.
In my test code.
You can select do tx test or rx test.
Of course, you can choose one test board to select the tx test and the other test board to select the rx test. Then, communicate between the two test boards.
The select method and test result show as below.

image

image

@koratshail
Copy link
Author

koratshail commented Jul 26, 2019

@yachen . Thanks for helping us.

Can you please look into below ISR code? I think something is different than your example.
Is this right way to read data from UART ISR?

void user_uart_handler(uint8_t uart_num)
{
	NVIC_DisableIRQ(UART_IRQ_OFFSET + uart_num);
	uint8_t u8InChar = 0xFF;
	UART_T *uart = (UART_T *)(UART_BASE + uart_num * (UART_OFFSET));
	uint32_t u32IntSts;
	u32IntSts = uart->INTSTS;

	**if (u32IntSts & UART_INTSTS_RDAINT_Msk)** {
		**while (UART_IS_RX_READY(uart))** {
			/* Get the character from UART Buffer */
			u8InChar = UART_READ(uart); 
			DEBUG_LOGD(UART, TAG1, "UART %d data : %c", uart_num, u8InChar);
		}
	}
	NVIC_EnableIRQ(UART_IRQ_OFFSET + uart_num);
}

@mjchen1
Copy link
Contributor

mjchen1 commented Jul 26, 2019

Hi @koratshail,
maybe you can remove print debug message(DEBUG_LOGD(UART, TAG1, "UART %d data : %c", uart_num, u8InChar);) .
then try again.

@koratshail
Copy link
Author

koratshail commented Jul 26, 2019

Forgot to say that it will not print any data. It will there only understanding purpose.
I am asking about below lines those are different from your code.
We have : if (u32IntSts & UART_INTSTS_RDAINT_Msk) {
You have : if((u32IntSts & UART_INTSTS_RDAINT_Msk) || (u32IntSts & UART_INTSTS_RXTOINT_Msk))

We have : while (UART_IS_RX_READY(uart))
You have: while(!(UART1->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk))

do we do the right things in code?

@mjchen1
Copy link
Contributor

mjchen1 commented Jul 26, 2019

you can change to
if((u32IntSts & UART_INTSTS_RDAINT_Msk) || (u32IntSts & UART_INTSTS_RXTOINT_Msk))
and
while(!(UART1->FIFOSTS & UART_FIFOSTS_RXEMPTY_Msk))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants