ISR Buffer is not working and controller is getting hang. Please, Help me out the problem is coming in ISR Buffer

#include<uart.h>
#include “mbed.h”
#include “stm32EEPROM.h”
#include “packets.h”
#define DB_RX PA_2
#define DB_TX PA_3
#define NU_RX PA_9
#define NU_TX PA_10
#define METER_ISR_BUFFER_SIZE 300
#define LTE_COMMAND_LENGTH 50
#define SOH ‘{’
#define ETX ‘}’

#define WAITING_FOR_START 0
#define WAITING_FOR_END 1

#define METER_PKT_SIZE 52

extern bool bDebug;

// Serial Comm (TXD, RXD)
Serial DbUart(DB_RX, DB_TX);
Serial NuUart(NU_RX, NU_TX);
Serial pc(PB_3, PB_4);

//Serial ports[3] = (pc, NuUart, DbUart);

//Initializing Debug Send flag bit for basic initialization
unsigned int DBUARTSendFlag = 0;
unsigned int NUUARTSendFlag = 0;
unsigned int PCSendFlag = 0;
uint8_t pktBufA[EEPROM_PKT_SIZE],pktBufB[EEPROM_PKT_SIZE],pktBufC[EEPROM_PKT_SIZE];
//Setting buffer index value as volatile for reinitializing when interrupt is comming
volatile uint16_t bufA_index = 0;
volatile uint16_t bufB_index = 0;
volatile uint16_t bufC_index = 0;
uint16_t bufA_outdex = 0;
uint16_t bufB_outdex = 0;
uint16_t bufC_outdex = 0;
//Setting buffer value which stored in this array.Basically, This array is changing time to time.
char buffer1[METER_ISR_BUFFER_SIZE];
char buffer2[METER_ISR_BUFFER_SIZE];
char buffer3[METER_ISR_BUFFER_SIZE];

//Serial_A Interrupt Function
void DBRxInterrupt(void)
{
while(DbUart.readable())
{
buffer1[bufA_index] = DbUart.getc();
bufA_index = (bufA_index+1) % METER_ISR_BUFFER_SIZE;
}
//DBUARTSendFlag = 1;
}

void NURxInterrupt(void)
{
while(NuUart.readable())
{
buffer2[bufB_index] = NuUart.getc();
bufB_index = (bufB_index+1) % METER_ISR_BUFFER_SIZE;
}
//NUUARTSendFlag = 1;
}

void PCRxInterrupt(void)
{
while(pc.readable())
{
buffer3[bufC_index] = pc.getc();
bufC_index = (bufC_index+1) % METER_ISR_BUFFER_SIZE;
}
//NUUARTSendFlag = 1;
}

void Init_PCUART(void)
{
pc.attach(&PCRxInterrupt, Serial::RxIrq);
pc.baud(9600);
}

void Init_DBUART(void)
{
DbUart.attach(&DBRxInterrupt, Serial::RxIrq);
DbUart.baud(9600);
}

void Init_NUUART(void)
{
NuUart.attach(&NURxInterrupt, Serial::RxIrq);
NuUart.baud(9600);
}

void checkForMeterPackets()
{

uint8_t c;
static uint8_t stringingStateA=WAITING_FOR_START;
static uint8_t stringingStateB=WAITING_FOR_START;
static uint8_t stringingStateC=WAITING_FOR_START;

static uint8_t stringingIndexA=0;
static uint8_t stringingIndexB=0;
static uint8_t stringingIndexC=0;

//This index value is testing for port1 data checking
while(bufA_outdex != bufA_index)
{
//if(bDebug) pc.printf("\rPacket is Here = %d\r",bufA_outdex);
c = (uint8_t)buffer1[bufA_outdex];
bufA_outdex = (bufA_outdex+1) % METER_ISR_BUFFER_SIZE;

    switch(stringingStateA)
    {
        case WAITING_FOR_START:
            if( c==SOH)
            {
                //if(bDebug) pc.printf("\rI am in Waiting for Start State:");
                
                stringingIndexA=0;
                pktBufA[stringingIndexA++] = c;
                stringingStateA = WAITING_FOR_END;
               // pc.putc(pktBufA[0]);
            }
            break;
            
        case WAITING_FOR_END:
            if( c == ETX)
            {
                
                pktBufA[stringingIndexA++] = c;
                //if(bDebug) pc.printf("\rI am in Waiting for End State: %d",stringingIndexA);
                if(stringingIndexA==METER_PKT_SIZE)
                {
                    if(bDebug) pc.printf("\rI got full packet = %s", pktBufA);
                    processMeterPacket(1, pktBufA);
                    stringingIndexA = 0;
                }
                else
                {
                    stringingStateA = WAITING_FOR_START;
                }
            }
            else if(stringingIndexA < METER_PKT_SIZE )
            {
                pktBufA[stringingIndexA++] = c;
            }
            else
            {
                stringingStateA = WAITING_FOR_START;
            }
            break;
            
        default:
            stringingStateA = WAITING_FOR_START;
            break;
    }
}

//This index value is testing for port2 data checking
while(bufB_outdex != bufB_index)
{
//if(bDebug) pc.printf("\rPacket is Here = %d\r",bufB_outdex);
c = (uint8_t)buffer2[bufB_outdex];
bufB_outdex = (bufB_outdex+1) % METER_ISR_BUFFER_SIZE;

    switch(stringingStateB)
    {
        case WAITING_FOR_START:
            if( c==SOH)
            {
                //if(bDebug) pc.printf("\rI am in Waiting for Start State:");
                
                stringingIndexB=0;
                pktBufB[stringingIndexB++] = c;
                stringingStateB=WAITING_FOR_END;
               //if(bDebug) pc.putc(pktBufA[0]);
            }
            break;
            
        case WAITING_FOR_END:
            if( c == ETX)
            {
                
                pktBufB[stringingIndexB++] = c;
                //if(bDebug) pc.printf("\rI am in Waiting for End State: %d",stringingIndexA);
                if(stringingIndexB == METER_PKT_SIZE)
                {
                    if(bDebug) pc.printf("\rI got full packet = %s", pktBufA);
                    processMeterPacket(2, pktBufB);
                    stringingIndexB = 0;
                }
                else
                {
                    stringingStateB = WAITING_FOR_START;
                }
            }
            else if(stringingIndexB < METER_PKT_SIZE )
            {
                pktBufB[stringingIndexB++] = c;
            }
            else
            {
                stringingStateB = WAITING_FOR_START;
            }
            break;
            
        default:
            stringingStateB = WAITING_FOR_START;
            break;
    }
}

//This index value is testing for port3 data checking
while(bufC_outdex != bufC_index)
{
//if(bDebug) pc.printf("\rPacket is Here = %d\r",bufC_outdex);
c = (uint8_t)buffer3[bufC_outdex];
bufC_outdex = (bufC_outdex+1) % METER_ISR_BUFFER_SIZE;

    switch(stringingStateC)
    {
        case WAITING_FOR_START:
            if(c == SOH)
            {
                //if(bDebug)  pc.printf("\rI am in Waiting for Start State:");
                
                stringingIndexC=0;
                pktBufC[stringingIndexC++] = c;
                stringingStateC = WAITING_FOR_END;
               //if(bDebug) pc.putc(pktBufA[0]);
            }
            break;
            
        case WAITING_FOR_END:
            if(c == ETX)
            {
                
                pktBufC[stringingIndexC++] = c;
                //if(bDebug) pc.printf("\rI am in Waiting for End State: %d",stringingIndexA);
                if(stringingIndexC==METER_PKT_SIZE)
                {
                    //if(bDebug) pc.printf("\rI got full packet = %s", pktBufA);
                    processMeterPacket(3, pktBufC);
                    stringingIndexC = 0;
                }
                else
                {
                    stringingStateC = WAITING_FOR_START;
                }
            }
            else if(stringingIndexC < METER_PKT_SIZE )
            {
                pktBufC[stringingIndexC++] = c;
            }
            else
            {
                stringingStateC = WAITING_FOR_START;
            }
            break;
            
        default:
            stringingStateC = WAITING_FOR_START;
            break;
    }
}
//repeat for buffer B

}

Hi Rajkumar,

Which platform and version of Mbed OS are you using? Use debugger to check which line cause hanging would help.

If you would like to do communication in ISR, you should use RawSerial, the documentation is here.

Regards,
Desmond

Hi Desmond,
I used RawSerial but it hangs my transmission also. And I am using online mbed os IDE. Can u suggest me more what exactly problem here.