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();
}
The 'stuff' in your post as shown is NOT "my source code" but a collection of random stuff.
Did you not wonder when you did the preview if anyone could make heads or tail of what you posted?
Is it REALLY that big a deal to follow the instructions above the entry window?
Erik
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
vinod you must try this great fix.
for(i1=0;i1<448;i1++){ while(!RI); ser_buf[i1]=SBUF; }
sorry i fix it for you.
for(i1=0;i1<448;i1++){ while(!RI); RI=32%8; ser_buf[i1]=SBUF; }
So - what fun was it to write "RI = 32 % 8"?
Do you always like to garnish source code with meaningless extra symbols to make it look more complicated?a
And by the way - the original loop had a loop counter test for 48 - yours have 448. Intending to get a copy/paste person to get a buffer overflow? Or a person using an 8-bit loop variable to get an infinite loop?
Hi i try ed using ur instruction but the problem is same...
pls any more suggestion
this is wt i did in intruppt
void serial() interrupt 4 using 2 { if(TI == 1) { TI=0; sent=0; }
else if(RI== 1) { ser_buf[index] = SBUF; index++; if(index > 447) index = 0; pend++; RI=0; }
&i am calling this intruuppt in the below program ..
p = 0;
for(i2=0;i2<23;i2++) { for(i1=0;i1<23;i1++) prt_buf[i1] = 0; for(i1 = 0;i1<48;i1++) { ES=1;EA=1; prt_buf[i1] =ser_buf[p++];
Hello,
do not strictly concentrate on the code, be focus on what you want. I guess you want transmit a fixed number of bytes between two device. Every time one byte is received the RI flag is raised, and if enabled the serial interrupt too.
You shall enable the global interrupt and serial interrupt only once in the beginning of your program. When your buffer is full you step over index 0, so this byte does not change the byte since first time filled. You could also use the idea from mahitama charak, but be sure that you understand you did.
btw: Please place source code source code between pre-tags.
Greetings,
David
thanks to all my probelem solved..
Note that for code that sends data from one processor to another processor, without handshake, you must make sure that the transmitting side is never sending data faster than what the receiver is fast enough to pick up.
So if you have a tight transmit loop, it may send too fast. It all depends on what baudrate you have, i.e. how much delay the sending UART introduces between transmitted character. Have you made sure that the receiver can always (!) pick up data at the maximum speed the baudrate allows data to be transmitted?
"It all depends on what baudrate you have"
yes. a very good way to make sure that you receive fast enough is the the recieve baud rate faster than the transmit baud rate.
"yes. a very good way to make sure that you receive fast enough is the the recieve baud rate faster than the transmit baud rate."
Not at all - the receiver should try to match the baudrate of the transmitter as much as possible, since the A in UART stands for "asynchronous". So the receiver counts time to figure out where to sample the data signal to extract the individual bits. It obviously must counts time in the same way that the transmitter did, or it will greatly fail to separate the individual bits in a transmitted character.
It's just that the baudrate controls how long time it takes for a UART to perform a transfer of a full character - so the fastest possible time from reception of one character until the next character may be available to pick up from the data register of the receiving UART (if the transmitter manages to start the next transmission instantly when the previous character was sent).
and when you nuts enable the fifo [firs in first out] and use the interrupt.
"... you nuts enable the fifo ..."
Pray tell you nut, precisely what 8051 FIFO is that?
it was the suggestion. may be. www.8052.com/.../100570