|
|
View previous topic :: View next topic |
Author |
Message |
peteD
Joined: 22 May 2006 Posts: 5
|
H/W UART won't work but force_sw will... what's with that? |
Posted: Wed Sep 16, 2009 9:41 pm |
|
|
Using Olimex PIC-IO board with 16F628A and trusty CCS complier.
Code: |
#include <16F628A.h>
#fuses HS,NOWDT,NOPUT,NOBROWNOUT,NOLVP,PROTECT,NOMCLR
#use delay(clock=20000000) // 20MHz crystal (see HS in fuses)
#use rs232(baud=4800, xmit=PIN_B2, rcv=PIN_B1, parity=N, BITS=8, stop=1, force_sw, errors) // note that these are the hardware UART pins
// when force_sw is removed, this does not echo the input data
printf("Hello World"); // this outputs just fine in either case
while(1)
{
while(TRUE)
putc( getc() );
}
|
The source of the incoming date is hyperterm. It works if force_sw is set, but not if force_sw is removed.
I need to implement an INT_RDA version, but after code I have used on other hardware for this in the past did not work, I tried hours of tests and seemed to have isolated the problem to the hardware UART not working, as evidence by this code.
(I have also tried just specifying "UART1" in the use RS232 and that did not change anything).
Anyone see anything I am doing wrong here? Do UARTs just up and fail?
Thanks! |
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Wed Sep 16, 2009 10:45 pm |
|
|
No, that's not normal.
I've used the hardware UARTs on many PIC's with great success...
Looking at your code doesn't immediately show anything obvious..
Try changing your code to:
Code: |
void main (void) {
char c;
delay_ms(500); // just for sanity.
printf("hello world\r\n");
while (1) {
if ( kbhit() ) {
c = getc();
putc(c);
}
}
}
|
I like to break things down to simple to troubleshoot... _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Ttelmah Guest
|
|
Posted: Thu Sep 17, 2009 2:55 am |
|
|
What compiler version?.
There was a problem on some versions at one point, with not configuring the hardware UART correctly, on this chip.
I think I remember PCM programmer posting the fix needed. TRIS change?.
Best Wishes |
|
|
Guest
|
|
Posted: Thu Sep 17, 2009 9:23 am |
|
|
The version of the Ccsc.exe files is 4.3.0.218
Sorry, I did not include the tris setting in the listing. It is in the code. Here are the lines I dd not show.
Code: |
#use STANDARD_IO(A)
#use STANDARD_IO(B) //(also tried FAST_IO, which I usually use)
#define TRIS_A_SETTING 0b00010000 // xx x I1 D1 D2 D3 D4
#define TRIS_B_SETTING 0x00011011 // xx LED I4 I3 Tx Rx I2
...
(in main.c)....
set_tris_a(TRIS_A_SETTING);
set_tris_b(TRIS_B_SETTING);
PORTA = CLEAR; // Turn off all lights
PORTB = CLEAR; |
|
|
|
bkamen
Joined: 07 Jan 2004 Posts: 1615 Location: Central Illinois, USA
|
|
Posted: Thu Sep 17, 2009 9:53 am |
|
|
Anonymous wrote: | The version of the Ccsc.exe files is 4.3.0.218
Sorry, I did not include the tris setting in the listing. It is in the code. Here are the lines I dd not show.
Code: |
#use STANDARD_IO(A)
#use STANDARD_IO(B) //(also tried FAST_IO, which I usually use)
#define TRIS_A_SETTING 0b00010000 // xx x I1 D1 D2 D3 D4
#define TRIS_B_SETTING 0x00011011 // xx LED I4 I3 Tx Rx I2
...
(in main.c)....
set_tris_a(TRIS_A_SETTING);
set_tris_b(TRIS_B_SETTING);
PORTA = CLEAR; // Turn off all lights
PORTB = CLEAR; |
|
Ahhh, have you tried with the pins for the UART being set for input? I know it can work that way with some PICs... (IIRC)
If you read the datasheet carefully, it will probably mention how the PIC wants the TRIS state to use the device.
Software UART will most likely override your settings and thus why it works.
-Ben _________________ Dazed and confused? I don't think so. Just "plain lost" will do. :D |
|
|
Ttelmah Guest
|
|
Posted: Thu Sep 17, 2009 10:21 am |
|
|
When asked for CCS version numbers, what we want, is in the format X.xxx. It is at the top of the .lst file, or 'help', 'about'. The version numbers you get from the CCS files, if you look at their 'version' using MS, doesn't tell us anything (CCS have the habit of changing these, then not changing them....).
The TRIS bits for both TX, and RX, have to be set to '1' on the 628, for the hardware UART.
Best Wishes |
|
|
FvM
Joined: 27 Aug 2008 Posts: 2337 Location: Germany
|
|
Posted: Thu Sep 17, 2009 11:06 am |
|
|
Quote: | The TRISS bits fo both TX, and RX, have to be set to '1' on the 628, for the hardware UART. | According to the data sheet, the UART Tx peripheral OE overrides the TRIS setting for Tx, so the original setting is ignored for this pin. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu Sep 17, 2009 11:45 am |
|
|
One problem is that you have been posting code fragments.
Post the complete (but short) test program that you are using.
Edit it down to a small program. Test it. Verify that it still fails.
Then post it. |
|
|
|
|
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
|