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.
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
hii
updating the code not resolved issue.
same problem.
problem ask to second rplay.
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