View previous topic :: View next topic |
Author |
Message |
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Fri Jan 11, 2019 8:48 am |
|
|
Mr.Ttelmah you are right maybe FLOAT_HIGH code is faulty. With simple test prog.
Code: |
#include <12F1840.h>
#device *=16
#fuses INTRC_IO,NOPROTECT,MCLR,PUT,BROWNOUT,NOWDT
#use delay(INTERNAL=32MHz)
#use rs232(baud=9600, xmit=PIN_A4, FORCE_SW, STREAM=TX, FLOAT_HIGH)
void main(void){
delay_ms(100);
fprintf(TX,"\r\n SW-UART Test.");
while(TRUE)
;
}
|
also get garbage data. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Fri Jan 11, 2019 8:58 am |
|
|
What resistor size are you using?.
What does a scope show?.
How are you looking at this data?. Remember TTL serial is _inverted_ from
'RS232', so sits high when idle. |
|
|
gaugeguy
Joined: 05 Apr 2011 Posts: 290
|
|
Posted: Fri Jan 11, 2019 9:06 am |
|
|
Your schematic shows the TX and RX connections to the processor are reversed. |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Fri Jan 11, 2019 9:07 am |
|
|
Quote: | What resistor size are you using?. |
Pull up res=3k3;
Quote: |
'RS232', so sits high when idle. |
I have max232 driver.
I'm sure that hardware is OK, because I have used before and just add PIC to tx/rx line. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9127 Location: Greensville,Ontario
|
|
Posted: Fri Jan 11, 2019 9:07 am |
|
|
I'm stiil not convinced he's set the APFCON register
....
bit 7 RXDTSEL: Pin Selection bit
0 = RX/DT function is on RA1
1 = RX/DT function is on RA5
bit 6 SDOSEL: Pin Selection bit
0 = SDO function is on RA0
1 = SDO function is on RA4
the defaults are on RA1/0 whereas he wants to use RA5/4
... something like
#byte APFCON = 0x11D
APFCOn=0b11000000;
... in his program before accessing the UART should 'reassign' the UART to the pins he's using.
I can't compile/test to see IF the compiler sets the APFCON register based on the #use RS232(....options...).
seeing the listing would tell !
Jay |
|
|
kmp84
Joined: 02 Feb 2010 Posts: 345
|
|
Posted: Fri Jan 11, 2019 9:14 am |
|
|
Quote: | Your schematic shows the TX and RX connections to the processor are reversed. | Just the name are reversed.
https://ibb.co/BPTmNR6 |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Fri Jan 11, 2019 9:17 am |
|
|
The APFCON register doesn't come into things for the transmit. Would only
apply to the RX.
He is currently testing the transmit only.
I have a 'nasty suspicion' there is a code bug in the FLOAT_HIGH code
for this chip. It seems to be setting the BSR incorrectly at one point. It
actually sets the BSR correctly, and then on the very next line changes it, then accesses a register. The duplicate setting can't be right (any way you
look at it!...). I must admit I doubt if the PIC12 FLOAT_HIGH implementation
has ever been tested. Not a thing that is ever used that much, especially
on these smaller chips.... |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9127 Location: Greensville,Ontario
|
|
Posted: Fri Jan 11, 2019 9:37 am |
|
|
Hay Mr. T.. I have to ask why you say APFCON doesn't control which RA pin the UART sends data to ? I've just downloaded the newest datasheet and I'm still seeing that the UART can send data to either RA0 or RA4. I'm thinking bit 2 ,'TXCKSEL' is the 'control' bit NOT the SDOSEL I previouly said. I assumed TX and RX bits would be side by side.. fighting a nasty cold doesn't help the thinking process.
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Fri Jan 11, 2019 9:43 am |
|
|
We are not using the UART!.....
The whole point is the UART can't do an 'open collector ' drive.
So we are using a _software_ UART on the transmit.
#use rs232(baud=9600, xmit=PIN_A4, FORCE_SW, STREAM=TX, FLOAT_HIGH)
Note 'FORCE_SW'.
Now we are enabling the UART for the receive (in the earlier code), and
in this it may be necessary to control APFCON, but 'one step at a time'.
Just testing the software UART transmit at this point. |
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9127 Location: Greensville,Ontario
|
|
Posted: Fri Jan 11, 2019 10:59 am |
|
|
Thanks Mr. T.
the light bulb's working better now... I got focused(blinded, dazed) on sending serial data on a pin that can be connected to a HW UART, didn't occour that he needs to bitbang....
Jay |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19249
|
|
Posted: Fri Jan 11, 2019 12:01 pm |
|
|
Yes. In the 'main' code, I'm trying to use a trick that has been used many
times before here of enabling the hardware UART for receive only. You
have to set it up 'as normal', then just turn off the transmit part using
TXEN. I must admit when we get 'back' to this, we are then going to
have to set the corresponding APFCON bit, since the pin being used is the
'alternate', not the primary. However before trying this, I was wanting
to test just the FLOAT_HIGH software UART. I have glanced at the code
being generated for this, and it looks as if it is making a mistake in
bank selection.
It doesn't seem to be setting the LATA bit when it should, so don't think
it is going to work.
As I said I suspect this has not been tested on this chip family. |
|
|
|