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

PIC18F4520 - two RS232 devices at one bus

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



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

PIC18F4520 - two RS232 devices at one bus
PostPosted: Tue Feb 14, 2017 3:57 am     Reply with quote

Hello,

I am developing application when I want to operate 2 RS232 devices and to communicate with them I require RS232 receive data interrupt.

I want to use RC6/TX/CK and RC7/RX/DT as a USART.

I understand that devices can not run both at the time so their power supply will be controlled by transistor key (so only one at the moment will be listening and talking) but is it possible form program site.

Something like this:
Code:

If (devise_1)
{
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1) //example values
}

If (devise_2)
{
#use rs232(baud=19200,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=PORT1) //example values
}

Also will it works with interrupts?
Ttelmah



Joined: 11 Mar 2010
Posts: 19554

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 4:42 am     Reply with quote

The #use line, is _not_ code. It can't be included in program flow. It is a 'preprocessor' directive, setting things up.
Your chip only has one hardware USART, so only one UART interrupt.

However what you show makes no sense. You are just using the single USART on the single pair of pins, so nothing needs to change. Just set this up once before the start of the code.
It appears all you want to do is change the baud rate?. If so, then there is a program command for this:
Code:

//In the header for your code. Before any code itself.
//After chip definition, fuses & clock settings
#USE RS232 (UART1, baud=9600, bits=8, stream=PORT1)

//Then in your code:
   If (devise_1)
       setup_uart(9600,PORT1); //set the UART to use 9600 baud
   else
       setup_uart(19200,PORT1); //set the UART to the alternative rate
silelis



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 5:11 am     Reply with quote

Understand. Is it also possible to change other UART parameters like parity, bits, and so on? (even in #ASM)???
I mean during program execution?
temtronic



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

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 7:09 am     Reply with quote

two comments...

Can you select a PIC that has 2 HW UARTS ? It'd make your life a LOT easier,even if it cost you another $1 ! If the PIC is to ONLY receive data from one of the 'devices' you could use a pin that has interrupt capability and use a software UART.

It's not normal, though possible, to change the UART parameters, however you need to do a LOT of 'decoding' to confirm the parameters are correct. I'm not too sure how you can do this unless you KNOW what 'device' is being attached to the PIC and the actual data it sends.

I am curious as to your application.More details may show us a better soultion for you.

Jay
silelis



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 7:15 am     Reply with quote

The application is audio receiver (specific one with not a lot of free room inside of case) and on RX/TX bus there is mp3 module and DAB+ module (audio inputs).

So I am almost 100% certain that they will not talk in parallel. That Is why I asked about it.

I just consider all possibilities in design and code.
Ttelmah



Joined: 11 Mar 2010
Posts: 19554

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 8:14 am     Reply with quote

There are very few other parameters. The PIC is very restricted on what it 'can' do. In fact it can't generate parity and this has to be done in added software. You can do this by setting up multiple streams and using 'NOINIT' on these. then just enabling the stream you want.
It's also worth realising that a lot of modes can be done with others.

8bit+parity is actually done by enabling 9bit mode on the PIC and generating the parity in software.

Generally very little these days uses anything other than 8bit no parity.
silelis



Joined: 12 Jun 2007
Posts: 68
Location: Poland, podlaskie district

View user's profile Send private message

PostPosted: Tue Feb 14, 2017 1:24 pm     Reply with quote

Ttelmah wrote:
You can do this by setting up multiple streams and using 'NOINIT'


Can You explain it little more?
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