View previous topic :: View next topic |
Author |
Message |
silelis
Joined: 12 Jun 2007 Posts: 68 Location: Poland, podlaskie district
|
PIC18F4520 - two RS232 devices at one bus |
Posted: Tue Feb 14, 2017 3:57 am |
|
|
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: 19494
|
|
Posted: Tue Feb 14, 2017 4:42 am |
|
|
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
|
|
Posted: Tue Feb 14, 2017 5:11 am |
|
|
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: 9220 Location: Greensville,Ontario
|
|
Posted: Tue Feb 14, 2017 7:09 am |
|
|
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
|
|
Posted: Tue Feb 14, 2017 7:15 am |
|
|
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: 19494
|
|
Posted: Tue Feb 14, 2017 8:14 am |
|
|
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
|
|
Posted: Tue Feb 14, 2017 1:24 pm |
|
|
Ttelmah wrote: | You can do this by setting up multiple streams and using 'NOINIT' |
Can You explain it little more? |
|
|
|