Sonsivri
 
*
Welcome, Guest. Please login or register.
Did you miss your activation email?
April 19, 2024, 05:45:29 05:45


Login with username, password and session length


Pages: [1]
Print
Author Topic: High Speed & Efficient 2nd RS-232  (Read 7550 times)
0 Members and 1 Guest are viewing this topic.
sam_des
Senior Member
****
Offline Offline

Posts: 253

Thank You
-Given: 124
-Receive: 146


« on: November 08, 2007, 03:16:40 15:16 »

Hello everyone,

This is High Speed & Efficient Software+Hardware RS-232C implmentation for PIC.
It's features are,
 1] Like other Soft-Serial comm. it does not depend on software-loops
 2] It is NOT limited to low speeds only. I've tested it upto 38400 Baud.
 3] It is completely interrupt driven.

Uses:
 1] 2nd UART channel to CPUs having only 1
 2] Adding Half-Duplex UART to CPUs having no built-in UART.
 3] RS-485 (No direction change has been implemented yet).
 4] With enough resources, 3rd or 4th UART can also be added.

Hope you will find this useful.
Any comments/suggestions are welcome.

regards,
sam_des


« Last Edit: November 08, 2007, 04:48:11 16:48 by sam_des » Logged

Never be afraid to do something new. Remember Amateurs built the Ark, Professionals built the Titanic !
sonsivritwchen
Junior Member
**
Offline Offline

Posts: 37

Thank You
-Given: 18
-Receive: 15


« Reply #1 on: November 10, 2007, 01:57:48 01:57 »

Thanks, sam_des,
  It sounds very good. But,..., do I miss something in your post. I could not find your code.

Logged
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #2 on: November 10, 2007, 01:51:46 13:51 »

Hi!
I tried to compile the CC5X program with MPLAB but it gave up with macro "RRF"(need more argument). I have another "RS232 echo" program(9600 baud, pic 16F628) that is somewhat easier. sam_des says he use Jen's editor, but I don't like that. Maybe the fault is there. You'll find the "RELOC.INC" in the CC5X folder and the linker script for pic 16F628 in MPASM Suite/LKR

well, well... I'll take the time(sometime) to put inline asm in the main module since the linkerscript needs modifying when it comes to interrupt, and I really don't know how to modify the *.inc files.
« Last Edit: November 10, 2007, 07:33:09 19:33 by robban » Logged

Code Warrior
sam_des
Senior Member
****
Offline Offline

Posts: 253

Thank You
-Given: 124
-Receive: 146


« Reply #3 on: November 12, 2007, 06:10:00 18:10 »

Hello robban,

I guess you are forgetting to add the cc5x path in all the fields in Project Setup of MPLAB. If you still get problem, then you can use "sw232.mak" file provided in rar.
Just create a batch file with command --

x:\cc5x Dir\cc5x.exe +sw232.mak main.c & it will compile ok. Just substitute x:\cc5x dir with your cc5x installation path.

Well, now I've tested this code for Baud 57600bps. Grin
Of course, all my testing is done in Proteus. Has anyone tested this on real hardware ? I will be very glad to hear about it.

regards,
sam_des

Logged

Never be afraid to do something new. Remember Amateurs built the Ark, Professionals built the Titanic !
iso
Newbie
*
Offline Offline

Posts: 12

Thank You
-Given: 14
-Receive: 1


« Reply #4 on: November 13, 2007, 12:35:05 12:35 »

where is the party?
where is the code? Roll Eyes
Logged
robban
Senior Member
****
Offline Offline

Posts: 265

Thank You
-Given: 34
-Receive: 38


Warrior


WWW
« Reply #5 on: November 13, 2007, 02:32:43 14:32 »

At the top of this topic....
Logged

Code Warrior
kernelx
Junior Member
**
Offline Offline

Posts: 35

Thank You
-Given: 18
-Receive: 27


rm -rf /


« Reply #6 on: November 14, 2007, 06:01:52 18:01 »

I upload the file into several mirrors:

turbouplaod link : http://d.turboupload.com/d/2147147/sw232.rar.html
rapidshare link : http://rapidshare.com/files/69702749/sw232.rar.html

I hope sam_des dont mind if I made mirrors of his excellent work.
Logged

I'm just simply a newbie in electronics field.
picflash
Newbie
*
Offline Offline

Posts: 26

Thank You
-Given: 61
-Receive: 10


« Reply #7 on: November 18, 2007, 05:38:58 05:38 »

hello,

Your codes is cool, I have a request, can you port it to CCS C ?

Thank you,
PIC Flash
Logged
sam_des
Senior Member
****
Offline Offline

Posts: 253

Thank You
-Given: 124
-Receive: 146


« Reply #8 on: November 19, 2007, 07:08:52 19:08 »

Hello,

I am posting a enhanced version of my sw232 comm. driver. Nothing new in the basic, just few additions--
1] Automatic configuration on Baud Rate selection.
2] String Print
3] Unsigned/Signed 8-Bit number print.

Also, I am posting port of this driver to CCS PIC compiler as requsted by PIC Flash.
But there is one serious problem. Right now only upto 19200 bps is possible. Higher bauds are NOT possible with current code-structure.  Embarrassed
I think, "custom interrupts" for CCS must be used  Undecided
I will try when I get enough time.
Also, CCS requires much more code & RAM compared to CC5X.

As always any suggestions/comments/error reports are welcome.

regards,
sam_des
« Last Edit: November 19, 2007, 07:11:28 19:11 by sam_des » Logged

Never be afraid to do something new. Remember Amateurs built the Ark, Professionals built the Titanic !
setoy
Newbie
*
Offline Offline

Posts: 20

Thank You
-Given: 10
-Receive: 11


« Reply #9 on: November 20, 2007, 09:50:22 09:50 »


I think, "custom interrupts" for CCS must be used  Undecided
I will try when I get enough time.

regards,
sam_des

Hello sam_des.
What you mean under "custom interrupts" for CCS ?
Logged
sam_des
Senior Member
****
Offline Offline

Posts: 253

Thank You
-Given: 124
-Receive: 146


« Reply #10 on: November 21, 2007, 05:22:46 17:22 »

Hello setoy,

By "custom interrupts", I mean - global interrupts (#int_global) directive for CCS. Actually that means you've to write all the context save-restore code for interrupts as well as any interrupt dispatching needed.

Though it is not as easy as it seems. My code have used 2 built-in functions  label_address() & goto_address() which does use compiler's internal storage for temp. variables. Since Compiiler can use any of the addresses for temp. vars. we can not guess which locations we need to save.

Another problem is that we can't get the address of label using inline asm like --
  #asm
      movlw    high(lab)
      movwf    PCLATH
      movlw    low(lab)
      movwf   PCL
  lab:
  #endasm
So we are forced to use compiler's built-in functions. That's what CCS is famous for - a lot of built-in functions !!  Angry

Still, I haven't used CCS after v3.242. Newer versions may have work-arounds. It will be nice if there are work-arounds & someone implement them for this code.  Wink

BTW, I've also ported this code to PBP v2.50. If anyone is interested, I'll post it in the Basic section of our forum.

regards,
sam_des
Logged

Never be afraid to do something new. Remember Amateurs built the Ark, Professionals built the Titanic !
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #11 on: December 04, 2011, 01:31:31 13:31 »

As most of old hosted files are corrupted then would someone please reupload sam_des work?

I am looking for a good non-blocking software uart (interrupt driven), buffered full duplex would be the best.

TIA - Ichan
Logged

There is Gray, not only Black or White.
koky
Active Member
***
Offline Offline

Posts: 180

Thank You
-Given: 149
-Receive: 157


WWW
« Reply #12 on: December 04, 2011, 04:09:54 16:09 »

I have this copy in my archive
Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #13 on: December 04, 2011, 04:30:01 16:30 »

Koky, thanks for the help uploading it again.

After reading the code quickly, both putc and getc are blocking, so the interrupt use is not very useful here.

Time to scratch my head now..

-ichan
Logged

There is Gray, not only Black or White.
gan_canny
Junior Member
**
Offline Offline

Posts: 89

Thank You
-Given: 101
-Receive: 26


« Reply #14 on: December 04, 2011, 05:16:54 17:16 »

First PIC's very often have hardware UARTs so use them. For those PIC's that don't there are software emulations many of which are blocking as the main code must wait while a char is received and further the main code is restricted to a very tight loop since it must be ready at all times to receive an inbound bit. A solution is to wire the inbound bit onto a pin that can trigger an interrupt. Rb on change or ext_interrupt. As far as CCS goes there are good working examples in their forum library. Now typically rs232 is sampled at 16 times the baud rate this is what the PIC hardware UART does.This 16x sampling is how the timing of middle of the bit is found. The middle is useful for tolerance since the real timing can advance or slip almost 1/2 a bit time. A PIC interrupt requires the saving of the main program state and then restoring it. That's several dozen instructions. This then restrains the maximum baud rate for special interrupt code written to detect an incoming bit. This is often corrected somewhat by a sample early on the bit but may also sacrifice some tolerance. In contrast the PIC hardware UART interrupts when a full char is received and immediately buffers the next one. This gives much higher baud rates than any bit banged code using another interrupt on change pin. Again the CCS library has good working code.
« Last Edit: December 04, 2011, 05:27:07 17:27 by gan_canny » Logged
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #15 on: December 04, 2011, 10:23:52 22:23 »

Gan_canny, thanks for the info.

I need it because there is no microchip PIC (excluding PIC32) has ECAN port and more than 2 UART that I needed.

I am now working on it, the TX part is done - still working with the RX part, it is harder.

Attached a test with proteus, 2 HW uart + 1 SW UART all ring buffered interrupt driven. Data received at UART1 sent to UART2, UART2 to SW UART, there will be SW UART to UART1 if I can make it. Three led continuously blinking at 0.1, 1, and 10 second cycle to test the non-blocking feature.

In the .rar file there is the .dsn and .hex of it.

-ichan
Logged

There is Gray, not only Black or White.
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #16 on: December 05, 2011, 09:29:00 21:29 »

Do not want to hijack others thread, i put my last work on a new thread:

http://www.sonsivri.to/forum/index.php?topic=41756.0


-ichan
Logged

There is Gray, not only Black or White.
sam_des
Senior Member
****
Offline Offline

Posts: 253

Thank You
-Given: 124
-Receive: 146


« Reply #17 on: January 04, 2012, 01:44:53 13:44 »

Hello,

Sorry for replying so late. I just missed this  Embarrassed and It's been nearly 4 years  Roll Eyes

Quote
Koky, thanks for the help uploading it again.

After reading the code quickly, both putc and getc are blocking, so the interrupt use is not very useful here.

Time to scratch my head now..

-ichan

Yes, as far as I remember my original code blocked in getc() and putc() since it was meant for test-purpose not for real work.

It is very easy to make them non-blocking using seperate rx/tx buffers and any attempt to rx/tx while buffer is full can be flagged to caller as error without blocking, i.e. without waiting for space in buffer.
Caller can take the action as required.

Also, since my original code was basically intended for half-duplex comm., it is not possible to rx and tx simultaneously. This limitation is due to fact that both rx and tx use same timer to time the bit-period and can be overcame by using two seperate timers. But it is very rare case, where two timers are available for soft. comm and in such case I would prefer using external UART IC or use 2nd uC for just that purpose.

I may have mis-understood your words about blocking nature of soft comm. If you can give more details, may be I can help you.

regards,
sam_des
Logged

Never be afraid to do something new. Remember Amateurs built the Ark, Professionals built the Titanic !
Ichan
Hero Member
*****
Offline Offline

Posts: 833

Thank You
-Given: 312
-Receive: 392



WWW
« Reply #18 on: January 04, 2012, 08:13:37 20:13 »

Thanks for your over to help, but I already have solutions of my own.

-ichan
Logged

There is Gray, not only Black or White.
Pages: [1]
Print
Jump to:  


DISCLAIMER
WE DONT HOST ANY ILLEGAL FILES ON THE SERVER
USE CONTACT US TO REPORT ILLEGAL FILES
ADMINISTRATORS CANNOT BE HELD RESPONSIBLE FOR USERS POSTS AND LINKS

... Copyright © 2003-2999 Sonsivri.to ...
Powered by SMF 1.1.18 | SMF © 2006-2009, Simple Machines LLC | HarzeM Dilber MC