lpc55s16 USART data read related issue

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

lpc55s16 USART data read related issue

2,539 次查看
firmwareteam
Contributor I

i am using lpc55s16 usart interrupt sample code .lpc55s16 next side another device  transmit data in this code i can read 32 bytes and same time another 32 bytes data read 9times loop ran then full completed 258 byte data correct and i want to read more than 258 bytes read but at singles times loop.

attach screenshot(83) read data 32 byte and 9loop full completed .

data in 1 singel loop 258 byte data read?

screenshot singels 32 bytes data read ss

how to change in usart code.

usart data read function.

bool usart_Read(uint8_t* b) {
 
 
    if ((kUSART_RxFifoNotEmptyFlag  ) & USART_GetStatusFlags(USART1))
      {
          *b = USART_ReadByte(USART1);
           return true;
      }
   else
     {
    return false;
     }
}
 
 
9times loop ran then full completed 258 byte data.
case STEP_READ_LEN: /* Read length byte */
case STEP_READ_LEN:
if (usart_Read(&re->len)) {
 
 
return STEP_READ_DATA;
}
break;
 
case STEP_READ_DATA:
if (re->pos < re->len) {
 
 
if (usart_Read(&(re->data[re->pos]))) {
re->pos++;
}
}
0 项奖励
回复
5 回复数

2,500 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @firmwareteam 

If you want to read 258 bytes in a single loop iteration instead of 9 iterations of 32 bytes each, you need to modify your USART interrupt handling.

You can change the usart_Read.

int usart_Read(uint8_t* buf, int max_len) {
   int bytesRead = 0;
   while ((kUSART_RxFifoNotEmptyFlag) & USART_GetStatusFlags(USART1)) {
       if (bytesRead < max_len) {
           buf[bytesRead] = USART_ReadByte(USART1);
           bytesRead++;
       } else {
           break; // Stop reading if buffer is full
       }
   }
   return bytesRead; // Return the number of bytes read
}

And you can update the STEP_READ_DATA case

case STEP_READ_DATA:
   if (re->pos < re->len) {
       int bytesReceived = usart_Read(&(re->data[re->pos]), re->len - re->pos);
       re->pos += bytesReceived;
       // If all 258 bytes are received in one loop, exit
       if (re->pos >= re->len) {
           return STEP_PROCESS_DATA;  // Proceed to process data
       }
   }
   break;

 

BR

Harry

0 项奖励
回复

2,494 次查看
firmwareteam
Contributor I

Hiii

update the STEP_READ_DATA case and change the usart_Read function.

same problem read data not change,32 bytes data read 9times loop ran then full completed 258 byte data.

0 项奖励
回复

2,418 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @firmwareteam 

May I ask if updating the code has resolved your issue?

BR

Harry

0 项奖励
回复

2,413 次查看
firmwareteam
Contributor I

hii

updating the code not resolved issue.

same problem.

problem ask to second rplay.

0 项奖励
回复

2,366 次查看
Harry_Zhang
NXP Employee
NXP Employee

Hi @firmwareteam 

To read more than 258 bytes in a single loop, I rewrote the relevant code.

#define DEMO_BUFFER_SIZE          512  
#define DATA_TO_RECEIVE           258  
.....
uint8_t rxBuffer[DEMO_BUFFER_SIZE];
volatile uint16_t rxCount = 0;
volatile bool dataReceived = false;

void DEMO_USART_IRQHandler(void)
{
   uint8_t data;
   if ((kUSART_RxFifoNotEmptyFlag | kUSART_RxError) & USART_GetStatusFlags(DEMO_USART))
   {
       data = USART_ReadByte(DEMO_USART);
       if (rxCount < DATA_TO_RECEIVE) // Store only up to the required amount
       {
           rxBuffer[rxCount++] = data;
           if (rxCount >= DATA_TO_RECEIVE)
           {
               dataReceived = true;  // Signal that required data has been received
           }
       }
   }

   SDK_ISR_EXIT_BARRIER;
}

.....

int main(void)
{

....

   while (1)
   {
       if (dataReceived)
       {
           /* Process received data */
           USART_WriteBlocking(DEMO_USART, rxBuffer, rxCount);  // Echo received data
           rxCount = 0;  // Reset counter
           dataReceived = false;  // Reset flag
       }
   }
}  

 

BR

Harry

0 项奖励
回复