|
|
View previous topic :: View next topic |
Author |
Message |
sjharris
Joined: 11 May 2006 Posts: 78
|
Software UART woes. |
Posted: Fri Aug 04, 2006 3:10 am |
|
|
Hello,
I have been trying to use a software UART for some time now, I am using it to get 7 bit data TX and RX as opposed to using HW UART.
I have a simple program that polls kbhit command to see if any data is waiting, then if it is then it goes and gets it.
If no data has been received then the program will run a little animation on two 7 segment leds. It keeps polling the kbhit.
When I send something to PIC it returns it back to PC and it all works OK.
BUT. The animation will not start until you have sent something to PC, like the PIC is waiting to receive something even thought nothing is waiting and once you have sent something to PIC you cannot send anymore to it. It doesnt respond.
Do I need to clear and interrupts manually for the receiver to start again?
I cannot place code in the forums because of security purposes.
If you need any more details I will try my best.
Please help this is driving me nuts.
Cheers
SH |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Fri Aug 04, 2006 4:29 am |
|
|
If you are using the software UART then there is no interrupts that need to be set or cleared.
If you need only 7 bits but have control of the PC end then you could always set the PC to transmit 7 bits plus to stop bits. Then you and strip off the MSB when you pull the character out of the UART enableing you to use the hardware UART.
Failing that, without looking at the code there isn't much more help I can offer unless you would like an alternate RS232 driver. If so you can checkout my site. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Ttelmah Guest
|
|
Posted: Fri Aug 04, 2006 4:48 am |
|
|
There are no interrupts involved in the software UART.
The way it 'works', is that it looks for the input being low, waits 1.5 bit times from the point where it first sees this, and then samples the input at 1 bit time intervals. Now 'kbhit', on the software UART, simply looks for the input being low. There is a potential problem, and this is probably what is catching you. Imagine (for instance), that you use a kbhit, followed by a branch to a getc, at 9600bps, inside a routine, which itself takes 0.1mSec to 'loop' to the test. The serial line goes low, immediately after kbhit is tested. 0.1mSec latter the loop comes round again, and kbhit sees the signal as being low. The code then jumps to the getc, and since the bit time, is only 1.04mSec, the signal just happens to rise, between the kbhit test, and the getc. Getc, then looks at the input, and it is high, so it sits waiting for a character to arrive....
Now the system will normally 'recover' from this, by seeing a low inside the data character as the start bit, and retrieve a garbage character starting from this point, but depending how the input code 'parses' what is arriving, it can cause problems. As a general 'rule of thumb', to use kbhit, with the software UART, the code must reach the test no less frequently than about 1/4 the bit time, if it is to work properly. Slower than this,and corruption will probably occur, and a hang does become possible.
Best Wishes |
|
|
sjharris
Joined: 11 May 2006 Posts: 78
|
Thanks |
Posted: Fri Aug 04, 2006 7:11 am |
|
|
OK,
Thats is what I suspected. I may have a way around it.
I have checked the input on a scope and there seems to be a 1 bit period after each byte that I can use as an 8th bit, essentially always 1, I can then AND this with 0x7F to mask it out and then TX it to PC hopefully with 8 bit TX but only 7bits of data.
Hopefully this will work.
Thanks for your help |
|
|
ckielstra
Joined: 18 Mar 2004 Posts: 3680 Location: The Netherlands
|
|
Posted: Fri Aug 04, 2006 7:45 am |
|
|
Quote: | I have checked the input on a scope and there seems to be a 1 bit period after each byte that I can use as an 8th bit, | Just checking. You are not confusing this extra bit with the stop bit that follows each character? You really see: start bit/7 data bits/stop bit/extra bit ?
Sending the 7 bit protocol to the PC can be faked using your trick: Set the PIC UART to 8-bit mode and make sure the 8th bit is always a 1, this way you are sending 7 databits with 2 i.s.o. 1 stop bits. Extra stop bits are never a problem to the receiver and are automatically ignored.
Maybe you can also change your PC to send 2 stop bits? Than you are garuanteed to always receive the extra 8th bit and your trick is going to work. |
|
|
sjharris
Joined: 11 May 2006 Posts: 78
|
|
Posted: Fri Aug 11, 2006 4:59 am |
|
|
Yes that is correct there are 7 data bits, 1 stop bit then an extra bit that seems to be always high.
I am trying to get the pic to mask the last bit off, it doesnt seem to be working.
I am using getc and anding that with 0x7F so get rid of the last bit.
I hope this will work. It hasnt so far. |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|