Jump to content

Advantages Of Hardware Uart Over Software Uart ?


Recommended Posts

Hi guys,

 

Can any one tell me the advantages of using hardware uart over software uart?

 

Raghunathan.

 

Less software required, you are not tieing up the processor to some bit bashing routine.

 

Make cyclic buffers for your RX and TX data and service in interrupt time.

Link to post
Share on other sites
Hi guys,

 

Can any one tell me the advantages of using hardware uart over software uart?

 

Raghunathan.

 

Less software required, you are not tieing up the processor to some bit bashing routine.

 

Make cyclic buffers for your RX and TX data and service in interrupt time.

 

Hi Picxie,

 

I have not used the hardware uart so far. I suppose Huart will take less code space compared to Suart. Picxie, can you explain the second advantage regarding servicing in interrut time with any example.

 

Thanks,

 

Raghunathan.

Link to post
Share on other sites

Basic Hardware Uart usage

 

/* bare min in interrupt for rx 
*  * remember to clear out the holder fast enough, will start dumping after 3 bytes or use multi-dimension
*/
if(rcif)
{
  rxHolder[rxCount] = rcreg;  /* read data into array to handle in main when count max is reached */
  rxCount++;                            /* increment count */
  rcif = 0;                                   /* safety clear - SHOULD clear on rcreg read */
}


/* minimal non-blocking send 
   under timer trigger if critical 
   otherwise handled general in main
*/
if(!txsta)   /* is last send done? skip if not */
{
  txreg = dataToSend;
}

 

Thats about it other than setting up the registers.

Edited by emte
Link to post
Share on other sites
Basic Hardware Uart usage

 

/* bare min in interrupt for rx 
*  * remember to clear out the holder fast enough, will start dumping after 3 bytes or use multi-dimension
*/
if(rcif)
{
  rxHolder[rxCount] = rcreg;  /* read data into array to handle in main when count max is reached */
  rxCount++;                            /* increment count */
  rcif = 0;                                   /* safety clear - SHOULD clear on rcreg read */
}


/* minimal non-blocking send 
   under timer trigger if critical 
   otherwise handled general in main
*/
if(!txsta)   /* is last send done? skip if not */
{
  txreg = dataToSend;
}

 

Thats about it other than setting up the registers.

 

Hi emte,

Its just today that i started to read the data sheet of 16f8xx on the USART module.

I realize that the flag rcif can't be cleared in software. Its cleared only in hardware & this happens when you read the rcreg register. I think upon reading the rcreg, it automatically gets cleared (gets empty). And since rcreg is a double buffered, capable of storing 2 bytes of data it may probably take 2 reads before you can clear the rcreg register and rcif flag. The only way to disable the interrupt is to clear the rcie enable bit. Am i write ? can you add some more information to improve my understanding. I have changed your code a bit. Is it o.k?

while (rcif ==1)
{
  rxHolder[rxCount] = rcreg;  /* read data into array to handle in main when count max is reached */
  rxCount++;                            /* increment count */
}

 

Regards

Raghunathan.

Link to post
Share on other sites
Hi emte,

Its just today that i started to read the data sheet of 16f8xx on the USART module.

I realize that the flag rcif can't be cleared in software. Its cleared only in hardware & this happens when you read the rcreg register. I think upon reading the rcreg, it automatically gets cleared (gets empty). And since rcreg is a double buffered, capable of storing 2 bytes of data it may probably take 2 reads before you can clear the rcreg register and rcif flag. The only way to disable the interrupt is to clear the rcie enable bit. Am i write ? can you add some more information to improve my understanding. I have changed your code a bit. Is it o.k?

while (rcif ==1)
{
  rxHolder[rxCount] = rcreg;  /* read data into array to handle in main when count max is reached */
  rxCount++;                            /* increment count */
}

 

Regards

Raghunathan.

 

I realize that the flag rcif can't be cleared in software. Its cleared only in hardware & this happens when you read the rcreg register.

Is not fully reliable, the errata on many devices state that you need to clear it in software or

that reading it will not be enough to clear it. (i do not recall specifically for the 16f877a)

 

rcreg is double buffered, but this means your can actually deal with upto three bytes if your

system is slow, two in the registers and one "on deck". (although your last one may not be reliable)

 

As for the interrupt, it will interrupt again when it shifts the data from the secondary into the main

rc register, this means every time you "read" the rcreg the flag will be cleared but if you have

more that you have not delt with yet you will get another interrupt right away.

 

If your using the chunk of code above and handling your captured data in main, you will not have

to worry about missing data. At 20Mhz that gives you an internal clock of 5Mhz and an instruction

time of 200nS, even at 115 you will not miss data unless you have some other bad interrupt code.

So there is really no reason to disable the receive uart ... unless your using it with a pair of serial RF

devices that may interfear with each other.

 

Not sure if any of that helps make things any clearer ...

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...