Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm using USART for RS232 communication and I'm receiving only two characters of whatever I send through RS232 port I'm not sure what's the problem ,please help me guys,....

What I have tried:

C++
void ism_rs232_handler(void)
{	
	 uint32_t readBuffer;
	 uint32_t readStatus;
	
	puts("\r\n Inside RS232 Handler \r\n");
	
		readStatus = usart_get_status(RS232_USART);		
		if (readStatus & US_CSR_RXRDY)
		{					
			uint8_t ret = usart_read1(RS232_USART, (uint8_t *)&readBuffer);
			{
				gv_rs232RespData[gv_rs232Count++] = readBuffer;
			}		
			printf("\r\n String = %s \r\n",gv_rs232RespData);
			
			// Once the expected bytes are received raise the flag
				if(gv_rs232Count > 3)
				{
					gv_rs232RcvFlag = true;
				}	

		}		



}
uint32_t usart_read1(Usart *p_usart, uint8_t *puc_data)
{
	/* Check if the receiver is ready */
	if ((p_usart->US_CSR & US_CSR_RXRDY) == 0)
	return 1;

	/* Read character */
	*puc_data = (uint8_t) p_usart->US_RHR & US_RHR_RXCHR_Msk;

	return 0;
}


These are the two functions I'm using I'm not sure what's the problem any suggestions?
Posted
Updated 1-Aug-22 2:50am
v2
Comments
Richard MacCutchan 1-Aug-22 3:50am    
You need to use your debugger to find out what is happening. The issue is specific to the device you are trying to read from.
jeron1 1-Aug-22 10:50am    
You're returning a a value from usart_read1() but not using it. If you are using interrupts, does the interrupt flag need to be cleared manually, so it can fire again? How deep is the UART buffer?

1 solution

My best guess is that you missed some multithreading, so the COM port has no time to receive more data.
Best is to use some own reading thread which enques the data for the main UI thread. Collect the data til some packet is complete and than comsume it.

Best is to read the this articel about Serial library for C++ to better understand the architectural challenges.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900