Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
Andy Neil
09/03/05 02:13
Read: 808 times

#100515 - Slight misconception.
Responding to: Jeff Corr's previous message
Russell Bull said:
The core problem with your code is that the uart can only cope with one character at a time,
(my emphasis)

Jeff Corr said:
You seemed to indicate in your message that the 8051 type uC is not well suited for receiving serial port data

No, that's not what he meant at all!
He's just telling you that you can't use it in the way you've tried to!

Note that some UART chips - eg, the ones used in PCs - do have built-in FIFO buffers, but your average 8051 does not.
Your average 8051's UART handles just one character at a time - and, therefore, so must your code.

does anybody use it for this purpose?

I've used up to four UARTs on a Triscend - all streaming serial data.
Handling serial data on an 8051 is extremely common indeed.

The way I understood it (correct me if I am wrong) but the serial port int is triggered when a char. is received.

Correct so far.

At this point, it would probably be helpful if you had chapter 3 of the "bible" open in front of you at page 11, and refer to figure 12 on page 12:

Chapter 3 - 80C51 Family Hardware Description:

For simplicity, assume that nothing at all is happening on the transmit half of the 8051 UART...

As the serial data bits are received, they are shifted into a shift register. When a complete byte has been received (start bit, 8 data bits, stop bit), it is copied from the shift register into SBUF, and RI is set.

Upon jumping to the interupt, one char is received, the RI bit is set high...

Not quite.

As noted above, the RI bit is set by the hardware when the completed received byte is loaded into SBUF.
If the serial interrupt is enabled, setting the RI bit causes an interrupt to occurr - and the processor jumps to the serial interrupt vector location. Again, this all happens in hardware.

So, when your Interrupt Service Routine (ISR) is entered, you know that exactly one received byte is present in SBUF.
Therefore, the job of your ISR is:
  • Clear the RI bit;
  • Retrieve the character from SBUF into some suitable storage.
    and that's all it should do - this leaves the serial port ready for the next byte.
    When reception of the next byte is complete (and not before), SBUF will be loaded again, RI will be set again, and your ISR will be called again to retrieve another one byte.

    and the program should loop until then.

    The main program might loop - but the ISR certainly shouldn't!
    In fact, the whole point of using interrupt-driven serial IO is that the main program does not need to waste time looping while waiting for characters!

    That all assumed receive-only UART activity.
    In general, the UART ISR will be entered whenever RI (the receiver interrupt) or TI (the transmit interrupt) or both is set; therefore a general UART ISR has two sections - one checks RI, and handles the receive interrupt; the other checks TI, and handles the transmit interrupt.

    Hrm.. can an interupt be triggered from within itself?

    If RI is (still) set when the ISR exits, the processor will immediately jump straight back into the ISR!

  • List of 85 messages in thread
    Laser system serial port com      Jeff Corr      09/02/05 01:25      
       MHz?      Oliver Sedlacek      09/02/05 01:32      
          11.059      Jeff Corr      09/02/05 01:54      
             also...      Jeff Corr      09/02/05 01:55      
       Even more... anybody got any ideas?      Jeff Corr      09/02/05 02:30      
          Values in      Anders Sandström      09/02/05 02:58      
       text???      Jan Waclawek      09/02/05 03:14      
          thanks so far      Jeff Corr      09/02/05 05:29      
             Back to basics      Andy Neil      09/02/05 05:53      
             Oh, come on...      Andy Neil      09/02/05 06:45      
          "Program" or "Code?"      Andy Neil      09/02/05 11:01      
       Oh dear...      Andy Neil      09/02/05 03:57      
       Fundamental Comms Problem      Andy Neil      09/02/05 04:05      
       Serial Code - Doomed!      Andy Neil      09/02/05 04:23      
          this is getting ridiculous      Erik Malund      09/02/05 06:13      
             learning process      Jan Waclawek      09/02/05 06:21      
                oh well      Erik Malund      09/02/05 06:54      
                   agreed - waiting for the real stuff :-)      Jan Waclawek      09/02/05 06:58      
                cart before horse      Andy Neil      09/02/05 07:03      
                   weekend approaching?      Jan Waclawek      09/02/05 07:34      
                      sure we can, but then why do you say the      Erik Malund      09/02/05 07:55      
       this belong in the chat, but since it is      Erik Malund      09/02/05 11:07      
          hrm      Jeff Corr      09/02/05 12:10      
             make an effort do not "whip up some code      Erik Malund      09/02/05 13:36      
                facts & emotions      Jan Waclawek      09/02/05 14:50      
                   k      Jeff Corr      09/02/05 15:29      
                      Good luck with the 430's      Russell Bull      09/02/05 18:20      
                         int      Jeff Corr      09/02/05 18:44      
                            Slight misconception.      Andy Neil      09/03/05 02:13      
                               Next step      Andy Neil      09/03/05 02:39      
             -1 provocative troll      Terry Lingle      09/02/05 17:25      
                read      Jeff Corr      09/02/05 18:50      
                   which derivative?      Jan Waclawek      09/03/05 07:20      
                      dallas      Jeff Corr      09/04/05 00:37      
                         DS89C420      Jan Waclawek      09/04/05 03:55      
                            system im using      Jeff Corr      09/04/05 08:49      
                               int      Jeff Corr      09/04/05 09:28      
                                  Process      Andy Neil      09/05/05 00:04      
                                     Why do you persist      Erik Malund      09/06/05 09:02      
                                  2 byte protocol      Robert Revens      09/05/05 03:24      
                                     Intersting, but...      Andy Neil      09/05/05 04:50      
                                        very interesting      Jeff Corr      09/05/05 19:33      
                                           How to proceed      Andy Neil      09/06/05 00:02      
                         a problem and a suggestion      Erik Malund      09/06/05 09:00      
       Problems many & varied      Russell Bull      09/05/05 20:46      
          Begin at the beginning!      Andy Neil      09/05/05 23:59      
             started again      Jeff Corr      09/06/05 00:31      
                Re: started again      Hans Van Pelt      09/06/05 01:07      
                   ah crap.      Jeff Corr      09/06/05 01:18      
                      ah my eyes!      Hans Van Pelt      09/06/05 01:36      
                         continued..      Jeff Corr      09/06/05 01:47      
                            Second UART      Hans Van Pelt      09/06/05 01:58      
                               int vector      Jeff Corr      09/06/05 02:33      
                                  Look at the datasheet !      Steve M. Taylor      09/06/05 02:37      
                                     yup      Jeff Corr      09/06/05 03:37      
                serial port 1 interrupt vector      Jan Waclawek      09/06/05 02:06      
                   okay      Jeff Corr      09/06/05 02:41      
                      Still not OK      Hans Van Pelt      09/06/05 03:18      
                         ISR reset      Jeff Corr      09/06/05 03:41      
                      take rest      Jan Waclawek      09/06/05 03:18      
                         rest........      Jeff Corr      09/06/05 03:43      
                            STOP      Steve M. Taylor      09/06/05 04:07      
                            just to be sure...      Jan Waclawek      09/06/05 04:09      
                               man int triggering      Jeff Corr      09/06/05 05:48      
                Craig, please remove this thread this is      Erik Malund      09/06/05 09:05      
                   Request        Craig Steiner      09/06/05 09:16      
       num      Jeff Corr      09/06/05 07:32      
          again      Jan Waclawek      09/06/05 07:57      
             Thanks ALOT Jan !!      Jeff Corr      09/06/05 11:11      
                works, so now do the reading      Jan Waclawek      09/06/05 14:46      
                   serial port int      Jeff Corr      09/07/05 20:41      
                      transmit      Jan Waclawek      09/07/05 23:15      
                         transmit      Jeff Corr      09/08/05 08:53      
                            Oh dear      Donald Catto      09/09/05 09:55      
                               I dont give up.      Jeff Corr      09/09/05 16:22      
                                  er      Steve M. Taylor      09/09/05 17:31      
                                     brains?      Jeff Corr      09/10/05 08:19      
                                        Or lack thereof...      Donald Catto      09/12/05 06:45      
                                  Persistance is a virtue      Russell Bull      09/09/05 17:39      
                                     basics      Jeff Corr      09/10/05 08:22      
       updated      Jeff Corr      09/14/05 18:48      
          Solve i problem at a time      Russell Bull      09/15/05 01:44      
       one more problem knocked down      Jeff Corr      09/16/05 00:32      
          PWM spoiled by Rx      Jan Waclawek      09/16/05 03:51      
             lines      Jeff Corr      09/16/05 13:45      

    Back to Subject List