View previous topic :: View next topic |
Author |
Message |
shardul
Joined: 12 Nov 2010 Posts: 8
|
How to use software UART? |
Posted: Mon Dec 31, 2012 1:19 am |
|
|
I've been trying for a week to debug my software UART routine and have not succeeded yet.
It generates signal for hardware UART but not for pins which i define.
my code is
Code: |
// defined in .h file
#use rs232(baud=9600,xmit=PIN_B7,rcv=PIN_B6,bits=9,multi_master,errors,long_data,force_sw,enable=pin_E2,STREAM=sensor)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,STREAM=terminal)
// main code in while(1) loop
fputc('A',sensor);
delay_ms(500);
|
Moderators please delete it if reposted here (I couldn't find any other related topic).
I'm using 18F45K20 CCS 4.130 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19555
|
|
Posted: Mon Dec 31, 2012 2:18 am |
|
|
You are using 'MULTI_MASTER', without defining a separate 'RETURN' pin. As such the RCV pin will be treated as the return pin (PIN B6), and the code _will not transmit, unless this is high_. I'd guess it is not high.
If this line is detected to not be high when you go to transmit, bit 6 of 'RS232_ERRORS' will be set, and _all_ future data output on the port will stop, till you clear this bit.
Best Wishes |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Mon Dec 31, 2012 3:18 am |
|
|
You have also specified Errors and force_sw. These are mutually exclusinve. Errors is used to tell the compiler to generate extra code to detect an error condition of the hardware UART and restart the hardware UART if the error condition exists. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19555
|
|
Posted: Mon Dec 31, 2012 3:39 am |
|
|
ERRORS, is not mutually exclusive to FORCE_SW. When using hardware, it is 'required', but with a software UART, it still enables the RS232_ERRORS byte, with bit 7 of this giving the 9th data bit, and bit 6 the collision for multi_master, or float_high mode.
Best Wishes |
|
|
shardul
Joined: 12 Nov 2010 Posts: 8
|
|
Posted: Mon Dec 31, 2012 3:40 am |
|
|
Thanks a ton Ttelmah
i did that change and the pin started transmitting the signal
can you do one favour ... wil you tell me how these settings should be
i mean multi master and several other things like what might affect/required for transmission of software UART
it would be a BIG help cause i'm tryin to use 1HW+2SW UARTs |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19555
|
|
Posted: Mon Dec 31, 2012 4:20 am |
|
|
Ouch. You really need to do a bit of research.
Seriously, look at the examples. Realise how _few_ settings they use. You have so many things that would not normally be used, that it is terrifying....
Bits=9 - do you really want this. 99.9% of serial communications, uses 7 or 8 data bits, not 9.
Long_data - only used if you are sending more than a byte at a time. Links to the above.
force_sw - not needed. Only wanted, if you are using the _hardware_ pins, and want to ensure a software UART is used, for things like multi-master operation.
Multi-master - not wanted/needed. Only wanted if you are using a half duplex bus on something like RS485, not 232, which allows different devices to 'control' the bus (be the master). Hence devices can't send, till 'they' have control of the bus.
Enable - only used again, if you are using half-duplex communications, and need a line to control the bus transceiver. Otherwise just wastes a pin....
Have you looked in the forum, about software RS232. Are you aware of the _limitations_ this imposes:
You can only do _one_ thing at a time. One channel receiving, or one channel transmitting. If your code needs comms on two 'non hardware' ports at the same time, you need to be using another solution (more complex software, or - better - hardware). The fact you refer to a 'sensor', suggests that this is a device that is going to want to send you data. As such, _problems_.
Search the forum.
Best Wishes |
|
|
shardul
Joined: 12 Nov 2010 Posts: 8
|
|
Posted: Mon Dec 31, 2012 4:43 am |
|
|
sorry .... but i'm a newbee to this
i'm using two RS232 & one RS485 and looking at ccs rs485 example i set bit to 9 ... else it was 8
I'll be sending a string over the line to detect a specific sensor (rs485) => does it justify "long data" & "multi master"
and i'm using enable pin (hardware connected to max13430)
I've read "#use rs232" in help section & constructed that code
just wasn't sure where things were going wrong.
Thanks again ... |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19555
|
|
Posted: Mon Dec 31, 2012 8:06 am |
|
|
Quote: |
sorry .... but i'm a newbee to this
i'm using two RS232 & one RS485 and looking at ccs rs485 example i set bit to 9 ... else it was 8
I'll be sending a string over the line to detect a specific sensor (rs485) => does it justify "long data" & "multi master"
and i'm using enable pin (hardware connected to max13430)
I've read "#use rs232" in help section & constructed that code
just wasn't sure where things were going wrong.
Thanks again ... Smile
|
No.....
The example, uses the ninth data bit as a signal to control multi-master operation. It is _not_ needed for simple 'point to point' RS485.
Seriously, step back. Describe the communication protocol used by the devices you want to connect. Have you some data on them?.
Best Wishes |
|
|
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Tue Jan 01, 2013 9:20 am |
|
|
let me give you a friendly tip:
sooner or later your your communication will fail with bad chars being received &&|| being dropped.
for two channels of SOLID data com - consider the 18f46K22 with TWO hardware uarts and set up #INT_RDA handlers for EACH.
then and only then will you have two channels you can TRUST to work.
the software uart is a sketchy bit of code at best and has ZERO reliability if there are ANY INTS enabled or if there is a hardware UART running at the same time or even if you are trying to do a "soft" RS232 outbyte at the same time. i would never let soft RS-232 loose on a customer that i ever expect to do biz with in the future. |
|
|
shardul
Joined: 12 Nov 2010 Posts: 8
|
|
Posted: Wed Jan 02, 2013 11:57 pm |
|
|
yeah .... there'll be data sent by slaves to master
and thank u all for suggestions ..... i'll be careful & will do some homework before applying anythin
|
|
|
|