Jump to content

Recommended Posts

I'm using the PIC16F913, which has a serial output. I set up the serial port to transmit on a timer overflow interrupt.

 

To send serial data, all I have to do is set TXREG equal to the byte I want to send, right?

 

I've set this up with 2 different compilers, 3 different serial port readers, 3 different baud rates, and I keep getting the same results - serial data is transmitted, but it's not what I sent. In the code snippets below, I send 0x39, but what I get is 0x63 (or ASCII "c" for hyperterm).

 

The data that I get on the serial port is consistent, but never the same as what I send - it's not shifted or inverted. Not sure what the issue is - anyone have any ideas? Thanks!

 

txsta = 0b00100000;
rcsta = 0b10000000;
spbrg = 0b00001100;		//Baud: 1200

...

txreg = 0x39;

Edited by dersk

Share this post


Link to post
Share on other sites

0x39 = 00111001(stop=1)

0x63 = 01100011(stop=1)

 

I forget if the msb or lsb is sent first but assumming that the msb is sent first, the 0x39 could look like 0x63 if the receiver was set up to read 7 bits instead of 8 and was sampling a little too fast. I think it is the LSB first so who knows.

 

Your baud rate value of 0xc (12) looks suspect to me. But, I am looking at a data sheet for a 16F874. Most of the baud rate generators have been the same for the newer 16F devices so I'm assuming it is the same for the 16F913. You did not specify a clock frequecy that you are running the chip so it is hard to say what the correct value is.

 

I'm not a big fan of low baud rates as all it does is slow down your PIC waiting to send data. 115.2K baud has always worked really well for me with a 20 MHz clock.

 

The bottom line is that you should check the data sheet for this part and use the equation or tables provided to check that you selected a proper baud rate.

Share this post


Link to post
Share on other sites
I'm using the PIC16F913, which has a serial output. I set up the serial port to transmit on a timer overflow interrupt.

 

To send serial data, all I have to do is set TXREG equal to the byte I want to send, right?

 

I've set this up with 2 different compilers, 3 different serial port readers, 3 different baud rates, and I keep getting the same results - serial data is transmitted, but it's not what I sent. In the code snippets below, I send 0x39, but what I get is 0x63 (or ASCII "c" for hyperterm).

 

The data that I get on the serial port is consistent, but never the same as what I send - it's not shifted or inverted. Not sure what the issue is - anyone have any ideas? Thanks!

 

txsta = 0b00100000;
rcsta = 0b10000000;
spbrg = 0b00001100;		//Baud: 1200

...

txreg = 0x39;

 

Looks like it could be an inversion issue, the bits match when bit shifted and inverted:

0x39 = 00111001
0x63 =01100011

Regards

Dave

Share this post


Link to post
Share on other sites

Do you have some form of RS232 driver chip tagged onto the TX outpit pin or are you driving directly from PIC to PC serial port. A driver chip will give you the correct inversion, as well as voltage levels.

 

The baud rate value (12) is correct for the default internal oscillator at 4MHz or Fosc = 1MHz.

 

Cheers

 

Reynard

Share this post


Link to post
Share on other sites
I'm using the PIC16F913, which has a serial output. I set up the serial port to transmit on a timer overflow interrupt.

 

To send serial data, all I have to do is set TXREG equal to the byte I want to send, right?

 

I've set this up with 2 different compilers, 3 different serial port readers, 3 different baud rates, and I keep getting the same results - serial data is transmitted, but it's not what I sent. In the code snippets below, I send 0x39, but what I get is 0x63 (or ASCII "c" for hyperterm).

 

The data that I get on the serial port is consistent, but never the same as what I send - it's not shifted or inverted. Not sure what the issue is - anyone have any ideas? Thanks!

 

txsta = 0b00100000;
rcsta = 0b10000000;
spbrg = 0b00001100;		//Baud: 1200

...

txreg = 0x39;

Try sending without the timer interrupt & check it up just to rule out the timing problem else you might be writing into the TXreg to often before one transmit is completed.

regards

Raghunathan.

Share this post


Link to post
Share on other sites
Do you have some form of RS232 driver chip tagged onto the TX outpit pin or are you driving directly from PIC to PC serial port. A driver chip will give you the correct inversion, as well as voltage levels.

 

That's what I needed - a driver chip - thanks for all the suggestions, I got it to work.

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...

×
×
  • Create New...