CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Software UART library

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
nehallove



Joined: 16 Jan 2008
Posts: 61

View user's profile Send private message

Software UART library
PostPosted: Mon Jul 23, 2012 11:06 pm     Reply with quote

Hi All,

We are trying to implement software Uart for our product because of some constraint. Does CCS has software library for software UART like MPLab that I can use?

Thank you.

Nehl
_________________
nehal
temtronic



Joined: 01 Jul 2010
Posts: 9229
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Tue Jul 24, 2012 5:08 am     Reply with quote

Yes..it's in the manual...look under setup rs232(.....options....). Within design limits of the PIC you have, almost every I/O pin can be a UART.

hth
jay
nehallove



Joined: 16 Jan 2008
Posts: 61

View user's profile Send private message

PostPosted: Tue Jul 24, 2012 1:55 pm     Reply with quote

I am sharing I2C and software uart on the same pin. I am using
#use i2c(Master,Slow,sda=PIN_C4,scl=PIN_C3,force_hw,RESTART_WDT). How do I switch between UART and I2C at run time?

Thanks

nehl
_________________
nehal
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Tue Jul 24, 2012 4:27 pm     Reply with quote

You need to tell which pic for instance to get a better sense of what to do
but trying to share with i2C is a tough place to be.

And showing a schematic of the circuit attached to you pic would not be a bad idea either.
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PostPosted: Wed Jul 25, 2012 12:08 am     Reply with quote

Both software UART and I2C built-in functions are not prepared for dynamical pin sharing or e.g. re-initialization.

Basically, you would want to setup a software UART for the said pins, which are also hardware I2C pins according to your post. So hardware I2C functionalilty can be always achieved by accessing PIC special function registers, if the CCS I2C functions don't want to coexist with a software UART for the same pins, which I'm not sure about.

When switching from I2C to software UART, you'll need to re-initialize the port pins accordingly. So some low level action will be surely involved.

I wonder, how you want to use the pins as UART, if I2C peripherals are connected to it. They can easily block the pins, reacting on illegal I2C sequences.
Ttelmah



Joined: 11 Mar 2010
Posts: 19518

View user's profile Send private message

PostPosted: Wed Jul 25, 2012 2:23 am     Reply with quote

Realistically, the CCS software UART, has little needed in the way of 'setup'. For the output, the pin just needs to be set to drive high when not used, and for receive the pin just needs to be an input, and being pulled high by the external hardware before the receive functions are called.
Software I2C, as a master is similarly pretty friendly. The pins would need to be set to _float_ before I/O.
However mixing the two, will need a lot of care regarding the hardware I2C, is an 'open collector' bus, with the pins only ever driven low, and allowed to be pulled high with resistors. I can see problems mixing this onto either the receive line, or tx line for RS232, unless the hardware is physically disconnected when not in use.
Hardware I2C, will need you to set the TRIS to be set for both pins according to the data sheet for your particular chip, before use, and it would probably be best to turn off the peripheral before trying to use async serial on the pins. Unless the remote hardware is physically disconnected I can see problems occurring, if the serial is duplex, then the I2C condition that data on SDA must be stable when SCL is high, _will_ be breached, and I can quite easily see the lines generating an accidental 'start' condition, which could put the chips into an unknown state.
If this is 'simplex' serial, with just (say) the TX pin being used, then with care it could be made to work. Otherwise, it is an "accident waiting to happen".....
An alternative, would be to use a really simple PIC that has an I2C hardware peripheral as an I2C slave, and add it to the I2C bus, then have _it_ transmit/receive the serial needed under control of I2C.

Best Wishes
nehallove



Joined: 16 Jan 2008
Posts: 61

View user's profile Send private message

PostPosted: Wed Jul 25, 2012 1:03 pm     Reply with quote

Thank you very much for your reply guys. It was very informative and i have a clear idea it is illegal to share same bus for i2c and Uart devices without disconnecting devices. In my case that is not possible. As Ttelmah suggest I will look for i2c to uart converter/processor for UART I/O.

Thanks

nehl
_________________
nehal
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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