0

I am trying to implement a circular buffer, I'm writing to it just fine, all the received data is there, but something about my function to read from it doesn't work. No data gets saved into MtoHSdata.

The data I'm trying to read has a Start (>) and End (<) symbol, and is supposed to be sent via USART1.

Read data function:

void MtoHS(struct remoteM *Buff)
{
    BYTE k = 0;

    static BYTE st = 1;

    switch (st)
    {
    case 1:
    {
        if ((*Buff).wr != (*Buff).re)
        {
            (*Buff).re = ((*Buff).re + 1) % (*Buff).max;

            if ((*Buff).Buffer[(*Buff).re] == '>')          // > == Start Symbol
            {
                k = 0;
                MtoHSdata[k] = (*Buff).Buffer[(*Buff).re];
            }
            else if ((*Buff).Buffer[(*Buff).re] == '<')     // < == End Symbol
            {
                MtoHSdata[k] = (*Buff).Buffer[(*Buff).re];
                st = 5;
            }
            else
            {
                MtoHSdata[k] = (*Buff).Buffer[(*Buff).re];  // Data
                k++;
            }
        }
    }
        break;
    /* When End Symbol was read, send data to M */
    case 5:
    {
        BYTE i = 0;

        while (MtoHSdata[i] != '<')
        {
            USART_SendData(USART1, MtoHSdata[i]);
            i++;
        }
    }
        break;

    default:
    {
        st = 1;
    }

    }
    return;
}

Write data function (interrupt):

void USART1_IRQHandler(void)
{
    if (USART_GetFlagStatus(USART1, USART_FLAG_RXNE) != RESET)
    {
        uint16_t byteM = 0;

        USART_GetITStatus(USART1, USART_IT_ORE);

        byteM = USART_ReceiveData(USART1);

        pRXD5->Buffer[pRXD5->wr] = byteM;
        pRXD5->wr = (pRXD5->wr + 1) % pRXD5->max;
    }
    return;
}

I'm calling MtoHS function with the parameter 'pRXD5'.

Could anyone please tell me what I'm doing wrong?

glts
  • 21,808
  • 12
  • 73
  • 94
Kater
  • 63
  • 10

0 Answers0