We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
I would like to have my two 89C51RD2 communicate with each other via UART. They are connected such that one TX pin is connected to the other's RX pin and vice versa. I tried sending byte by byte and it is working. However, when I tried to transmit larger amount of data at one go, the receiving end isnt able to read the data. I feel that I am missing something silly. Is the microcontroller able to store the incoming data while I poll and get them byte by byte? Would somebody please advise. Thank you. Cheers
If you are running 512k baud or 256k baud, then the transmitters send data faster than the receive can keep up with them them. I had this problem, we used a 100 or 200 microsec delay between transmits. if you are running a normal baud rate this shouldnt be a problem. But we had to set the serial interrupt highest priorty. Also if there is any other interrupt the could prevent the receive interrupt from immediately vectoring then you could have a situation where your second or third or any receive interrupt could get interrupted again before you leave the interrupt routine. So RI=1 when you leave the the rxinterrupt routine...you never will vector...hung. There is rx and tx stuff in the example below to take note of. The following code is from memory, it is not working code. char TxCount = -1; char CurrentTxBuffer[10]; char NewTxBuffer[10]; char *SendData; char RxBuffer[10]; // a circular rx buffer is best...not shown char *RxData; void MainLoop { char *RxData2; RxData = &RxBuffer; //do each new rx msg RxData2 = RxData; // do each new rx msg do { ... //Rx if(RxData2 != RxData) new rx data at *(++RxData2) ... //Is Tx Busy? example is CurrentTxBuffer // is not done yet but you want to send // another NextTxBuffer // nothing should interfere with TxCount // or SendData unless TxCount < 0 if(TxCount<0) //TxCount<0 = Tx not busy { TxCount = length of new tx message -1 SendData = &NewTxBuffer SBUF = *SendData++; //this starts tx } ...other mainloop stuff }while(1); } void SerialInterrupt(void) ... { do { if(RI) { RI=0; *RxData++=SBUF; } // Tx // dont forget there is always 1 more // TI after the last byte has been sent // So you need to transmit only if Tx // buffer count is not zero. // if(TI) { TI=0; // always clr interrupt first // dont write SBUF if Count = 0 if(TxCount--) //TxCount=TxBuffLength SBUF = *SendData++; } }while( RI || TI ); // only use the do while if you think you // are sometimes not finishing transmit, // tx hangs up. or your losing rx bytes }