This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Not storing the data from SBUF

Hi MCU is recieving the data from other MCU& i am unable to store the data using SBUF..so pls help me.. only the last byte is receiving again & again...

thanks

here my source code

p = 0; for(i1=0;i1<448;i1++) ser_buf[i1]=SBUF;

for(i2=0;i2<8;i2++) { for(i1=0;i1<48;i1++) prt_buf[i1] = 0; for(i1 = 0;i1<48;i1++) prt_buf[i1] =ser_buf[p++];

print_graph();

}

Parents
  • Hi,

    your data incoming is asynchronous, so you cannot read it like your code intended.
    Try a interrupt driven storage of your data in a buffer like a FIFO. You need to check the serial receive flag RI to react on incoming data.

    example

    #define         ROLLOVERINCREMENT( x, max )     x = ++x >= max ? 0 : x++
    
    static char g_Uart0RxBuffer[UART_RecieveBufferSize];
    
    void ISR_UART0(void) interrupt SI0_VECTOR
    {
            if(RI == 1)
            {
                    RI = 0;
                    g_Uart0RxBuffer[g_Uart0RxPositionIn] = SBUF;
                    ROLLOVERINCREMENT(g_Uart0RxPositionIn, UART_RecieveBufferSize);
            }
    }
    

    Greetings,
    David

Reply
  • Hi,

    your data incoming is asynchronous, so you cannot read it like your code intended.
    Try a interrupt driven storage of your data in a buffer like a FIFO. You need to check the serial receive flag RI to react on incoming data.

    example

    #define         ROLLOVERINCREMENT( x, max )     x = ++x >= max ? 0 : x++
    
    static char g_Uart0RxBuffer[UART_RecieveBufferSize];
    
    void ISR_UART0(void) interrupt SI0_VECTOR
    {
            if(RI == 1)
            {
                    RI = 0;
                    g_Uart0RxBuffer[g_Uart0RxPositionIn] = SBUF;
                    ROLLOVERINCREMENT(g_Uart0RxPositionIn, UART_RecieveBufferSize);
            }
    }
    

    Greetings,
    David

Children