Jump to content
Sign in to follow this  
subkor

Bug In Serial_driver.h

Recommended Posts

Damnit! I accidentally refreshed the page and lost everything I just typed! Sorry but I'm only trialing the software so I'm not going to type out all the proper headings again!

 

If you look in serial_driver.h dated 15 Nov 2004 (from BoostC 1.8 I think) you will find the following problems (some code removed for clarity):

 

Note, this is relevant to the PIC16F628.

 

void PUTC(char tx_char)

{

volatile bit l_txif@T_TXIF_PIR.u_TXIF; // 0xf9e.4;

 

while (!l_txif); // wait until tx register is empty

 

l_txreg = tx_char;

}

 

l_txif will only be set when the l_txreg line is completed, therefore it will wait forever. It should be something like:

 

volatile bit l_trmt@0x98.1; //txsta

while (!l_trmt);

l_txreg = tx_char;

 

Which will wait for any current transmissions to finish.

 

 

If you look at:

 

void UART_INIT(unsigned char BRG_mode, unsigned char BRG_divisor)

{

volatile unsigned char l_rcsta@T_RCSTA;

volatile bit l_brgh@T_TXSTA.u_BRGH;

 

if (BRG_mode)

l_brgh = 1;

else

l_brgh = 0;

l_txsta = 0xa4; // enable transmit function

}

 

The l_txsta assignment overwrites any result from the l_brgh assignment. This ignores any low speed settings for the serial port.

 

Just quickly, there's a compiler bug involving conditional operators in an array index. Something like

a[(:(?d:e]=f;

has problems when

g=(B)?d:e;

a[g]=f;

works fine. I haven't got the code anymore so I can't remember the details. Sorry but my trial period is about to end so I'm off to evaluate other software.

 

Good Luck.

David

Share this post


Link to post
Share on other sites

BoostC doesn't have any trial period. The version 1.6 that is included into SourceBoost 5.7 release was set to expire to force users to upgrade to newer version.If you update to Tte current BoostC version 1.8 it will fix this expiration problem.

 

Regards,

Pavel

Share this post


Link to post
Share on other sites

The original code sequence (below) does not loop forever.

 

void PUTC(char tx_char)
{
volatile bit l_txif@T_TXIF_PIR.u_TXIF; // 0xf9e.4;

while (!l_txif); // wait until tx register is empty

l_txreg = tx_char;
}

 

l_txif is set by the hardware UART when the TXREG is empty. The test

while (!l_txif); // wait until tx register is empty

 

will loop until the TXIF flag is set by the PIC which is the intended behaviour - it will not loop forever unless the serial port was not initiaised.

 

The second issue in UART_init is a bug.

code prior to bug fix:

  // setup the USART baud rate
 // configure baud rate generator mode High vs Low speed
 if (BRG_mode)
	 l_brgh = 1;
 else
	 l_brgh = 0;	
	 
 // configure the divisor	
 l_spbrg = BRG_divisor;
 l_txsta = 0xa4; // enable transmit function
	 // 7   Async mode - don't care
	 // 6   8 bit selection
	 // 5   Enable TX
	 // 4   SYNC - Async mode
	 // 3   not implemented
	 // 2   BRGH - high speed
	 // 1-0 don't care

The corrected code:

  // setup the USART baud rate
 // configure the divisor	
 l_spbrg = BRG_divisor;
 l_txsta = 0xa4; // enable transmit function
	 // 7   Async mode - don't care
	 // 6   8 bit selection
	 // 5   Enable TX
	 // 4   SYNC - Async mode
	 // 3   not implemented
	 // 2   BRGH - high speed
	 // 1-0 don't care	

 // configure baud rate generator mode High vs Low speed
 if (BRG_mode)
	 l_brgh = 1;
 else
	 l_brgh = 0;

Share this post


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...
Sign in to follow this  

×
×
  • Create New...