Jump to content
Sign in to follow this  
BJH

Uart Documentation

Recommended Posts

Hello all,

 

I am trying to use the Sourceboost UART driver. I am in the process of reading the documentation so that I can get to grips with how to use it. I have encountered something that is confusing to me. On page 87 of the boostc manual that is supplied with the latest Sourceboost package, examples are given such as below:

#define uart1TxInterruptHandler \
rs232TxInterruptHandler<PIR1,TX1IF,TXREG1,sizeof(txBuffer), \
TXSTA,TXEN,TXSTA,TRMT>

Can someone tell me what the backslashes (\) are for?

Also, with regard to the boostc manual, there seem to be differences between the manual supplied with the sourceboost package (boostc.pdf) and the one linked to on the website (http://www.sourceboost.com/Products/BoostC/Docs/boostc.pdf)

Cheers all,

BJH

Share this post


Link to post
Share on other sites

The backslashes are continuation markers. #defines have to be on a single line. To avoid ugly definitions, C compilers allow the backslash to continue the current line on the previous line.

 

#define ICKY you_are(\

int making_me_very_happy);

 

Is the same as:

 

#define ICKY you_are(int making_me_very_happy);

Edited by trossin

Share this post


Link to post
Share on other sites

The backslashes are continuation markers. #defines have to be on a single line. To avoid ugly definitions, C compilers allow the backslash to continue the current line on the previous line.

 

#define ICKY you_are(\

int making_me_very_happy);

 

Is the same as:

 

#define ICKY you_are(int making_me_very_happy);

 

Ah okay, thanks for the explanation. I did consider line continuations but as C does not care about such things I didn't see why it would be needed. I didn't consider that #define statements would need to be one-liners, but obviously they would need to be.

 

Cheers,

 

Brian

Share this post


Link to post
Share on other sites

Okay, I've got the uart driver working now. It took me a while to wrap my mind around how it's all supposed to work, mainly because I'm not too familiar with the use of templates.

 

Thanks,

 

BJH

Share this post


Link to post
Share on other sites

Okay, now that I've had some time to play with the UART driver, I'm experiencing an intermittent transmit problem. Below are two simple functions I've written to send RS232 data; one for sending a single character, and another for sending a message:

void printc(unsigned char c)
{
uart1Tx©;
}
void printm(unsigned char* message)
{
int i = 0;
while (message != '\0')
{
uart1Tx(message);
i++;
}
}

 

To test some things I decided to use my ISR to echo anything that was received over RS232. This way I can connect a terminal to it, type some data on the terminal, and this data should be echoed back to the screen:

 

// UART1 Receive

 

if (pir1.RC1IF)
{
if(uart1RxInterruptHandler())
{
while (rxCnt != 0)
{
unsigned char data = uart1Rx();
if (data == 0xd)
{
printm("\r\n> ");
}
else
{
printc(data);
}
}
}
}

 

 

This works quite well. Unfortunately, though, the code has a habbit of intermittently repeating a character twice. Here's the result of me typing the alphabet into the terminal a few times:

 

> abbcdeffghijkklmmnopqrsttuvwxyzz
> abbcddeefghijkklmmnopqrstuvwxyz
> abcddefghijklmmnopqrsstuvwxyz
> aabcdeefghhijklmnopqrstuvwxyz
> abcdefghijklmnopqrstuvwxyz
> abcddefghijklmnopqrstuvwxyz

 

On the last two lines I typed really fast with no delay between characters. On the other lines I typed by pressing one single key at a time with a small delay. It seems that if I type really quickly, and therefore send data quite repetitively, it doesn't repeat any characters. Otherwise it intermittently repeats some transmitted characters.

Has anyone else experienced this? Or does anyone have recommendations?

Share this post


Link to post
Share on other sites

I solved my problem with the repeated characters by making proper use of the buffer. My test code rendered the buffer pointless as I was processing characters every single time an interrupt was generated. So I changed my interrupt service routine so that it only processes data when the buffer has more than 7 characters in it. Elsewhere in the ISR there is another piece of code which executes every time TIMER0 overflows (about once every 0.5 seconds), and in this part of the code I flush the buffer so that any data <7 characters long that is lingering there gets processed.

 

Now I don't see the repeated characters issue.

Share this post


Link to post
Share on other sites

Your content will need to be approved by a moderator

Guest
You are commenting as a guest. If you have an account, please sign in.
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  

×